fixed numerous checkstyle warnings (javadoc, trailing spaces, tabs, parenthesis, declaration order ...)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@980981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a48186437b
commit
e24bdc331c
|
@ -34,7 +34,7 @@ public interface BivariateRealFunction {
|
||||||
* @return the value.
|
* @return the value.
|
||||||
* @throws FunctionEvaluationException if the function evaluation fails.
|
* @throws FunctionEvaluationException if the function evaluation fails.
|
||||||
*/
|
*/
|
||||||
public double value(double x, double y)
|
double value(double x, double y)
|
||||||
throws FunctionEvaluationException;
|
throws FunctionEvaluationException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,6 @@ public interface TrivariateRealFunction {
|
||||||
* @return the value.
|
* @return the value.
|
||||||
* @throws FunctionEvaluationException if the function evaluation fails.
|
* @throws FunctionEvaluationException if the function evaluation fails.
|
||||||
*/
|
*/
|
||||||
public double value(double x, double y, double z)
|
double value(double x, double y, double z)
|
||||||
throws FunctionEvaluationException;
|
throws FunctionEvaluationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.apache.commons.math.DimensionMismatchException;
|
||||||
import org.apache.commons.math.FunctionEvaluationException;
|
import org.apache.commons.math.FunctionEvaluationException;
|
||||||
import org.apache.commons.math.analysis.BivariateRealFunction;
|
import org.apache.commons.math.analysis.BivariateRealFunction;
|
||||||
import org.apache.commons.math.exception.NoDataException;
|
import org.apache.commons.math.exception.NoDataException;
|
||||||
import org.apache.commons.math.exception.NonMonotonousSequenceException;
|
|
||||||
import org.apache.commons.math.exception.OutOfRangeException;
|
import org.apache.commons.math.exception.OutOfRangeException;
|
||||||
import org.apache.commons.math.util.MathUtils;
|
import org.apache.commons.math.util.MathUtils;
|
||||||
|
|
||||||
|
@ -86,8 +85,8 @@ public class BicubicSplineInterpolatingFunction
|
||||||
* every grid point.
|
* every grid point.
|
||||||
* @throws DimensionMismatchException if the various arrays do not contain
|
* @throws DimensionMismatchException if the various arrays do not contain
|
||||||
* the expected number of elements.
|
* the expected number of elements.
|
||||||
* @throws NonMonotonousSequenceException if {@code x} or {@code y} are not strictly
|
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
|
||||||
* increasing.
|
* if {@code x} or {@code y} are not strictly increasing.
|
||||||
* @throws NoDataException if any of the arrays has zero length.
|
* @throws NoDataException if any of the arrays has zero length.
|
||||||
*/
|
*/
|
||||||
public BicubicSplineInterpolatingFunction(double[] x,
|
public BicubicSplineInterpolatingFunction(double[] x,
|
||||||
|
@ -346,23 +345,37 @@ public class BicubicSplineInterpolatingFunction
|
||||||
*/
|
*/
|
||||||
class BicubicSplineFunction
|
class BicubicSplineFunction
|
||||||
implements BivariateRealFunction {
|
implements BivariateRealFunction {
|
||||||
|
|
||||||
|
/** Number of points. */
|
||||||
private static final short N = 4;
|
private static final short N = 4;
|
||||||
|
|
||||||
/** Coefficients */
|
/** Coefficients */
|
||||||
private final double[][] a = new double[N][N];
|
private final double[][] a;
|
||||||
/** Partial derivatives */
|
|
||||||
BivariateRealFunction partialDerivativeX = null;
|
/** First partial derivative along x. */
|
||||||
BivariateRealFunction partialDerivativeY = null;
|
private BivariateRealFunction partialDerivativeX;
|
||||||
BivariateRealFunction partialDerivativeXX = null;
|
|
||||||
BivariateRealFunction partialDerivativeYY = null;
|
/** First partial derivative along y. */
|
||||||
BivariateRealFunction partialDerivativeXY = null;
|
private BivariateRealFunction partialDerivativeY;
|
||||||
|
|
||||||
|
/** Second partial derivative along x. */
|
||||||
|
private BivariateRealFunction partialDerivativeXX;
|
||||||
|
|
||||||
|
/** Second partial derivative along y. */
|
||||||
|
private BivariateRealFunction partialDerivativeYY;
|
||||||
|
|
||||||
|
/** Second crossed partial derivative. */
|
||||||
|
private BivariateRealFunction partialDerivativeXY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Simple constructor.
|
||||||
* @param a Spline coefficients
|
* @param a Spline coefficients
|
||||||
*/
|
*/
|
||||||
public BicubicSplineFunction(double[] aV) {
|
public BicubicSplineFunction(double[] a) {
|
||||||
|
this.a = new double[N][N];
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
for (int j = 0; j < N; j++) {
|
for (int j = 0; j < N; j++) {
|
||||||
a[i][j] = aV[i + N * j];
|
this.a[i][j] = a[i + N * j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.commons.math.util.LocalizedFormats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a linear function for interpolation of real univariate functions.
|
* Implements a linear function for interpolation of real univariate functions.
|
||||||
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
public class LinearInterpolator implements UnivariateRealInterpolator {
|
public class LinearInterpolator implements UnivariateRealInterpolator {
|
||||||
/**
|
/**
|
||||||
|
@ -34,8 +35,8 @@ public class LinearInterpolator implements UnivariateRealInterpolator {
|
||||||
* @return a function which interpolates the data set
|
* @return a function which interpolates the data set
|
||||||
* @throws DimensionMismatchException if {@code x} and {@code y}
|
* @throws DimensionMismatchException if {@code x} and {@code y}
|
||||||
* have different sizes.
|
* have different sizes.
|
||||||
* @throws NonMonotonousSequenceException if {@code x} is not sorted in
|
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
|
||||||
* strict increasing order.
|
* if {@code x} is not sorted in strict increasing order.
|
||||||
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
|
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
|
||||||
* than 2.
|
* than 2.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.MathException;
|
import org.apache.commons.math.MathException;
|
||||||
import org.apache.commons.math.util.LocalizedFormats;
|
import org.apache.commons.math.util.LocalizedFormats;
|
||||||
import org.apache.commons.math.util.MathUtils;
|
import org.apache.commons.math.util.MathUtils;
|
||||||
|
import org.apache.commons.math.util.MathUtils.Order;
|
||||||
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||||
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
|
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
|
||||||
|
|
||||||
|
@ -55,8 +56,8 @@ public class SmoothingBicubicSplineInterpolator
|
||||||
throw new DimensionMismatchException(xval.length, zval.length);
|
throw new DimensionMismatchException(xval.length, zval.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
MathUtils.checkOrder(xval, 1, true);
|
MathUtils.checkOrder(xval, Order.Direction.INCREASING, true);
|
||||||
MathUtils.checkOrder(yval, 1, true);
|
MathUtils.checkOrder(yval, Order.Direction.INCREASING, true);
|
||||||
|
|
||||||
final int xLen = xval.length;
|
final int xLen = xval.length;
|
||||||
final int yLen = yval.length;
|
final int yLen = yval.length;
|
||||||
|
|
|
@ -34,7 +34,11 @@ import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
|
||||||
*/
|
*/
|
||||||
public class SmoothingPolynomialBicubicSplineInterpolator
|
public class SmoothingPolynomialBicubicSplineInterpolator
|
||||||
extends BicubicSplineInterpolator {
|
extends BicubicSplineInterpolator {
|
||||||
|
|
||||||
|
/** Fitter for x. */
|
||||||
private final PolynomialFitter xFitter;
|
private final PolynomialFitter xFitter;
|
||||||
|
|
||||||
|
/** Fitter for y. */
|
||||||
private final PolynomialFitter yFitter;
|
private final PolynomialFitter yFitter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
|
||||||
* @return a function which interpolates the data set
|
* @return a function which interpolates the data set
|
||||||
* @throws DimensionMismatchException if {@code x} and {@code y}
|
* @throws DimensionMismatchException if {@code x} and {@code y}
|
||||||
* have different sizes.
|
* have different sizes.
|
||||||
* @throws NonMonotonousSequenceException if {@code x} is not sorted in
|
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
|
||||||
* strict increasing order.
|
* if {@code x} is not sorted in strict increasing order.
|
||||||
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
|
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
|
||||||
* than 3.
|
* than 3.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -126,6 +126,8 @@ public class TricubicSplineInterpolatingFunction
|
||||||
* to x on every grid point.
|
* to x on every grid point.
|
||||||
* @param dFdY Values of the partial derivative of function with respect
|
* @param dFdY Values of the partial derivative of function with respect
|
||||||
* to y on every grid point.
|
* to y on every grid point.
|
||||||
|
* @param dFdZ Values of the partial derivative of function with respect
|
||||||
|
* to z on every grid point.
|
||||||
* @param d2FdXdY Values of the cross partial derivative of function on
|
* @param d2FdXdY Values of the cross partial derivative of function on
|
||||||
* every grid point.
|
* every grid point.
|
||||||
* @param d2FdXdZ Values of the cross partial derivative of function on
|
* @param d2FdXdZ Values of the cross partial derivative of function on
|
||||||
|
@ -155,8 +157,7 @@ public class TricubicSplineInterpolatingFunction
|
||||||
final int yLen = y.length;
|
final int yLen = y.length;
|
||||||
final int zLen = z.length;
|
final int zLen = z.length;
|
||||||
|
|
||||||
if (xLen == 0 || yLen == 0 || z.length == 0
|
if (xLen == 0 || yLen == 0 || z.length == 0 || f.length == 0 || f[0].length == 0) {
|
||||||
|| f.length == 0 || f[0].length == 0) {
|
|
||||||
throw new NoDataException();
|
throw new NoDataException();
|
||||||
}
|
}
|
||||||
if (xLen != f.length) {
|
if (xLen != f.length) {
|
||||||
|
@ -421,8 +422,8 @@ public class TricubicSplineInterpolatingFunction
|
||||||
*/
|
*/
|
||||||
class TricubicSplineFunction
|
class TricubicSplineFunction
|
||||||
implements TrivariateRealFunction {
|
implements TrivariateRealFunction {
|
||||||
|
/** Number of points. */
|
||||||
private static final short N = 4;
|
private static final short N = 4;
|
||||||
private static final short N2 = N * N;
|
|
||||||
/** Coefficients */
|
/** Coefficients */
|
||||||
private final double[][][] a = new double[N][N][N];
|
private final double[][][] a = new double[N][N][N];
|
||||||
|
|
||||||
|
@ -433,7 +434,7 @@ class TricubicSplineFunction
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
for (int j = 0; j < N; j++) {
|
for (int j = 0; j < N; j++) {
|
||||||
for (int k = 0; k < N; k++) {
|
for (int k = 0; k < N; k++) {
|
||||||
a[i][j][k] = aV[i + N * j + N2 * k];
|
a[i][j][k] = aV[i + N * (j + N * k)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ public interface TrivariateRealGridInterpolator {
|
||||||
* @param fval the values of the interpolation points on all the grid knots:
|
* @param fval the values of the interpolation points on all the grid knots:
|
||||||
* {@code fval[i][j][k] = f(xval[i], yval[j], zval[k])}.
|
* {@code fval[i][j][k] = f(xval[i], yval[j], zval[k])}.
|
||||||
* @return a function that interpolates the data set.
|
* @return a function that interpolates the data set.
|
||||||
* @throws NoDataException if any of the arrays has zero length.
|
* @throws org.apache.commons.math.exception.NoDataException if any of the arrays has zero length.
|
||||||
* @throws DimensionMismatchException if the array lengths are inconsistent.
|
* @throws org.apache.commons.math.exception.DimensionMismatchException if the array lengths are inconsistent.
|
||||||
* @throws MathException if arguments violate assumptions made by the
|
* @throws MathException if arguments violate assumptions made by the
|
||||||
* interpolation algorithm.
|
* interpolation algorithm.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -41,7 +41,7 @@ public abstract class AbstractContinuousDistribution
|
||||||
|
|
||||||
/** Serializable version identifier */
|
/** Serializable version identifier */
|
||||||
private static final long serialVersionUID = -38038050983108802L;
|
private static final long serialVersionUID = -38038050983108802L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RandomData instance used to generate samples from the distribution
|
* RandomData instance used to generate samples from the distribution
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class MathIllegalArgumentException extends IllegalArgumentException {
|
||||||
* Arguments used to build the message.
|
* Arguments used to build the message.
|
||||||
*/
|
*/
|
||||||
private final Object[] arguments;
|
private final Object[] arguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param specific Message pattern providing the specific context of
|
* @param specific Message pattern providing the specific context of
|
||||||
* the error.
|
* the error.
|
||||||
|
@ -84,7 +84,7 @@ public class MathIllegalArgumentException extends IllegalArgumentException {
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public String getLocalizedMessage() {
|
public String getLocalizedMessage() {
|
||||||
|
|
|
@ -40,8 +40,8 @@ public class MathIllegalNumberException extends MathIllegalArgumentException {
|
||||||
*
|
*
|
||||||
* @param specific Localizable pattern.
|
* @param specific Localizable pattern.
|
||||||
* @param general Localizable pattern.
|
* @param general Localizable pattern.
|
||||||
* @param arguments Arguments. The first element must be the requested
|
* @param wrong wrong number
|
||||||
* value that raised the exception.
|
* @param arguments Arguments.
|
||||||
*/
|
*/
|
||||||
protected MathIllegalNumberException(Localizable specific,
|
protected MathIllegalNumberException(Localizable specific,
|
||||||
Localizable general,
|
Localizable general,
|
||||||
|
@ -55,8 +55,8 @@ public class MathIllegalNumberException extends MathIllegalArgumentException {
|
||||||
* Construct an exception.
|
* Construct an exception.
|
||||||
*
|
*
|
||||||
* @param general Localizable pattern.
|
* @param general Localizable pattern.
|
||||||
* @param arguments Arguments. The first element must be the requested
|
* @param wrong wrong number
|
||||||
* value that raised the exception.
|
* @param arguments Arguments.
|
||||||
*/
|
*/
|
||||||
protected MathIllegalNumberException(Localizable general,
|
protected MathIllegalNumberException(Localizable general,
|
||||||
Number wrong,
|
Number wrong,
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class NumberIsTooLargeException extends MathIllegalNumberException {
|
||||||
*
|
*
|
||||||
* @param wrong Value that is larger than the maximum.
|
* @param wrong Value that is larger than the maximum.
|
||||||
* @param max maximum.
|
* @param max maximum.
|
||||||
|
* @param boundIsAllowed if true the maximum is included in the allowed range.
|
||||||
*/
|
*/
|
||||||
public NumberIsTooLargeException(Number wrong,
|
public NumberIsTooLargeException(Number wrong,
|
||||||
Number max,
|
Number max,
|
||||||
|
@ -56,15 +57,16 @@ public class NumberIsTooLargeException extends MathIllegalNumberException {
|
||||||
* @param specific Specific contexte pattern .
|
* @param specific Specific contexte pattern .
|
||||||
* @param wrong Value that is larger than the maximum.
|
* @param wrong Value that is larger than the maximum.
|
||||||
* @param max maximum.
|
* @param max maximum.
|
||||||
|
* @param boundIsAllowed if true the maximum is included in the allowed range.
|
||||||
*/
|
*/
|
||||||
public NumberIsTooLargeException(Localizable specific,
|
public NumberIsTooLargeException(Localizable specific,
|
||||||
Number wrong,
|
Number wrong,
|
||||||
Number max,
|
Number max,
|
||||||
boolean boundIsAllowed) {
|
boolean boundIsAllowed) {
|
||||||
super(specific,
|
super(specific,
|
||||||
(boundIsAllowed ?
|
boundIsAllowed ?
|
||||||
LocalizedFormats.NUMBER_TOO_LARGE :
|
LocalizedFormats.NUMBER_TOO_LARGE :
|
||||||
LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED),
|
LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
|
||||||
wrong, max);
|
wrong, max);
|
||||||
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
|
@ -65,9 +65,9 @@ public class NumberIsTooSmallException extends MathIllegalNumberException {
|
||||||
Number min,
|
Number min,
|
||||||
boolean boundIsAllowed) {
|
boolean boundIsAllowed) {
|
||||||
super(specific,
|
super(specific,
|
||||||
(boundIsAllowed ?
|
boundIsAllowed ?
|
||||||
LocalizedFormats.NUMBER_TOO_SMALL :
|
LocalizedFormats.NUMBER_TOO_SMALL :
|
||||||
LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED),
|
LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
|
||||||
wrong, min);
|
wrong, min);
|
||||||
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<!-- $Revision$ $Date$ -->
|
||||||
|
<body>
|
||||||
|
Specialized exceptions for algorithms errors.
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -887,8 +887,8 @@ public abstract class AbstractRealVector implements RealVector {
|
||||||
dim = getDimension();
|
dim = getDimension();
|
||||||
current = new EntryImpl();
|
current = new EntryImpl();
|
||||||
next = new EntryImpl();
|
next = new EntryImpl();
|
||||||
if(next.getValue() == 0){
|
if (next.getValue() == 0) {
|
||||||
advance(next);
|
advance(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,13 +914,13 @@ public abstract class AbstractRealVector implements RealVector {
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public Entry next() {
|
public Entry next() {
|
||||||
int index = next.getIndex();
|
int index = next.getIndex();
|
||||||
if(index < 0){
|
if (index < 0) {
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
current.setIndex(index);
|
current.setIndex(index);
|
||||||
advance(next);
|
advance(next);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -63,4 +63,4 @@ public interface ExtendedFirstOrderDifferentialEquations extends FirstOrderDiffe
|
||||||
*/
|
*/
|
||||||
int getMainSetDimension();
|
int getMainSetDimension();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.MaxEvaluationsExceededException;
|
import org.apache.commons.math.MaxEvaluationsExceededException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.ExtendedFirstOrderDifferentialEquations;
|
import org.apache.commons.math.ode.ExtendedFirstOrderDifferentialEquations;
|
||||||
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
|
||||||
import org.apache.commons.math.ode.FirstOrderIntegrator;
|
import org.apache.commons.math.ode.FirstOrderIntegrator;
|
||||||
import org.apache.commons.math.ode.IntegratorException;
|
import org.apache.commons.math.ode.IntegratorException;
|
||||||
import org.apache.commons.math.ode.events.EventException;
|
import org.apache.commons.math.ode.events.EventException;
|
||||||
|
@ -286,7 +285,7 @@ public class FirstOrderIntegratorWithJacobians {
|
||||||
|
|
||||||
/** Get the current value of the step start time t<sub>i</sub>.
|
/** Get the current value of the step start time t<sub>i</sub>.
|
||||||
* <p>This method can be called during integration (typically by
|
* <p>This method can be called during integration (typically by
|
||||||
* the object implementing the {@link FirstOrderDifferentialEquations
|
* the object implementing the {@link org.apache.commons.math.ode.FirstOrderDifferentialEquations
|
||||||
* differential equations} problem) if the value of the current step that
|
* differential equations} problem) if the value of the current step that
|
||||||
* is attempted is needed.</p>
|
* is attempted is needed.</p>
|
||||||
* <p>The result is undefined if the method is called outside of
|
* <p>The result is undefined if the method is called outside of
|
||||||
|
@ -299,7 +298,7 @@ public class FirstOrderIntegratorWithJacobians {
|
||||||
|
|
||||||
/** Get the current signed value of the integration stepsize.
|
/** Get the current signed value of the integration stepsize.
|
||||||
* <p>This method can be called during integration (typically by
|
* <p>This method can be called during integration (typically by
|
||||||
* the object implementing the {@link FirstOrderDifferentialEquations
|
* the object implementing the {@link org.apache.commons.math.ode.FirstOrderDifferentialEquations
|
||||||
* differential equations} problem) if the signed value of the current stepsize
|
* differential equations} problem) if the signed value of the current stepsize
|
||||||
* that is tried is needed.</p>
|
* that is tried is needed.</p>
|
||||||
* <p>The result is undefined if the method is called outside of
|
* <p>The result is undefined if the method is called outside of
|
||||||
|
|
|
@ -76,6 +76,9 @@ public abstract class AdaptiveStepsizeIntegrator
|
||||||
/** Allowed relative vectorial error. */
|
/** Allowed relative vectorial error. */
|
||||||
protected final double[] vecRelativeTolerance;
|
protected final double[] vecRelativeTolerance;
|
||||||
|
|
||||||
|
/** Main set dimension. */
|
||||||
|
protected int mainSetDimension;
|
||||||
|
|
||||||
/** User supplied initial step. */
|
/** User supplied initial step. */
|
||||||
private double initialStep;
|
private double initialStep;
|
||||||
|
|
||||||
|
@ -85,9 +88,6 @@ public abstract class AdaptiveStepsizeIntegrator
|
||||||
/** Maximal step. */
|
/** Maximal step. */
|
||||||
private final double maxStep;
|
private final double maxStep;
|
||||||
|
|
||||||
/** Main set dimension. */
|
|
||||||
protected int mainSetDimension;
|
|
||||||
|
|
||||||
/** Build an integrator with the given stepsize bounds.
|
/** Build an integrator with the given stepsize bounds.
|
||||||
* The default step handler does nothing.
|
* The default step handler does nothing.
|
||||||
* @param name name of the method
|
* @param name name of the method
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.commons.math.analysis.MultivariateRealFunction;
|
||||||
* Commons-Math. Users of the API are advised to base their code on
|
* Commons-Math. Users of the API are advised to base their code on
|
||||||
* {@link MultivariateRealOptimizer} or on
|
* {@link MultivariateRealOptimizer} or on
|
||||||
* {@link DifferentiableMultivariateRealOptimizer}.
|
* {@link DifferentiableMultivariateRealOptimizer}.
|
||||||
|
* @param <T> the type of the objective function to be optimized
|
||||||
*
|
*
|
||||||
* @see MultivariateRealOptimizer
|
* @see MultivariateRealOptimizer
|
||||||
* @see DifferentiableMultivariateRealOptimizer
|
* @see DifferentiableMultivariateRealOptimizer
|
||||||
|
@ -98,7 +99,7 @@ public interface BaseMultivariateRealOptimizer<T extends MultivariateRealFunctio
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimize an objective function.
|
* Optimize an objective function.
|
||||||
*
|
*
|
||||||
* @param f Objective function.
|
* @param f Objective function.
|
||||||
* @param goalType Type of optimization goal: either {@link GoalType#MAXIMIZE}
|
* @param goalType Type of optimization goal: either {@link GoalType#MAXIMIZE}
|
||||||
* or {@link GoalType#MINIMIZE}.
|
* or {@link GoalType#MINIMIZE}.
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class RealPointValuePair implements Serializable {
|
||||||
* @param value value of an objective function at the point
|
* @param value value of an objective function at the point
|
||||||
*/
|
*/
|
||||||
public RealPointValuePair(final double[] point, final double value) {
|
public RealPointValuePair(final double[] point, final double value) {
|
||||||
this.point = (point == null ? null : point.clone());
|
this.point = (point == null) ? null : point.clone();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ public class RealPointValuePair implements Serializable {
|
||||||
*/
|
*/
|
||||||
public RealPointValuePair(final double[] point, final double value,
|
public RealPointValuePair(final double[] point, final double value,
|
||||||
final boolean copyArray) {
|
final boolean copyArray) {
|
||||||
this.point = (copyArray ?
|
this.point = copyArray ?
|
||||||
(point == null ? null : point.clone()) :
|
((point == null) ? null : point.clone()) :
|
||||||
point);
|
point;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class RealPointValuePair implements Serializable {
|
||||||
* @return a copy of the stored point
|
* @return a copy of the stored point
|
||||||
*/
|
*/
|
||||||
public double[] getPoint() {
|
public double[] getPoint() {
|
||||||
return (point == null ? null : point.clone());
|
return (point == null) ? null : point.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a reference to the point.
|
/** Get a reference to the point.
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class VectorialPointValuePair implements Serializable {
|
||||||
* @param value value of an objective function at the point
|
* @param value value of an objective function at the point
|
||||||
*/
|
*/
|
||||||
public VectorialPointValuePair(final double[] point, final double[] value) {
|
public VectorialPointValuePair(final double[] point, final double[] value) {
|
||||||
this.point = (point == null ? null : point.clone());
|
this.point = (point == null) ? null : point.clone();
|
||||||
this.value = (value == null ? null : value.clone());
|
this.value = (value == null) ? null : value.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build a point/objective function value pair.
|
/** Build a point/objective function value pair.
|
||||||
|
@ -57,19 +57,19 @@ public class VectorialPointValuePair implements Serializable {
|
||||||
*/
|
*/
|
||||||
public VectorialPointValuePair(final double[] point, final double[] value,
|
public VectorialPointValuePair(final double[] point, final double[] value,
|
||||||
final boolean copyArray) {
|
final boolean copyArray) {
|
||||||
this.point = (copyArray ?
|
this.point = copyArray ?
|
||||||
(point == null ? null : point.clone()) :
|
((point == null) ? null : point.clone()) :
|
||||||
point);
|
point;
|
||||||
this.value = (copyArray ?
|
this.value = copyArray ?
|
||||||
(value == null ? null : value.clone()) :
|
((value == null) ? null : value.clone()) :
|
||||||
value);
|
value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the point.
|
/** Get the point.
|
||||||
* @return a copy of the stored point
|
* @return a copy of the stored point
|
||||||
*/
|
*/
|
||||||
public double[] getPoint() {
|
public double[] getPoint() {
|
||||||
return (point == null ? null : point.clone());
|
return (point == null) ? null : point.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a reference to the point.
|
/** Get a reference to the point.
|
||||||
|
@ -85,7 +85,7 @@ public class VectorialPointValuePair implements Serializable {
|
||||||
* @return a copy of the stored value of the objective function
|
* @return a copy of the stored value of the objective function
|
||||||
*/
|
*/
|
||||||
public double[] getValue() {
|
public double[] getValue() {
|
||||||
return (value == null ? null : value.clone());
|
return (value == null) ? null : value.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a reference to the value of the objective function.
|
/** Get a reference to the value of the objective function.
|
||||||
|
|
|
@ -260,8 +260,8 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
|
||||||
throws FunctionEvaluationException, OptimizationException,
|
throws FunctionEvaluationException, OptimizationException,
|
||||||
IllegalArgumentException {
|
IllegalArgumentException {
|
||||||
|
|
||||||
if (startConfiguration == null
|
if ((startConfiguration == null) ||
|
||||||
|| startConfiguration.length != startPoint.length) {
|
(startConfiguration.length != startPoint.length)) {
|
||||||
// no initial configuration has been set up for simplex
|
// no initial configuration has been set up for simplex
|
||||||
// build a default one from a unit hypercube
|
// build a default one from a unit hypercube
|
||||||
final double[] unit = new double[startPoint.length];
|
final double[] unit = new double[startPoint.length];
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.commons.math.optimization.GoalType;
|
||||||
import org.apache.commons.math.optimization.OptimizationException;
|
import org.apache.commons.math.optimization.OptimizationException;
|
||||||
import org.apache.commons.math.optimization.RealConvergenceChecker;
|
import org.apache.commons.math.optimization.RealConvergenceChecker;
|
||||||
import org.apache.commons.math.optimization.RealPointValuePair;
|
import org.apache.commons.math.optimization.RealPointValuePair;
|
||||||
import org.apache.commons.math.optimization.SimpleScalarValueChecker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for implementing optimizers for multivariate scalar
|
* Base class for implementing optimizers for multivariate scalar
|
||||||
|
@ -38,10 +37,6 @@ import org.apache.commons.math.optimization.SimpleScalarValueChecker;
|
||||||
public abstract class AbstractScalarDifferentiableOptimizer
|
public abstract class AbstractScalarDifferentiableOptimizer
|
||||||
extends BaseAbstractScalarOptimizer<DifferentiableMultivariateRealFunction>
|
extends BaseAbstractScalarOptimizer<DifferentiableMultivariateRealFunction>
|
||||||
implements DifferentiableMultivariateRealOptimizer {
|
implements DifferentiableMultivariateRealOptimizer {
|
||||||
/** Number of gradient evaluations. */
|
|
||||||
private int gradientEvaluations;
|
|
||||||
/** Objective function gradient. */
|
|
||||||
private MultivariateVectorialFunction gradient;
|
|
||||||
|
|
||||||
/** Convergence checker.
|
/** Convergence checker.
|
||||||
* @deprecated in 2.2 (to be removed in 3.0). Please use the accessor
|
* @deprecated in 2.2 (to be removed in 3.0). Please use the accessor
|
||||||
|
@ -60,9 +55,15 @@ public abstract class AbstractScalarDifferentiableOptimizer
|
||||||
*/
|
*/
|
||||||
protected double[] point;
|
protected double[] point;
|
||||||
|
|
||||||
|
/** Number of gradient evaluations. */
|
||||||
|
private int gradientEvaluations;
|
||||||
|
|
||||||
|
/** Objective function gradient. */
|
||||||
|
private MultivariateVectorialFunction gradient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor with default settings.
|
* Simple constructor with default settings.
|
||||||
* The convergence check is set to a {@link SimpleScalarValueChecker},
|
* The convergence check is set to a {@link org.apache.commons.math.optimization.SimpleScalarValueChecker},
|
||||||
* the allowed number of iterations and evaluations are set to their
|
* the allowed number of iterations and evaluations are set to their
|
||||||
* default values.
|
* default values.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.commons.math.optimization.general;
|
||||||
import org.apache.commons.math.analysis.MultivariateRealFunction;
|
import org.apache.commons.math.analysis.MultivariateRealFunction;
|
||||||
import org.apache.commons.math.optimization.MultivariateRealOptimizer;
|
import org.apache.commons.math.optimization.MultivariateRealOptimizer;
|
||||||
import org.apache.commons.math.optimization.RealConvergenceChecker;
|
import org.apache.commons.math.optimization.RealConvergenceChecker;
|
||||||
import org.apache.commons.math.optimization.SimpleScalarValueChecker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for implementing optimizers for multivariate (not necessarily
|
* Base class for implementing optimizers for multivariate (not necessarily
|
||||||
|
@ -34,7 +33,7 @@ public abstract class AbstractScalarOptimizer
|
||||||
implements MultivariateRealOptimizer {
|
implements MultivariateRealOptimizer {
|
||||||
/**
|
/**
|
||||||
* Simple constructor with default settings.
|
* Simple constructor with default settings.
|
||||||
* The convergence check is set to a {@link SimpleScalarValueChecker},
|
* The convergence check is set to a {@link org.apache.commons.math.optimization.SimpleScalarValueChecker},
|
||||||
* the allowed number of iterations and evaluations are set to their
|
* the allowed number of iterations and evaluations are set to their
|
||||||
* default values.
|
* default values.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -230,10 +230,10 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
* during QR decomposition, it is considered to be a zero vector and hence the
|
* during QR decomposition, it is considered to be a zero vector and hence the
|
||||||
* rank of the matrix is reduced.
|
* rank of the matrix is reduced.
|
||||||
* </p>
|
* </p>
|
||||||
* @param qrRankingThreshold threshold for QR ranking
|
* @param threshold threshold for QR ranking
|
||||||
*/
|
*/
|
||||||
public void setQRRankingThreshold(final double qrRankingThreshold) {
|
public void setQRRankingThreshold(final double threshold) {
|
||||||
this.qrRankingThreshold = qrRankingThreshold;
|
this.qrRankingThreshold = threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.commons.math.optimization.general;
|
package org.apache.commons.math.optimization.general;
|
||||||
|
|
||||||
import org.apache.commons.math.FunctionEvaluationException;
|
import org.apache.commons.math.FunctionEvaluationException;
|
||||||
|
import org.apache.commons.math.MaxIterationsExceededException;
|
||||||
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||||
import org.apache.commons.math.optimization.GoalType;
|
import org.apache.commons.math.optimization.GoalType;
|
||||||
import org.apache.commons.math.optimization.OptimizationException;
|
import org.apache.commons.math.optimization.OptimizationException;
|
||||||
|
@ -61,7 +62,7 @@ public class PowellOptimizer
|
||||||
public PowellOptimizer(double lineSearchTolerance) {
|
public PowellOptimizer(double lineSearchTolerance) {
|
||||||
line = new LineSearch(lineSearchTolerance);
|
line = new LineSearch(lineSearchTolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
protected RealPointValuePair doOptimize()
|
protected RealPointValuePair doOptimize()
|
||||||
|
@ -70,35 +71,35 @@ public class PowellOptimizer
|
||||||
final GoalType goal = getGoalType();
|
final GoalType goal = getGoalType();
|
||||||
final double[] guess = getStartPoint();
|
final double[] guess = getStartPoint();
|
||||||
final int n = guess.length;
|
final int n = guess.length;
|
||||||
|
|
||||||
final double[][] direc = new double[n][n];
|
final double[][] direc = new double[n][n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
direc[i][i] = 1;
|
direc[i][i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] x = guess;
|
double[] x = guess;
|
||||||
double fVal = computeObjectiveValue(x);
|
double fVal = computeObjectiveValue(x);
|
||||||
double[] x1 = x.clone();
|
double[] x1 = x.clone();
|
||||||
while (true) {
|
while (true) {
|
||||||
incrementIterationsCounter();
|
incrementIterationsCounter();
|
||||||
|
|
||||||
double fX = fVal;
|
double fX = fVal;
|
||||||
double fX2 = 0;
|
double fX2 = 0;
|
||||||
double delta = 0;
|
double delta = 0;
|
||||||
int bigInd = 0;
|
int bigInd = 0;
|
||||||
double alphaMin = 0;
|
double alphaMin = 0;
|
||||||
|
|
||||||
double[] direc1 = new double[n];
|
double[] direc1 = new double[n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
direc1 = direc[i];
|
direc1 = direc[i];
|
||||||
|
|
||||||
fX2 = fVal;
|
fX2 = fVal;
|
||||||
|
|
||||||
line.search(x, direc1);
|
line.search(x, direc1);
|
||||||
fVal = line.getValueAtOptimum();
|
fVal = line.getValueAtOptimum();
|
||||||
alphaMin = line.getOptimum();
|
alphaMin = line.getOptimum();
|
||||||
setNewPointAndDirection(x, direc1, alphaMin);
|
setNewPointAndDirection(x, direc1, alphaMin);
|
||||||
|
|
||||||
if ((fX2 - fVal) > delta) {
|
if ((fX2 - fVal) > delta) {
|
||||||
delta = fX2 - fVal;
|
delta = fX2 - fVal;
|
||||||
bigInd = i;
|
bigInd = i;
|
||||||
|
@ -108,14 +109,13 @@ public class PowellOptimizer
|
||||||
final RealPointValuePair previous = new RealPointValuePair(x1, fX);
|
final RealPointValuePair previous = new RealPointValuePair(x1, fX);
|
||||||
final RealPointValuePair current = new RealPointValuePair(x, fVal);
|
final RealPointValuePair current = new RealPointValuePair(x, fVal);
|
||||||
if (getConvergenceChecker().converged(getIterations(), previous, current)) {
|
if (getConvergenceChecker().converged(getIterations(), previous, current)) {
|
||||||
switch (goal) {
|
if (goal == GoalType.MINIMIZE) {
|
||||||
case MINIMIZE:
|
return (fVal < fX) ? current : previous;
|
||||||
return (fVal < fX ? current : previous);
|
} else {
|
||||||
case MAXIMIZE:
|
return (fVal > fX) ? current : previous;
|
||||||
return (fVal > fX ? current : previous);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] x2 = new double[n];
|
double[] x2 = new double[n];
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
direc1[i] = x[i] - x1[i];
|
direc1[i] = x[i] - x1[i];
|
||||||
|
@ -137,7 +137,7 @@ public class PowellOptimizer
|
||||||
fVal = line.getValueAtOptimum();
|
fVal = line.getValueAtOptimum();
|
||||||
alphaMin = line.getOptimum();
|
alphaMin = line.getOptimum();
|
||||||
setNewPointAndDirection(x, direc1, alphaMin);
|
setNewPointAndDirection(x, direc1, alphaMin);
|
||||||
|
|
||||||
final int lastInd = n - 1;
|
final int lastInd = n - 1;
|
||||||
direc[bigInd] = direc[lastInd];
|
direc[bigInd] = direc[lastInd];
|
||||||
direc[lastInd] = direc1;
|
direc[lastInd] = direc1;
|
||||||
|
@ -200,6 +200,8 @@ public class PowellOptimizer
|
||||||
*
|
*
|
||||||
* @param p Starting point.
|
* @param p Starting point.
|
||||||
* @param d Search direction.
|
* @param d Search direction.
|
||||||
|
* @throws OptimizationException if function cannot be evaluated at some test point
|
||||||
|
* or algorithm fails to converge
|
||||||
*/
|
*/
|
||||||
public void search(final double[] p,
|
public void search(final double[] p,
|
||||||
final double[] d)
|
final double[] d)
|
||||||
|
@ -225,7 +227,9 @@ public class PowellOptimizer
|
||||||
bracket.getHi(),
|
bracket.getHi(),
|
||||||
bracket.getMid());
|
bracket.getMid());
|
||||||
valueAtOptimum = f.value(optimum);
|
valueAtOptimum = f.value(optimum);
|
||||||
} catch (Exception e) {
|
} catch (FunctionEvaluationException e) {
|
||||||
|
throw new OptimizationException(e);
|
||||||
|
} catch (MaxIterationsExceededException e) {
|
||||||
throw new OptimizationException(e);
|
throw new OptimizationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,6 +258,10 @@ public abstract class AbstractUnivariateRealOptimizer
|
||||||
* classes.
|
* classes.
|
||||||
*
|
*
|
||||||
* @return the optimum.
|
* @return the optimum.
|
||||||
|
* @throws MaxIterationsExceededException if the maximum iteration count
|
||||||
|
* is exceeded.
|
||||||
|
* @throws FunctionEvaluationException if an error occurs evaluating
|
||||||
|
* the function.
|
||||||
*/
|
*/
|
||||||
protected abstract double doOptimize()
|
protected abstract double doOptimize()
|
||||||
throws MaxIterationsExceededException, FunctionEvaluationException;
|
throws MaxIterationsExceededException, FunctionEvaluationException;
|
||||||
|
|
|
@ -26,8 +26,11 @@ import org.apache.commons.math.optimization.GoalType;
|
||||||
* Provide an interval that brackets a local optimum of a function.
|
* Provide an interval that brackets a local optimum of a function.
|
||||||
* This code is based on a Python implementation (from <em>SciPy</em>,
|
* This code is based on a Python implementation (from <em>SciPy</em>,
|
||||||
* module {@code optimize.py} v0.5).
|
* module {@code optimize.py} v0.5).
|
||||||
|
* @version $Revision$ $Date$
|
||||||
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public class BracketFinder {
|
public class BracketFinder {
|
||||||
|
/** Tolerance to avoid division by zero. */
|
||||||
private static final double EPS_MIN = 1e-21;
|
private static final double EPS_MIN = 1e-21;
|
||||||
/**
|
/**
|
||||||
* Golden section.
|
* Golden section.
|
||||||
|
@ -109,6 +112,10 @@ public class BracketFinder {
|
||||||
* @param goal {@link GoalType Goal type}.
|
* @param goal {@link GoalType Goal type}.
|
||||||
* @param xA Initial point.
|
* @param xA Initial point.
|
||||||
* @param xB Initial point.
|
* @param xB Initial point.
|
||||||
|
* @throws MaxIterationsExceededException if the maximum iteration count
|
||||||
|
* is exceeded.
|
||||||
|
* @throws FunctionEvaluationException if an error occurs evaluating
|
||||||
|
* the function.
|
||||||
*/
|
*/
|
||||||
public void search(UnivariateRealFunction func,
|
public void search(UnivariateRealFunction func,
|
||||||
GoalType goal,
|
GoalType goal,
|
||||||
|
@ -117,7 +124,7 @@ public class BracketFinder {
|
||||||
throws MaxIterationsExceededException,
|
throws MaxIterationsExceededException,
|
||||||
FunctionEvaluationException {
|
FunctionEvaluationException {
|
||||||
reset();
|
reset();
|
||||||
final boolean isMinim = (goal == GoalType.MINIMIZE);
|
final boolean isMinim = goal == GoalType.MINIMIZE;
|
||||||
|
|
||||||
double fA = eval(func, xA);
|
double fA = eval(func, xA);
|
||||||
double fB = eval(func, xB);
|
double fB = eval(func, xB);
|
||||||
|
@ -140,7 +147,7 @@ public class BracketFinder {
|
||||||
if (++iterations > maxIterations) {
|
if (++iterations > maxIterations) {
|
||||||
throw new MaxIterationsExceededException(maxIterations);
|
throw new MaxIterationsExceededException(maxIterations);
|
||||||
}
|
}
|
||||||
|
|
||||||
double tmp1 = (xB - xA) * (fB - fC);
|
double tmp1 = (xB - xA) * (fB - fC);
|
||||||
double tmp2 = (xB - xC) * (fB - fA);
|
double tmp2 = (xB - xC) * (fB - fA);
|
||||||
|
|
||||||
|
@ -239,9 +246,10 @@ public class BracketFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param func Function.
|
* @param f Function.
|
||||||
* @param x Argument.
|
* @param x Argument.
|
||||||
* @return {@code f(x)}
|
* @return {@code f(x)}
|
||||||
|
* @throws FunctionEvaluationException if function cannot be evaluated at x
|
||||||
*/
|
*/
|
||||||
private double eval(UnivariateRealFunction f,
|
private double eval(UnivariateRealFunction f,
|
||||||
double x)
|
double x)
|
||||||
|
|
|
@ -46,11 +46,7 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
|
||||||
setRelativeAccuracy(1e-9);
|
setRelativeAccuracy(1e-9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc} */
|
||||||
* Perform the optimization.
|
|
||||||
*
|
|
||||||
* @return the optimum.
|
|
||||||
*/
|
|
||||||
protected double doOptimize()
|
protected double doOptimize()
|
||||||
throws MaxIterationsExceededException, FunctionEvaluationException {
|
throws MaxIterationsExceededException, FunctionEvaluationException {
|
||||||
return localMin(getGoalType() == GoalType.MINIMIZE,
|
return localMin(getGoalType() == GoalType.MINIMIZE,
|
||||||
|
@ -92,7 +88,8 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
|
||||||
if (t <= 0) {
|
if (t <= 0) {
|
||||||
throw new NotStrictlyPositiveException(t);
|
throw new NotStrictlyPositiveException(t);
|
||||||
}
|
}
|
||||||
double a, b;
|
double a;
|
||||||
|
double b;
|
||||||
if (lo < hi) {
|
if (lo < hi) {
|
||||||
a = lo;
|
a = lo;
|
||||||
b = hi;
|
b = hi;
|
||||||
|
@ -140,16 +137,15 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
|
||||||
r = e;
|
r = e;
|
||||||
e = d;
|
e = d;
|
||||||
|
|
||||||
if (p > q * (a - x)
|
if (p > q * (a - x) &&
|
||||||
&& p < q * (b - x)
|
p < q * (b - x) &&
|
||||||
&& Math.abs(p) < Math.abs(0.5 * q * r)) {
|
Math.abs(p) < Math.abs(0.5 * q * r)) {
|
||||||
// Parabolic interpolation step.
|
// Parabolic interpolation step.
|
||||||
d = p / q;
|
d = p / q;
|
||||||
u = x + d;
|
u = x + d;
|
||||||
|
|
||||||
// f must not be evaluated too close to a or b.
|
// f must not be evaluated too close to a or b.
|
||||||
if (u - a < tol2
|
if (u - a < tol2 || b - u < tol2) {
|
||||||
|| b - u < tol2) {
|
|
||||||
if (x <= m) {
|
if (x <= m) {
|
||||||
d = tol1;
|
d = tol1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -210,15 +206,12 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
|
||||||
} else {
|
} else {
|
||||||
b = u;
|
b = u;
|
||||||
}
|
}
|
||||||
if (fu <= fw
|
if (fu <= fw || w == x) {
|
||||||
|| w == x) {
|
|
||||||
v = w;
|
v = w;
|
||||||
fv = fw;
|
fv = fw;
|
||||||
w = u;
|
w = u;
|
||||||
fw = fu;
|
fw = fu;
|
||||||
} else if (fu <= fv
|
} else if (fu <= fv || v == x || v == w) {
|
||||||
|| v == x
|
|
||||||
|| v == w) {
|
|
||||||
v = u;
|
v = u;
|
||||||
fv = fu;
|
fv = fu;
|
||||||
}
|
}
|
||||||
|
|
|
@ -829,7 +829,7 @@ public class RandomDataImpl implements RandomData, Serializable {
|
||||||
* @param k
|
* @param k
|
||||||
* size of the permutation (must satisfy 0 < k <= n).
|
* size of the permutation (must satisfy 0 < k <= n).
|
||||||
* @return the random permutation as an int array
|
* @return the random permutation as an int array
|
||||||
* @throws NumberIsTooLargException if {@code k > n}.
|
* @throws NumberIsTooLargeException if {@code k > n}.
|
||||||
* @throws NotStrictlyPositiveException if {@code k <= 0}.
|
* @throws NotStrictlyPositiveException if {@code k <= 0}.
|
||||||
*/
|
*/
|
||||||
public int[] nextPermutation(int n, int k) {
|
public int[] nextPermutation(int n, int k) {
|
||||||
|
|
|
@ -32,7 +32,9 @@ public class DummyLocalizable implements Localizable {
|
||||||
/** Source string. */
|
/** Source string. */
|
||||||
private final String source;
|
private final String source;
|
||||||
|
|
||||||
/** Simple constructor. */
|
/** Simple constructor.
|
||||||
|
* @param source source text
|
||||||
|
*/
|
||||||
public DummyLocalizable(final String source) {
|
public DummyLocalizable(final String source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -493,7 +493,7 @@ public final class MathUtils {
|
||||||
yInt = SGN_MASK - yInt;
|
yInt = SGN_MASK - yInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isEqual = (Math.abs(xInt - yInt) <= maxUlps);
|
final boolean isEqual = Math.abs(xInt - yInt) <= maxUlps;
|
||||||
|
|
||||||
return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
|
return isEqual && !Double.isNaN(x) && !Double.isNaN(y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ import org.apache.commons.math.exception.NotStrictlyPositiveException;
|
||||||
* <li>...</li>
|
* <li>...</li>
|
||||||
* <li>(1, 3, 2) corresponds to 23</li>
|
* <li>(1, 3, 2) corresponds to 23</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
* @version $Revision$ $Date$
|
||||||
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public class MultidimensionalCounter implements Iterable<Integer> {
|
public class MultidimensionalCounter implements Iterable<Integer> {
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +79,8 @@ public class MultidimensionalCounter implements Iterable<Integer> {
|
||||||
private int count = -1;
|
private int count = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an iterator (see {@link MultidimensionalCounter#iterator()}.
|
* Create an iterator
|
||||||
|
* @see #iterator()
|
||||||
*/
|
*/
|
||||||
Iterator() {
|
Iterator() {
|
||||||
counter[last] = -1;
|
counter[last] = -1;
|
||||||
|
@ -108,7 +111,7 @@ public class MultidimensionalCounter implements Iterable<Integer> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ++count;
|
return ++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +140,7 @@ public class MultidimensionalCounter implements Iterable<Integer> {
|
||||||
* of the iterator.
|
* of the iterator.
|
||||||
* @throws IndexOutOfBoundsException if {@code index} is not in the
|
* @throws IndexOutOfBoundsException if {@code index} is not in the
|
||||||
* correct interval (as defined by the length of the argument in the
|
* correct interval (as defined by the length of the argument in the
|
||||||
* {@link MultidimensionalCounter#MultidimensionalCounter(int[])
|
* {@link #MultidimensionalCounter(int[])
|
||||||
* constructor of the enclosing class}).
|
* constructor of the enclosing class}).
|
||||||
*/
|
*/
|
||||||
public int getCount(int dim) {
|
public int getCount(int dim) {
|
||||||
|
@ -215,9 +218,9 @@ public class MultidimensionalCounter implements Iterable<Integer> {
|
||||||
|| index >= totalSize) {
|
|| index >= totalSize) {
|
||||||
throw new OutOfRangeException(index, 0, totalSize);
|
throw new OutOfRangeException(index, 0, totalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int[] indices = new int[dimension];
|
final int[] indices = new int[dimension];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < last; i++) {
|
for (int i = 0; i < last; i++) {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
|
@ -270,7 +270,6 @@ public final class BicubicSplineInterpolatingFunctionTest {
|
||||||
|
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
for (int j = 0; j < N; j++) {
|
for (int j = 0; j < N; j++) {
|
||||||
final int index = i + N * j;
|
|
||||||
coeff[i + N * j] = (i + 1) * (j + 2);
|
coeff[i + N * j] = (i + 1) * (j + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue