diff --git a/src/java/org/apache/commons/math/estimation/AbstractEstimator.java b/src/java/org/apache/commons/math/estimation/AbstractEstimator.java index b26dcd55f..8c344f241 100644 --- a/src/java/org/apache/commons/math/estimation/AbstractEstimator.java +++ b/src/java/org/apache/commons/math/estimation/AbstractEstimator.java @@ -34,10 +34,16 @@ import org.apache.commons.math.linear.decomposition.LUDecompositionImpl; */ public abstract class AbstractEstimator implements Estimator { + /** Default maximal number of cost evaluations allowed. */ + public static final int DEFAULT_MAX_COST_EVALUATIONS = 100; + /** * Build an abstract estimator for least squares problems. + *

The maximal number of cost evaluations allowed is set + * to its default value {@link #DEFAULT_MAX_COST_EVALUATIONS}.

*/ protected AbstractEstimator() { + setMaxCostEval(DEFAULT_MAX_COST_EVALUATIONS); } /** diff --git a/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java b/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java index 7a1c14c48..722544d27 100644 --- a/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java +++ b/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java @@ -40,6 +40,34 @@ import org.apache.commons.math.linear.decomposition.LUDecompositionImpl; public class GaussNewtonEstimator extends AbstractEstimator implements Serializable { + /** Serializable version identifier */ + private static final long serialVersionUID = 5485001826076289109L; + + /** Default threshold for cost steady state detection. */ + private static final double DEFAULT_STEADY_STATE_THRESHOLD = 1.0e-6; + + /** Default threshold for cost convergence. */ + private static final double DEFAULT_CONVERGENCE = 1.0e-6; + + /** Threshold for cost steady state detection. */ + private double steadyStateThreshold; + + /** Threshold for cost convergence. */ + private double convergence; + + /** Simple constructor with default settings. + *

+ * The estimator is built with default values for all settings. + *

+ * @see #DEFAULT_STEADY_STATE_THRESHOLD + * @see #DEFAULT_CONVERGENCE + * @see AbstractEstimator#DEFAULT_MAX_COST_EVALUATIONS + */ + public GaussNewtonEstimator() { + this.steadyStateThreshold = DEFAULT_STEADY_STATE_THRESHOLD; + this.convergence = DEFAULT_CONVERGENCE; + } + /** * Simple constructor. * @@ -66,19 +94,42 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa * to improve the criterion anymore * @param steadyStateThreshold steady state detection threshold, the * problem has converged has reached a steady state if - * Math.abs (Jn - Jn-1) < Jn * convergence, where - * Jn and Jn-1 are the current and - * preceding criterion value (square sum of the weighted residuals - * of considered measurements). + * Math.abs(Jn - Jn-1) < + * Jn × convergence, where Jn + * and Jn-1 are the current and preceding criterion + * values (square sum of the weighted residuals of considered measurements). */ - public GaussNewtonEstimator(int maxCostEval, - double convergence, - double steadyStateThreshold) { + public GaussNewtonEstimator(final int maxCostEval, final double convergence, + final double steadyStateThreshold) { setMaxCostEval(maxCostEval); this.steadyStateThreshold = steadyStateThreshold; this.convergence = convergence; } + /** + * Set the convergence criterion threshold. + * @param convergence criterion threshold below which we do not need + * to improve the criterion anymore + */ + public void setConvergence(final double convergence) { + this.convergence = convergence; + } + + /** + * Set the steady state detection threshold. + *

+ * The problem has converged has reached a steady state if + * Math.abs(Jn - Jn-1) < + * Jn × convergence, where Jn + * and Jn-1 are the current and preceding criterion + * values (square sum of the weighted residuals of considered measurements). + *

+ * @param steadyStateThreshold steady state detection threshold + */ + public void setSteadyStateThreshold(final double steadyStateThreshold) { + this.steadyStateThreshold = steadyStateThreshold; + } + /** * Solve an estimation problem using a least squares criterion. * @@ -92,7 +143,7 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa * below a physical threshold under which improvement are considered * useless or when the algorithm is unable to improve it (even if it * is still high). The first condition that is met stops the - * iterations. If the convergence it nos reached before the maximum + * iterations. If the convergence it not reached before the maximum * number of iterations, an {@link EstimationException} is * thrown.

* @@ -172,13 +223,4 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa } - /** Threshold for cost steady state detection. */ - private double steadyStateThreshold; - - /** Threshold for cost convergence. */ - private double convergence; - - /** Serializable version identifier */ - private static final long serialVersionUID = 5485001826076289109L; - }