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:
Luc Maisonobe 2010-07-30 22:03:04 +00:00
parent a48186437b
commit e24bdc331c
35 changed files with 185 additions and 128 deletions

View File

@ -34,7 +34,7 @@ public interface BivariateRealFunction {
* @return the value.
* @throws FunctionEvaluationException if the function evaluation fails.
*/
public double value(double x, double y)
double value(double x, double y)
throws FunctionEvaluationException;
}

View File

@ -35,6 +35,6 @@ public interface TrivariateRealFunction {
* @return the value.
* @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;
}

View File

@ -20,7 +20,6 @@ import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.BivariateRealFunction;
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.util.MathUtils;
@ -86,8 +85,8 @@ public class BicubicSplineInterpolatingFunction
* every grid point.
* @throws DimensionMismatchException if the various arrays do not contain
* the expected number of elements.
* @throws NonMonotonousSequenceException if {@code x} or {@code y} are not strictly
* increasing.
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
* if {@code x} or {@code y} are not strictly increasing.
* @throws NoDataException if any of the arrays has zero length.
*/
public BicubicSplineInterpolatingFunction(double[] x,
@ -346,23 +345,37 @@ public class BicubicSplineInterpolatingFunction
*/
class BicubicSplineFunction
implements BivariateRealFunction {
/** Number of points. */
private static final short N = 4;
/** Coefficients */
private final double[][] a = new double[N][N];
/** Partial derivatives */
BivariateRealFunction partialDerivativeX = null;
BivariateRealFunction partialDerivativeY = null;
BivariateRealFunction partialDerivativeXX = null;
BivariateRealFunction partialDerivativeYY = null;
BivariateRealFunction partialDerivativeXY = null;
private final double[][] a;
/** First partial derivative along x. */
private BivariateRealFunction partialDerivativeX;
/** First partial derivative along y. */
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
*/
public BicubicSplineFunction(double[] aV) {
public BicubicSplineFunction(double[] a) {
this.a = new double[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
a[i][j] = aV[i + N * j];
this.a[i][j] = a[i + N * j];
}
}
}

View File

@ -25,6 +25,7 @@ import org.apache.commons.math.util.LocalizedFormats;
/**
* Implements a linear function for interpolation of real univariate functions.
* @version $Revision$ $Date$
*/
public class LinearInterpolator implements UnivariateRealInterpolator {
/**
@ -34,8 +35,8 @@ public class LinearInterpolator implements UnivariateRealInterpolator {
* @return a function which interpolates the data set
* @throws DimensionMismatchException if {@code x} and {@code y}
* have different sizes.
* @throws NonMonotonousSequenceException if {@code x} is not sorted in
* strict increasing order.
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
* if {@code x} is not sorted in strict increasing order.
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
* than 2.
*/

View File

@ -21,6 +21,7 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.util.LocalizedFormats;
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.polynomials.PolynomialSplineFunction;
@ -55,8 +56,8 @@ public class SmoothingBicubicSplineInterpolator
throw new DimensionMismatchException(xval.length, zval.length);
}
MathUtils.checkOrder(xval, 1, true);
MathUtils.checkOrder(yval, 1, true);
MathUtils.checkOrder(xval, Order.Direction.INCREASING, true);
MathUtils.checkOrder(yval, Order.Direction.INCREASING, true);
final int xLen = xval.length;
final int yLen = yval.length;

View File

@ -34,7 +34,11 @@ import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
*/
public class SmoothingPolynomialBicubicSplineInterpolator
extends BicubicSplineInterpolator {
/** Fitter for x. */
private final PolynomialFitter xFitter;
/** Fitter for y. */
private final PolynomialFitter yFitter;
/**

View File

@ -59,8 +59,8 @@ public class SplineInterpolator implements UnivariateRealInterpolator {
* @return a function which interpolates the data set
* @throws DimensionMismatchException if {@code x} and {@code y}
* have different sizes.
* @throws NonMonotonousSequenceException if {@code x} is not sorted in
* strict increasing order.
* @throws org.apache.commons.math.exception.NonMonotonousSequenceException
* if {@code x} is not sorted in strict increasing order.
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
* than 3.
*/

View File

@ -126,6 +126,8 @@ public class TricubicSplineInterpolatingFunction
* to x on every grid point.
* @param dFdY Values of the partial derivative of function with respect
* 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
* every grid point.
* @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 zLen = z.length;
if (xLen == 0 || yLen == 0 || z.length == 0
|| f.length == 0 || f[0].length == 0) {
if (xLen == 0 || yLen == 0 || z.length == 0 || f.length == 0 || f[0].length == 0) {
throw new NoDataException();
}
if (xLen != f.length) {
@ -421,8 +422,8 @@ public class TricubicSplineInterpolatingFunction
*/
class TricubicSplineFunction
implements TrivariateRealFunction {
/** Number of points. */
private static final short N = 4;
private static final short N2 = N * N;
/** Coefficients */
private final double[][][] a = new double[N][N][N];
@ -433,7 +434,7 @@ class TricubicSplineFunction
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
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)];
}
}
}

View File

@ -39,8 +39,8 @@ public interface TrivariateRealGridInterpolator {
* @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])}.
* @return a function that interpolates the data set.
* @throws NoDataException if any of the arrays has zero length.
* @throws DimensionMismatchException if the array lengths are inconsistent.
* @throws org.apache.commons.math.exception.NoDataException if any of the arrays has zero length.
* @throws org.apache.commons.math.exception.DimensionMismatchException if the array lengths are inconsistent.
* @throws MathException if arguments violate assumptions made by the
* interpolation algorithm.
*/

View File

@ -41,7 +41,7 @@ public abstract class AbstractContinuousDistribution
/** Serializable version identifier */
private static final long serialVersionUID = -38038050983108802L;
/**
* RandomData instance used to generate samples from the distribution
* @since 2.2

View File

@ -48,7 +48,7 @@ public class MathIllegalArgumentException extends IllegalArgumentException {
* Arguments used to build the message.
*/
private final Object[] arguments;
/**
* @param specific Message pattern providing the specific context of
* the error.
@ -84,7 +84,7 @@ public class MathIllegalArgumentException extends IllegalArgumentException {
return sb.toString();
}
/** {@inheritDoc} */
@Override
public String getLocalizedMessage() {

View File

@ -40,8 +40,8 @@ public class MathIllegalNumberException extends MathIllegalArgumentException {
*
* @param specific Localizable pattern.
* @param general Localizable pattern.
* @param arguments Arguments. The first element must be the requested
* value that raised the exception.
* @param wrong wrong number
* @param arguments Arguments.
*/
protected MathIllegalNumberException(Localizable specific,
Localizable general,
@ -55,8 +55,8 @@ public class MathIllegalNumberException extends MathIllegalArgumentException {
* Construct an exception.
*
* @param general Localizable pattern.
* @param arguments Arguments. The first element must be the requested
* value that raised the exception.
* @param wrong wrong number
* @param arguments Arguments.
*/
protected MathIllegalNumberException(Localizable general,
Number wrong,

View File

@ -44,6 +44,7 @@ public class NumberIsTooLargeException extends MathIllegalNumberException {
*
* @param wrong Value that is larger than the maximum.
* @param max maximum.
* @param boundIsAllowed if true the maximum is included in the allowed range.
*/
public NumberIsTooLargeException(Number wrong,
Number max,
@ -56,15 +57,16 @@ public class NumberIsTooLargeException extends MathIllegalNumberException {
* @param specific Specific contexte pattern .
* @param wrong Value that is larger than the maximum.
* @param max maximum.
* @param boundIsAllowed if true the maximum is included in the allowed range.
*/
public NumberIsTooLargeException(Localizable specific,
Number wrong,
Number max,
boolean boundIsAllowed) {
super(specific,
(boundIsAllowed ?
LocalizedFormats.NUMBER_TOO_LARGE :
LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED),
boundIsAllowed ?
LocalizedFormats.NUMBER_TOO_LARGE :
LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
wrong, max);
this.max = max;

View File

@ -65,9 +65,9 @@ public class NumberIsTooSmallException extends MathIllegalNumberException {
Number min,
boolean boundIsAllowed) {
super(specific,
(boundIsAllowed ?
LocalizedFormats.NUMBER_TOO_SMALL :
LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED),
boundIsAllowed ?
LocalizedFormats.NUMBER_TOO_SMALL :
LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
wrong, min);
this.min = min;

View File

@ -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>

View File

@ -887,8 +887,8 @@ public abstract class AbstractRealVector implements RealVector {
dim = getDimension();
current = new EntryImpl();
next = new EntryImpl();
if(next.getValue() == 0){
advance(next);
if (next.getValue() == 0) {
advance(next);
}
}
@ -914,13 +914,13 @@ public abstract class AbstractRealVector implements RealVector {
/** {@inheritDoc} */
public Entry next() {
int index = next.getIndex();
if(index < 0){
throw new NoSuchElementException();
}
current.setIndex(index);
advance(next);
return current;
int index = next.getIndex();
if (index < 0) {
throw new NoSuchElementException();
}
current.setIndex(index);
advance(next);
return current;
}
/** {@inheritDoc} */

View File

@ -63,4 +63,4 @@ public interface ExtendedFirstOrderDifferentialEquations extends FirstOrderDiffe
*/
int getMainSetDimension();
}
}

View File

@ -28,7 +28,6 @@ import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MaxEvaluationsExceededException;
import org.apache.commons.math.ode.DerivativeException;
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.IntegratorException;
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>.
* <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
* is attempted is needed.</p>
* <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.
* <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
* that is tried is needed.</p>
* <p>The result is undefined if the method is called outside of

View File

@ -76,6 +76,9 @@ public abstract class AdaptiveStepsizeIntegrator
/** Allowed relative vectorial error. */
protected final double[] vecRelativeTolerance;
/** Main set dimension. */
protected int mainSetDimension;
/** User supplied initial step. */
private double initialStep;
@ -85,9 +88,6 @@ public abstract class AdaptiveStepsizeIntegrator
/** Maximal step. */
private final double maxStep;
/** Main set dimension. */
protected int mainSetDimension;
/** Build an integrator with the given stepsize bounds.
* The default step handler does nothing.
* @param name name of the method

View File

@ -27,6 +27,7 @@ import org.apache.commons.math.analysis.MultivariateRealFunction;
* Commons-Math. Users of the API are advised to base their code on
* {@link MultivariateRealOptimizer} or on
* {@link DifferentiableMultivariateRealOptimizer}.
* @param <T> the type of the objective function to be optimized
*
* @see MultivariateRealOptimizer
* @see DifferentiableMultivariateRealOptimizer
@ -98,7 +99,7 @@ public interface BaseMultivariateRealOptimizer<T extends MultivariateRealFunctio
/**
* Optimize an objective function.
*
*
* @param f Objective function.
* @param goalType Type of optimization goal: either {@link GoalType#MAXIMIZE}
* or {@link GoalType#MINIMIZE}.

View File

@ -44,7 +44,7 @@ public class RealPointValuePair implements Serializable {
* @param value value of an objective function at the point
*/
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;
}
@ -57,9 +57,9 @@ public class RealPointValuePair implements Serializable {
*/
public RealPointValuePair(final double[] point, final double value,
final boolean copyArray) {
this.point = (copyArray ?
(point == null ? null : point.clone()) :
point);
this.point = copyArray ?
((point == null) ? null : point.clone()) :
point;
this.value = value;
}
@ -67,7 +67,7 @@ public class RealPointValuePair implements Serializable {
* @return a copy of the stored point
*/
public double[] getPoint() {
return (point == null ? null : point.clone());
return (point == null) ? null : point.clone();
}
/** Get a reference to the point.

View File

@ -44,8 +44,8 @@ public class VectorialPointValuePair implements Serializable {
* @param value value of an objective function at the point
*/
public VectorialPointValuePair(final double[] point, final double[] value) {
this.point = (point == null ? null : point.clone());
this.value = (value == null ? null : value.clone());
this.point = (point == null) ? null : point.clone();
this.value = (value == null) ? null : value.clone();
}
/** Build a point/objective function value pair.
@ -57,19 +57,19 @@ public class VectorialPointValuePair implements Serializable {
*/
public VectorialPointValuePair(final double[] point, final double[] value,
final boolean copyArray) {
this.point = (copyArray ?
(point == null ? null : point.clone()) :
point);
this.value = (copyArray ?
(value == null ? null : value.clone()) :
value);
this.point = copyArray ?
((point == null) ? null : point.clone()) :
point;
this.value = copyArray ?
((value == null) ? null : value.clone()) :
value;
}
/** Get the point.
* @return a copy of the stored point
*/
public double[] getPoint() {
return (point == null ? null : point.clone());
return (point == null) ? null : point.clone();
}
/** 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
*/
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.

View File

@ -260,8 +260,8 @@ public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer
throws FunctionEvaluationException, OptimizationException,
IllegalArgumentException {
if (startConfiguration == null
|| startConfiguration.length != startPoint.length) {
if ((startConfiguration == null) ||
(startConfiguration.length != startPoint.length)) {
// no initial configuration has been set up for simplex
// build a default one from a unit hypercube
final double[] unit = new double[startPoint.length];

View File

@ -25,7 +25,6 @@ import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.RealConvergenceChecker;
import org.apache.commons.math.optimization.RealPointValuePair;
import org.apache.commons.math.optimization.SimpleScalarValueChecker;
/**
* Base class for implementing optimizers for multivariate scalar
@ -38,10 +37,6 @@ import org.apache.commons.math.optimization.SimpleScalarValueChecker;
public abstract class AbstractScalarDifferentiableOptimizer
extends BaseAbstractScalarOptimizer<DifferentiableMultivariateRealFunction>
implements DifferentiableMultivariateRealOptimizer {
/** Number of gradient evaluations. */
private int gradientEvaluations;
/** Objective function gradient. */
private MultivariateVectorialFunction gradient;
/** Convergence checker.
* @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;
/** Number of gradient evaluations. */
private int gradientEvaluations;
/** Objective function gradient. */
private MultivariateVectorialFunction gradient;
/**
* 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
* default values.
*/

View File

@ -20,7 +20,6 @@ package org.apache.commons.math.optimization.general;
import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.optimization.MultivariateRealOptimizer;
import org.apache.commons.math.optimization.RealConvergenceChecker;
import org.apache.commons.math.optimization.SimpleScalarValueChecker;
/**
* Base class for implementing optimizers for multivariate (not necessarily
@ -34,7 +33,7 @@ public abstract class AbstractScalarOptimizer
implements MultivariateRealOptimizer {
/**
* 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
* default values.
*/

View File

@ -230,10 +230,10 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
* during QR decomposition, it is considered to be a zero vector and hence the
* rank of the matrix is reduced.
* </p>
* @param qrRankingThreshold threshold for QR ranking
* @param threshold threshold for QR ranking
*/
public void setQRRankingThreshold(final double qrRankingThreshold) {
this.qrRankingThreshold = qrRankingThreshold;
public void setQRRankingThreshold(final double threshold) {
this.qrRankingThreshold = threshold;
}
/** {@inheritDoc} */

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.optimization.general;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
@ -61,7 +62,7 @@ public class PowellOptimizer
public PowellOptimizer(double lineSearchTolerance) {
line = new LineSearch(lineSearchTolerance);
}
/** {@inheritDoc} */
@Override
protected RealPointValuePair doOptimize()
@ -70,35 +71,35 @@ public class PowellOptimizer
final GoalType goal = getGoalType();
final double[] guess = getStartPoint();
final int n = guess.length;
final double[][] direc = new double[n][n];
for (int i = 0; i < n; i++) {
direc[i][i] = 1;
}
double[] x = guess;
double fVal = computeObjectiveValue(x);
double[] x1 = x.clone();
while (true) {
incrementIterationsCounter();
double fX = fVal;
double fX2 = 0;
double delta = 0;
int bigInd = 0;
double alphaMin = 0;
double[] direc1 = new double[n];
for (int i = 0; i < n; i++) {
direc1 = direc[i];
fX2 = fVal;
line.search(x, direc1);
fVal = line.getValueAtOptimum();
alphaMin = line.getOptimum();
setNewPointAndDirection(x, direc1, alphaMin);
if ((fX2 - fVal) > delta) {
delta = fX2 - fVal;
bigInd = i;
@ -108,14 +109,13 @@ public class PowellOptimizer
final RealPointValuePair previous = new RealPointValuePair(x1, fX);
final RealPointValuePair current = new RealPointValuePair(x, fVal);
if (getConvergenceChecker().converged(getIterations(), previous, current)) {
switch (goal) {
case MINIMIZE:
return (fVal < fX ? current : previous);
case MAXIMIZE:
return (fVal > fX ? current : previous);
if (goal == GoalType.MINIMIZE) {
return (fVal < fX) ? current : previous;
} else {
return (fVal > fX) ? current : previous;
}
}
double[] x2 = new double[n];
for (int i = 0; i < n; i++) {
direc1[i] = x[i] - x1[i];
@ -137,7 +137,7 @@ public class PowellOptimizer
fVal = line.getValueAtOptimum();
alphaMin = line.getOptimum();
setNewPointAndDirection(x, direc1, alphaMin);
final int lastInd = n - 1;
direc[bigInd] = direc[lastInd];
direc[lastInd] = direc1;
@ -200,6 +200,8 @@ public class PowellOptimizer
*
* @param p Starting point.
* @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,
final double[] d)
@ -225,7 +227,9 @@ public class PowellOptimizer
bracket.getHi(),
bracket.getMid());
valueAtOptimum = f.value(optimum);
} catch (Exception e) {
} catch (FunctionEvaluationException e) {
throw new OptimizationException(e);
} catch (MaxIterationsExceededException e) {
throw new OptimizationException(e);
}
}

View File

@ -258,6 +258,10 @@ public abstract class AbstractUnivariateRealOptimizer
* classes.
*
* @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()
throws MaxIterationsExceededException, FunctionEvaluationException;

View File

@ -26,8 +26,11 @@ import org.apache.commons.math.optimization.GoalType;
* Provide an interval that brackets a local optimum of a function.
* This code is based on a Python implementation (from <em>SciPy</em>,
* module {@code optimize.py} v0.5).
* @version $Revision$ $Date$
* @since 2.2
*/
public class BracketFinder {
/** Tolerance to avoid division by zero. */
private static final double EPS_MIN = 1e-21;
/**
* Golden section.
@ -109,6 +112,10 @@ public class BracketFinder {
* @param goal {@link GoalType Goal type}.
* @param xA 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,
GoalType goal,
@ -117,7 +124,7 @@ public class BracketFinder {
throws MaxIterationsExceededException,
FunctionEvaluationException {
reset();
final boolean isMinim = (goal == GoalType.MINIMIZE);
final boolean isMinim = goal == GoalType.MINIMIZE;
double fA = eval(func, xA);
double fB = eval(func, xB);
@ -140,7 +147,7 @@ public class BracketFinder {
if (++iterations > maxIterations) {
throw new MaxIterationsExceededException(maxIterations);
}
double tmp1 = (xB - xA) * (fB - fC);
double tmp2 = (xB - xC) * (fB - fA);
@ -239,9 +246,10 @@ public class BracketFinder {
}
/**
* @param func Function.
* @param f Function.
* @param x Argument.
* @return {@code f(x)}
* @throws FunctionEvaluationException if function cannot be evaluated at x
*/
private double eval(UnivariateRealFunction f,
double x)

View File

@ -46,11 +46,7 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
setRelativeAccuracy(1e-9);
}
/**
* Perform the optimization.
*
* @return the optimum.
*/
/** {@inheritDoc} */
protected double doOptimize()
throws MaxIterationsExceededException, FunctionEvaluationException {
return localMin(getGoalType() == GoalType.MINIMIZE,
@ -92,7 +88,8 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
if (t <= 0) {
throw new NotStrictlyPositiveException(t);
}
double a, b;
double a;
double b;
if (lo < hi) {
a = lo;
b = hi;
@ -140,16 +137,15 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
r = e;
e = d;
if (p > q * (a - x)
&& p < q * (b - x)
&& Math.abs(p) < Math.abs(0.5 * q * r)) {
if (p > q * (a - x) &&
p < q * (b - x) &&
Math.abs(p) < Math.abs(0.5 * q * r)) {
// Parabolic interpolation step.
d = p / q;
u = x + d;
// f must not be evaluated too close to a or b.
if (u - a < tol2
|| b - u < tol2) {
if (u - a < tol2 || b - u < tol2) {
if (x <= m) {
d = tol1;
} else {
@ -210,15 +206,12 @@ public class BrentOptimizer extends AbstractUnivariateRealOptimizer {
} else {
b = u;
}
if (fu <= fw
|| w == x) {
if (fu <= fw || w == x) {
v = w;
fv = fw;
w = u;
fw = fu;
} else if (fu <= fv
|| v == x
|| v == w) {
} else if (fu <= fv || v == x || v == w) {
v = u;
fv = fu;
}

View File

@ -829,7 +829,7 @@ public class RandomDataImpl implements RandomData, Serializable {
* @param k
* size of the permutation (must satisfy 0 < k <= n).
* @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}.
*/
public int[] nextPermutation(int n, int k) {

View File

@ -32,7 +32,9 @@ public class DummyLocalizable implements Localizable {
/** Source string. */
private final String source;
/** Simple constructor. */
/** Simple constructor.
* @param source source text
*/
public DummyLocalizable(final String source) {
this.source = source;
}

View File

@ -493,7 +493,7 @@ public final class MathUtils {
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);
}

View File

@ -40,6 +40,8 @@ import org.apache.commons.math.exception.NotStrictlyPositiveException;
* <li>...</li>
* <li>(1, 3, 2) corresponds to 23</li>
* </ul>
* @version $Revision$ $Date$
* @since 2.2
*/
public class MultidimensionalCounter implements Iterable<Integer> {
/**
@ -77,7 +79,8 @@ public class MultidimensionalCounter implements Iterable<Integer> {
private int count = -1;
/**
* Create an iterator (see {@link MultidimensionalCounter#iterator()}.
* Create an iterator
* @see #iterator()
*/
Iterator() {
counter[last] = -1;
@ -108,7 +111,7 @@ public class MultidimensionalCounter implements Iterable<Integer> {
break;
}
}
return ++count;
}
@ -137,7 +140,7 @@ public class MultidimensionalCounter implements Iterable<Integer> {
* of the iterator.
* @throws IndexOutOfBoundsException if {@code index} is not 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}).
*/
public int getCount(int dim) {
@ -215,9 +218,9 @@ public class MultidimensionalCounter implements Iterable<Integer> {
|| index >= totalSize) {
throw new OutOfRangeException(index, 0, totalSize);
}
final int[] indices = new int[dimension];
int count = 0;
for (int i = 0; i < last; i++) {
int idx = 0;

View File

@ -270,7 +270,6 @@ public final class BicubicSplineInterpolatingFunctionTest {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
final int index = i + N * j;
coeff[i + N * j] = (i + 1) * (j + 2);
}
}