Fix Javadoc and checkstyle errors.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8916830e8a
commit
46b2ce2ee0
|
@ -119,6 +119,7 @@ public class GaussNewtonOptimizer implements LeastSquaresOptimizer {
|
||||||
return new GaussNewtonOptimizer(decomposition);
|
return new GaussNewtonOptimizer(decomposition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public Optimum optimize(final LeastSquaresProblem lsp) {
|
public Optimum optimize(final LeastSquaresProblem lsp) {
|
||||||
//create local evaluation and iteration counts
|
//create local evaluation and iteration counts
|
||||||
final Incrementor evaluationCounter = lsp.getEvaluationCounter();
|
final Incrementor evaluationCounter = lsp.getEvaluationCounter();
|
||||||
|
|
|
@ -41,6 +41,16 @@ class LeastSquaresProblemImpl
|
||||||
/** Initial guess. */
|
/** Initial guess. */
|
||||||
private RealVector start;
|
private RealVector start;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@link LeastSquaresProblem} from the given data.
|
||||||
|
*
|
||||||
|
* @param model the model function
|
||||||
|
* @param target the observed data
|
||||||
|
* @param start the initial guess
|
||||||
|
* @param checker the convergence checker
|
||||||
|
* @param maxEvaluations the allowed evaluations
|
||||||
|
* @param maxIterations the allowed iterations
|
||||||
|
*/
|
||||||
LeastSquaresProblemImpl(final MultivariateJacobianFunction model,
|
LeastSquaresProblemImpl(final MultivariateJacobianFunction model,
|
||||||
final RealVector target,
|
final RealVector target,
|
||||||
final RealVector start,
|
final RealVector start,
|
||||||
|
@ -53,18 +63,22 @@ class LeastSquaresProblemImpl
|
||||||
this.start = start;
|
this.start = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public int getObservationSize() {
|
public int getObservationSize() {
|
||||||
return target.getDimension();
|
return target.getDimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public int getParameterSize() {
|
public int getParameterSize() {
|
||||||
return start.getDimension();
|
return start.getDimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public RealVector getStart() {
|
public RealVector getStart() {
|
||||||
return start == null ? null : start.copy();
|
return start == null ? null : start.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public Evaluation evaluate(final RealVector point) {
|
public Evaluation evaluate(final RealVector point) {
|
||||||
//evaluate value and jacobian in one function call
|
//evaluate value and jacobian in one function call
|
||||||
final Pair<RealVector, RealMatrix> value = this.model.value(point);
|
final Pair<RealVector, RealMatrix> value = this.model.value(point);
|
||||||
|
@ -91,6 +105,14 @@ class LeastSquaresProblemImpl
|
||||||
/** reference to the observed values */
|
/** reference to the observed values */
|
||||||
private final RealVector target;
|
private final RealVector target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@link Evaluation} with no weights.
|
||||||
|
*
|
||||||
|
* @param values the computed function values
|
||||||
|
* @param jacobian the computed function Jacobian
|
||||||
|
* @param target the observed values
|
||||||
|
* @param point the abscissa
|
||||||
|
*/
|
||||||
private UnweightedEvaluation(final RealVector values,
|
private UnweightedEvaluation(final RealVector values,
|
||||||
final RealMatrix jacobian,
|
final RealMatrix jacobian,
|
||||||
final RealVector target,
|
final RealVector target,
|
||||||
|
@ -102,19 +124,22 @@ class LeastSquaresProblemImpl
|
||||||
this.point = point;
|
this.point = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public RealVector computeValue() {
|
public RealVector computeValue() {
|
||||||
return this.values;
|
return this.values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public RealMatrix computeJacobian() {
|
public RealMatrix computeJacobian() {
|
||||||
return this.jacobian;
|
return this.jacobian;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public RealVector getPoint() {
|
public RealVector getPoint() {
|
||||||
return this.point;
|
return this.point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public RealVector computeResiduals() {
|
public RealVector computeResiduals() {
|
||||||
return target.subtract(this.computeValue());
|
return target.subtract(this.computeValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,27 @@ package org.apache.commons.math3.fitting.leastsquares;
|
||||||
import org.apache.commons.math3.optim.ConvergenceChecker;
|
import org.apache.commons.math3.optim.ConvergenceChecker;
|
||||||
import org.apache.commons.math3.util.Incrementor;
|
import org.apache.commons.math3.util.Incrementor;
|
||||||
|
|
||||||
/** @author Evan Ward */
|
/**
|
||||||
|
* Common settings for all optimization problems. Includes divergence and convergence
|
||||||
|
* criteria.
|
||||||
|
*
|
||||||
|
* @param <PAIR> The type of value the {@link #getConvergenceChecker() convergence
|
||||||
|
* checker} will operate on. It should include the value of the model
|
||||||
|
* function and point where it was evaluated.
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
public interface OptimizationProblem<PAIR> {
|
public interface OptimizationProblem<PAIR> {
|
||||||
/**
|
/**
|
||||||
* Get a independent Incrementor that counts up to {@link #getMaxEvaluations()} and
|
* Get a independent Incrementor that counts up to the maximum number of evaluations
|
||||||
* then throws an exception.
|
* and then throws an exception.
|
||||||
*
|
*
|
||||||
* @return a counter for the evaluations.
|
* @return a counter for the evaluations.
|
||||||
*/
|
*/
|
||||||
Incrementor getEvaluationCounter();
|
Incrementor getEvaluationCounter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a independent Incrementor that counts up to {@link #getMaxIterations()} and
|
* Get a independent Incrementor that counts up to the maximum number of iterations
|
||||||
* then throws an exception.
|
* and then throws an exception.
|
||||||
*
|
*
|
||||||
* @return a counter for the evaluations.
|
* @return a counter for the evaluations.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,36 +22,36 @@ import org.apache.commons.math3.fitting.leastsquares.OptimizationProblem;
|
||||||
import org.apache.commons.math3.util.Incrementor;
|
import org.apache.commons.math3.util.Incrementor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for implementing optimizers. It contains the boiler-plate code for counting
|
* Base class for implementing optimization problems. It contains the boiler-plate code
|
||||||
* the number of evaluations of the objective function and the number of iterations of the
|
* for counting the number of evaluations of the objective function and the number of
|
||||||
* algorithm, and storing the convergence checker.
|
* iterations of the algorithm, and storing the convergence checker.
|
||||||
*
|
*
|
||||||
* @param <PAIR> Type of the point/value pair returned by the optimization algorithm.
|
* @param <PAIR> Type of the point/value pair returned by the optimization algorithm.
|
||||||
* @param <OPTIM> Type of a subclass of this class. This parameter allows to implement
|
|
||||||
* fluent API methods at upper levels of the class hierarchy (since the
|
|
||||||
* fluent API requires that the actual type of the subclass is returned).
|
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @since 3.3
|
* @since 3.3
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractOptimizationProblem<PAIR>
|
public abstract class AbstractOptimizationProblem<PAIR>
|
||||||
implements OptimizationProblem<PAIR> {
|
implements OptimizationProblem<PAIR> {
|
||||||
|
|
||||||
|
/** Callback to use for the evaluation counter. */
|
||||||
|
private static final MaxEvalCallback MAX_EVAL_CALLBACK = new MaxEvalCallback();
|
||||||
|
/** Callback to use for the iteration counter. */
|
||||||
|
private static final MaxIterCallback MAX_ITER_CALLBACK = new MaxIterCallback();
|
||||||
|
|
||||||
/** max evaluations */
|
/** max evaluations */
|
||||||
private final int maxEvaluations;
|
private final int maxEvaluations;
|
||||||
/** max iterations */
|
/** max iterations */
|
||||||
private final int maxIterations;
|
private final int maxIterations;
|
||||||
/** Convergence checker. */
|
/** Convergence checker. */
|
||||||
private ConvergenceChecker<PAIR> checker = null;
|
private final ConvergenceChecker<PAIR> checker;
|
||||||
|
|
||||||
|
|
||||||
public Incrementor getEvaluationCounter() {
|
|
||||||
return new Incrementor(this.maxEvaluations, MAX_EVAL_CALLBACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Incrementor getIterationCounter() {
|
|
||||||
return new Incrementor(this.maxIterations, MAX_ITER_CALLBACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an {@link AbstractOptimizationProblem} from the given data.
|
||||||
|
*
|
||||||
|
* @param maxEvaluations the number of allowed model function evaluations.
|
||||||
|
* @param maxIterations the number of allowed iterations.
|
||||||
|
* @param checker the convergence checker.
|
||||||
|
*/
|
||||||
protected AbstractOptimizationProblem(final int maxEvaluations,
|
protected AbstractOptimizationProblem(final int maxEvaluations,
|
||||||
final int maxIterations,
|
final int maxIterations,
|
||||||
final ConvergenceChecker<PAIR> checker) {
|
final ConvergenceChecker<PAIR> checker) {
|
||||||
|
@ -60,6 +60,17 @@ public abstract class AbstractOptimizationProblem<PAIR>
|
||||||
this.checker = checker;
|
this.checker = checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public Incrementor getEvaluationCounter() {
|
||||||
|
return new Incrementor(this.maxEvaluations, MAX_EVAL_CALLBACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public Incrementor getIterationCounter() {
|
||||||
|
return new Incrementor(this.maxIterations, MAX_ITER_CALLBACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
public ConvergenceChecker<PAIR> getConvergenceChecker() {
|
public ConvergenceChecker<PAIR> getConvergenceChecker() {
|
||||||
return checker;
|
return checker;
|
||||||
}
|
}
|
||||||
|
@ -77,8 +88,6 @@ public abstract class AbstractOptimizationProblem<PAIR>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final MaxEvalCallback MAX_EVAL_CALLBACK = new MaxEvalCallback();
|
|
||||||
|
|
||||||
/** Defines the action to perform when reaching the maximum number of evaluations. */
|
/** Defines the action to perform when reaching the maximum number of evaluations. */
|
||||||
private static class MaxIterCallback
|
private static class MaxIterCallback
|
||||||
implements Incrementor.MaxCountExceededCallback {
|
implements Incrementor.MaxCountExceededCallback {
|
||||||
|
@ -92,5 +101,4 @@ public abstract class AbstractOptimizationProblem<PAIR>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final MaxIterCallback MAX_ITER_CALLBACK = new MaxIterCallback();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue