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:
Luc Maisonobe 2014-02-18 14:33:14 +00:00
parent 8916830e8a
commit 46b2ce2ee0
4 changed files with 68 additions and 26 deletions

View File

@ -119,6 +119,7 @@ public class GaussNewtonOptimizer implements LeastSquaresOptimizer {
return new GaussNewtonOptimizer(decomposition);
}
/** {@inheritDoc} */
public Optimum optimize(final LeastSquaresProblem lsp) {
//create local evaluation and iteration counts
final Incrementor evaluationCounter = lsp.getEvaluationCounter();

View File

@ -41,6 +41,16 @@ class LeastSquaresProblemImpl
/** Initial guess. */
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,
final RealVector target,
final RealVector start,
@ -53,18 +63,22 @@ class LeastSquaresProblemImpl
this.start = start;
}
/** {@inheritDoc} */
public int getObservationSize() {
return target.getDimension();
}
/** {@inheritDoc} */
public int getParameterSize() {
return start.getDimension();
}
/** {@inheritDoc} */
public RealVector getStart() {
return start == null ? null : start.copy();
}
/** {@inheritDoc} */
public Evaluation evaluate(final RealVector point) {
//evaluate value and jacobian in one function call
final Pair<RealVector, RealMatrix> value = this.model.value(point);
@ -91,6 +105,14 @@ class LeastSquaresProblemImpl
/** reference to the observed values */
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,
final RealMatrix jacobian,
final RealVector target,
@ -102,19 +124,22 @@ class LeastSquaresProblemImpl
this.point = point;
}
/** {@inheritDoc} */
public RealVector computeValue() {
return this.values;
}
/** {@inheritDoc} */
public RealMatrix computeJacobian() {
return this.jacobian;
}
/** {@inheritDoc} */
public RealVector getPoint() {
return this.point;
}
/** {@inheritDoc} */
public RealVector computeResiduals() {
return target.subtract(this.computeValue());
}

View File

@ -3,19 +3,27 @@ package org.apache.commons.math3.fitting.leastsquares;
import org.apache.commons.math3.optim.ConvergenceChecker;
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> {
/**
* Get a independent Incrementor that counts up to {@link #getMaxEvaluations()} and
* then throws an exception.
* Get a independent Incrementor that counts up to the maximum number of evaluations
* and then throws an exception.
*
* @return a counter for the evaluations.
*/
Incrementor getEvaluationCounter();
/**
* Get a independent Incrementor that counts up to {@link #getMaxIterations()} and
* then throws an exception.
* Get a independent Incrementor that counts up to the maximum number of iterations
* and then throws an exception.
*
* @return a counter for the evaluations.
*/

View File

@ -22,36 +22,36 @@ import org.apache.commons.math3.fitting.leastsquares.OptimizationProblem;
import org.apache.commons.math3.util.Incrementor;
/**
* Base class for implementing optimizers. It contains the boiler-plate code for counting
* the number of evaluations of the objective function and the number of iterations of the
* algorithm, and storing the convergence checker.
* Base class for implementing optimization problems. It contains the boiler-plate code
* for counting the number of evaluations of the objective function and the number of
* iterations of the algorithm, and storing the convergence checker.
*
* @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).
* @param <PAIR> Type of the point/value pair returned by the optimization algorithm.
* @version $Id$
* @since 3.3
*/
public abstract class AbstractOptimizationProblem<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 */
private final int maxEvaluations;
/** max iterations */
private final int maxIterations;
/** Convergence checker. */
private ConvergenceChecker<PAIR> checker = null;
public Incrementor getEvaluationCounter() {
return new Incrementor(this.maxEvaluations, MAX_EVAL_CALLBACK);
}
public Incrementor getIterationCounter() {
return new Incrementor(this.maxIterations, MAX_ITER_CALLBACK);
}
private final ConvergenceChecker<PAIR> checker;
/**
* 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,
final int maxIterations,
final ConvergenceChecker<PAIR> checker) {
@ -60,6 +60,17 @@ public abstract class AbstractOptimizationProblem<PAIR>
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() {
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. */
private static class MaxIterCallback
implements Incrementor.MaxCountExceededCallback {
@ -92,5 +101,4 @@ public abstract class AbstractOptimizationProblem<PAIR>
}
}
private static final MaxIterCallback MAX_ITER_CALLBACK = new MaxIterCallback();
}