fixed checkstyle and findbugs errors

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@754765 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-03-15 21:35:38 +00:00
parent 77a6b785d2
commit 39647f7f30
17 changed files with 46 additions and 16 deletions

View File

@ -55,12 +55,12 @@
<!-- the following expositions of internal representation are intentional and documented --> <!-- the following expositions of internal representation are intentional and documented -->
<Match> <Match>
<Class name="org.apache.commons.math.optimization.PointValuePair"/> <Class name="org.apache.commons.math.optimization.ScalarPointValuePair"/>
<Method name="getPointRef" params="" returns="double[]" /> <Method name="getPointRef" params="" returns="double[]" />
<Bug pattern="EI_EXPOSE_REP" /> <Bug pattern="EI_EXPOSE_REP" />
</Match> </Match>
<Match> <Match>
<Class name="org.apache.commons.math.optimization.PointValuePair"/> <Class name="org.apache.commons.math.optimization.ScalarPointValuePair"/>
<Method name="&lt;init>" params="double[],double,boolean" returns="void" /> <Method name="&lt;init>" params="double[],double,boolean" returns="void" />
<Bug pattern="EI_EXPOSE_REP2" /> <Bug pattern="EI_EXPOSE_REP2" />
</Match> </Match>

View File

@ -68,7 +68,7 @@ public interface ScalarDifferentiableOptimizer extends Serializable {
void setConvergenceChecker(ScalarConvergenceChecker checker); void setConvergenceChecker(ScalarConvergenceChecker checker);
/** Get the convergence checker. /** Get the convergence checker.
* @param checker object to use to check for convergence * @return object used to check for convergence
*/ */
ScalarConvergenceChecker getConvergenceChecker(); ScalarConvergenceChecker getConvergenceChecker();

View File

@ -68,7 +68,7 @@ public interface ScalarOptimizer extends Serializable {
void setConvergenceChecker(ScalarConvergenceChecker checker); void setConvergenceChecker(ScalarConvergenceChecker checker);
/** Get the convergence checker. /** Get the convergence checker.
* @param checker object to use to check for convergence * @return object used to check for convergence
*/ */
ScalarConvergenceChecker getConvergenceChecker(); ScalarConvergenceChecker getConvergenceChecker();

View File

@ -56,7 +56,7 @@ public class ScalarPointValuePair implements Serializable {
* it will be referenced * it will be referenced
*/ */
public ScalarPointValuePair(final double[] point, final double value, public ScalarPointValuePair(final double[] point, final double value,
final boolean copyArray) { final boolean copyArray) {
this.point = copyArray ? point.clone() : point; this.point = copyArray ? point.clone() : point;
this.value = value; this.value = value;
} }

View File

@ -78,7 +78,7 @@ public interface VectorialDifferentiableOptimizer extends Serializable {
void setConvergenceChecker(VectorialConvergenceChecker checker); void setConvergenceChecker(VectorialConvergenceChecker checker);
/** Get the convergence checker. /** Get the convergence checker.
* @param checker object to use to check for convergence * @return object used to check for convergence
*/ */
VectorialConvergenceChecker getConvergenceChecker(); VectorialConvergenceChecker getConvergenceChecker();

View File

@ -313,7 +313,8 @@ public abstract class DirectSearchOptimizer implements ScalarOptimizer {
/** Build an initial simplex. /** Build an initial simplex.
* @param startPoint the start point for optimization * @param startPoint the start point for optimization
* @exception IllegalArgumentException * @exception IllegalArgumentException if the start point does not match
* simplex dimension
*/ */
private void buildSimplex(final double[] startPoint) private void buildSimplex(final double[] startPoint)
throws IllegalArgumentException { throws IllegalArgumentException {

View File

@ -303,8 +303,8 @@ public abstract class AbstractLeastSquaresOptimizer implements VectorialDifferen
// store least squares problem characteristics // store least squares problem characteristics
this.f = f; this.f = f;
this.target = target; this.target = target.clone();
this.weights = weights; this.weights = weights.clone();
this.variables = startPoint.clone(); this.variables = startPoint.clone();
this.residuals = new double[target.length]; this.residuals = new double[target.length];
@ -320,6 +320,11 @@ public abstract class AbstractLeastSquaresOptimizer implements VectorialDifferen
} }
/** Perform the bulk of optimization algorithm. /** Perform the bulk of optimization algorithm.
* @return the point/value pair giving the optimal value for objective function
* @exception ObjectiveException if the objective function throws one during
* the search
* @exception OptimizationException if the algorithm failed to converge
* @exception IllegalArgumentException if the start point dimension is wrong
*/ */
abstract protected VectorialPointValuePair doOptimize() abstract protected VectorialPointValuePair doOptimize()
throws ObjectiveException, OptimizationException, IllegalArgumentException; throws ObjectiveException, OptimizationException, IllegalArgumentException;

View File

@ -55,7 +55,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
* and the maximal number of evaluation is set to * and the maximal number of evaluation is set to
* {@link AbstractLeastSquaresOptimizer#DEFAULT_MAX_EVALUATIONS}. * {@link AbstractLeastSquaresOptimizer#DEFAULT_MAX_EVALUATIONS}.
* @param useLU if true, the normal equations will be solved using LU * @param useLU if true, the normal equations will be solved using LU
* decomposition, otherwise it will be solved using QR decomposition * decomposition, otherwise they will be solved using QR decomposition
*/ */
public GaussNewtonOptimizer(final boolean useLU) { public GaussNewtonOptimizer(final boolean useLU) {
this.useLU = useLU; this.useLU = useLU;

View File

@ -60,7 +60,10 @@ import org.apache.commons.math.linear.decomposition.NotPositiveDefiniteMatrixExc
*/ */
public class CorrelatedRandomVectorGenerator public class CorrelatedRandomVectorGenerator
implements RandomVectorGenerator { implements RandomVectorGenerator {
/** Serializable version identifier. */
private static final long serialVersionUID = -7162933284241468177L;
/** Simple constructor. /** Simple constructor.
* <p>Build a correlated random vector generator from its mean * <p>Build a correlated random vector generator from its mean

View File

@ -27,6 +27,9 @@ package org.apache.commons.math.random;
public class GaussianRandomGenerator implements NormalizedRandomGenerator { public class GaussianRandomGenerator implements NormalizedRandomGenerator {
/** Serializable version identifier. */
private static final long serialVersionUID = -4698731518385853565L;
/** Create a new generator. /** Create a new generator.
* @param generator underlying random generator to use * @param generator underlying random generator to use
*/ */

View File

@ -17,6 +17,8 @@
package org.apache.commons.math.random; package org.apache.commons.math.random;
import java.io.Serializable;
/** /**
* This interface represent a normalized random generator for * This interface represent a normalized random generator for
* scalars. * scalars.
@ -24,7 +26,7 @@ package org.apache.commons.math.random;
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since 1.2 * @since 1.2
*/ */
public interface NormalizedRandomGenerator { public interface NormalizedRandomGenerator extends Serializable {
/** Generate a random scalar with null mean and unit standard deviation. /** Generate a random scalar with null mean and unit standard deviation.
* <p>This method does <strong>not</strong> specify the shape of the * <p>This method does <strong>not</strong> specify the shape of the

View File

@ -17,6 +17,8 @@
package org.apache.commons.math.random; package org.apache.commons.math.random;
import java.io.Serializable;
/** This interface represents a random generator for whole vectors. /** This interface represents a random generator for whole vectors.
* *
* @since 1.2 * @since 1.2
@ -24,7 +26,7 @@ package org.apache.commons.math.random;
* *
*/ */
public interface RandomVectorGenerator { public interface RandomVectorGenerator extends Serializable {
/** Generate a random vector. /** Generate a random vector.
* @return a random vector as an array of double. * @return a random vector as an array of double.

View File

@ -31,6 +31,9 @@ import java.util.Arrays;
public class UncorrelatedRandomVectorGenerator public class UncorrelatedRandomVectorGenerator
implements RandomVectorGenerator { implements RandomVectorGenerator {
/** Serializable version identifier. */
private static final long serialVersionUID = -3268228248001718811L;
/** Simple constructor. /** Simple constructor.
* <p>Build an uncorrelated random vector generator from * <p>Build an uncorrelated random vector generator from
* its mean and standard deviation vectors.</p> * its mean and standard deviation vectors.</p>

View File

@ -31,6 +31,9 @@ package org.apache.commons.math.random;
public class UniformRandomGenerator implements NormalizedRandomGenerator { public class UniformRandomGenerator implements NormalizedRandomGenerator {
/** Serializable version identifier. */
private static final long serialVersionUID = 1569292426375546027L;
/** Create a new generator. /** Create a new generator.
* @param generator underlying random generator to use * @param generator underlying random generator to use
*/ */

View File

@ -549,8 +549,8 @@ public final class MathUtils {
* <code>0</code>.</li> * <code>0</code>.</li>
* </ul> * </ul>
* *
* @param u any number * @param p any number
* @param v any number * @param q any number
* @return the greatest common divisor, never negative * @return the greatest common divisor, never negative
* @throws ArithmeticException * @throws ArithmeticException
* if the result cannot be represented as a nonnegative int * if the result cannot be represented as a nonnegative int

View File

@ -112,6 +112,7 @@ extends TestCase {
optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 }); optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 });
assertEquals(0, optimizer.getRMS(), 1.0e-10); assertEquals(0, optimizer.getRMS(), 1.0e-10);
assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
} }
public void testColumnsPermutation() throws ObjectiveException, OptimizationException { public void testColumnsPermutation() throws ObjectiveException, OptimizationException {
@ -128,6 +129,9 @@ extends TestCase {
assertEquals(0, optimizer.getRMS(), 1.0e-10); assertEquals(0, optimizer.getRMS(), 1.0e-10);
assertEquals(7.0, optimum.getPoint()[0], 1.0e-10); assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
assertEquals(3.0, optimum.getPoint()[1], 1.0e-10); assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
assertEquals(4.0, optimum.getValue()[0], 1.0e-10);
assertEquals(6.0, optimum.getValue()[1], 1.0e-10);
assertEquals(1.0, optimum.getValue()[2], 1.0e-10);
} }

View File

@ -119,13 +119,14 @@ public class LevenbergMarquardtOptimizerTest
fail("wrong exception caught"); fail("wrong exception caught");
} }
assertEquals(1.5, optimum.getPoint()[0], 1.0e-10); assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
} }
public void testQRColumnsPermutation() throws ObjectiveException, OptimizationException { public void testQRColumnsPermutation() throws ObjectiveException, OptimizationException {
LinearProblem problem = LinearProblem problem =
new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } }, new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
new double[] { 4.0, 6.0, 1.0 }); new double[] { 4.0, 6.0, 1.0 });
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
VectorialPointValuePair optimum = VectorialPointValuePair optimum =
@ -133,6 +134,9 @@ public class LevenbergMarquardtOptimizerTest
assertEquals(0, optimizer.getRMS(), 1.0e-10); assertEquals(0, optimizer.getRMS(), 1.0e-10);
assertEquals(7.0, optimum.getPoint()[0], 1.0e-10); assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
assertEquals(3.0, optimum.getPoint()[1], 1.0e-10); assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
assertEquals(4.0, optimum.getValue()[0], 1.0e-10);
assertEquals(6.0, optimum.getValue()[1], 1.0e-10);
assertEquals(1.0, optimum.getValue()[2], 1.0e-10);
} }