From 2295b7c2fb916e929ab117724d0c108db4e97ae1 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Fri, 15 Feb 2008 10:01:26 +0000 Subject: [PATCH] improved SOC between AbstractEstimator and its derived classes (changed fields from protected to private, changed methods to final, added counter incrementation final method) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@627987 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/estimation/AbstractEstimator.java | 21 ++++++++++++------- .../math/estimation/GaussNewtonEstimator.java | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/commons/math/estimation/AbstractEstimator.java b/src/java/org/apache/commons/math/estimation/AbstractEstimator.java index 1c0e5ad88..19e06a052 100644 --- a/src/java/org/apache/commons/math/estimation/AbstractEstimator.java +++ b/src/java/org/apache/commons/math/estimation/AbstractEstimator.java @@ -44,7 +44,7 @@ public abstract class AbstractEstimator implements Estimator { * @param maxCostEval maximal number of cost evaluations allowed * @see #estimate */ - public void setMaxCostEval(int maxCostEval) { + public final void setMaxCostEval(int maxCostEval) { this.maxCostEval = maxCostEval; } @@ -53,7 +53,7 @@ public abstract class AbstractEstimator implements Estimator { * * @return number of cost evaluations * */ - public int getCostEvaluations() { + public final int getCostEvaluations() { return costEvaluations; } @@ -62,7 +62,7 @@ public abstract class AbstractEstimator implements Estimator { * * @return number of jacobian evaluations * */ - public int getJacobianEvaluations() { + public final int getJacobianEvaluations() { return jacobianEvaluations; } @@ -70,7 +70,7 @@ public abstract class AbstractEstimator implements Estimator { * Update the jacobian matrix. */ protected void updateJacobian() { - ++jacobianEvaluations; + incrementJacobianEvaluationsCounter(); Arrays.fill(jacobian, 0); for (int i = 0, index = 0; i < rows; i++) { WeightedMeasurement wm = measurements[i]; @@ -81,6 +81,13 @@ public abstract class AbstractEstimator implements Estimator { } } + /** + * Increment the jacobian evaluations counter. + */ + protected final void incrementJacobianEvaluationsCounter() { + ++jacobianEvaluations; + } + /** * Update the residuals array and cost function value. * @exception EstimationException if the number of cost evaluations @@ -283,12 +290,12 @@ public abstract class AbstractEstimator implements Estimator { protected double cost; /** Maximal allowed number of cost evaluations. */ - protected int maxCostEval; + private int maxCostEval; /** Number of cost evaluations. */ - protected int costEvaluations; + private int costEvaluations; /** Number of jacobian evaluations. */ - protected int jacobianEvaluations; + private int jacobianEvaluations; } \ No newline at end of file diff --git a/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java b/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java index b2732b0b4..6361fb04f 100644 --- a/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java +++ b/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java @@ -116,7 +116,7 @@ public class GaussNewtonEstimator extends AbstractEstimator implements Serializa do { // build the linear problem - ++jacobianEvaluations; + incrementJacobianEvaluationsCounter(); RealMatrix b = new RealMatrixImpl(parameters.length, 1); RealMatrix a = new RealMatrixImpl(parameters.length, parameters.length); for (int i = 0; i < measurements.length; ++i) {