Author: luc
Date: Sun Jan 20 09:30:18 2008
New Revision: 613633
URL: http://svn.apache.org/viewvc?rev=613633&view=rev
Log:
changed public fields to private and added accessors
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
Sun Jan 20 09:30:18 2008
@@ -543,8 +543,8 @@
// evaluate the cost at all non-evaluated simplex points
for (int i = 0; i < simplex.length; ++i) {
PointCostPair pair = simplex[i];
- if (Double.isNaN(pair.cost)) {
- simplex[i] = new PointCostPair(pair.point,
evaluateCost(pair.point));
+ if (Double.isNaN(pair.getCost())) {
+ simplex[i] = new PointCostPair(pair.getPoint(),
evaluateCost(pair.getPoint()));
}
}
@@ -559,7 +559,7 @@
protected void replaceWorstPoint(PointCostPair pointCostPair) {
int n = simplex.length - 1;
for (int i = 0; i < n; ++i) {
- if (simplex[i].cost > pointCostPair.cost) {
+ if (simplex[i].getCost() > pointCostPair.getCost()) {
PointCostPair tmp = simplex[i];
simplex[i] = pointCostPair;
pointCostPair = tmp;
@@ -576,8 +576,8 @@
} else if (o2 == null) {
return -1;
}
- double cost1 = ((PointCostPair) o1).cost;
- double cost2 = ((PointCostPair) o2).cost;
+ double cost1 = ((PointCostPair) o1).getCost();
+ double cost2 = ((PointCostPair) o2).getCost();
return (cost1 < cost2) ? -1 : ((o1 == o2) ? 0 : +1);
}
};
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
Sun Jan 20 09:30:18 2008
@@ -55,7 +55,7 @@
// save the original vertex
PointCostPair[] original = simplex;
- double originalCost = original[0].cost;
+ double originalCost = original[0].getCost();
// perform a reflection step
double reflectedCost = evaluateNewSimplex(original, 1.0);
@@ -94,14 +94,14 @@
private double evaluateNewSimplex(PointCostPair[] original, double coeff)
throws CostException {
- double[] xSmallest = original[0].point;
+ double[] xSmallest = original[0].getPoint();
int n = xSmallest.length;
// create the linearly transformed simplex
simplex = new PointCostPair[n + 1];
simplex[0] = original[0];
for (int i = 1; i <= n; ++i) {
- double[] xOriginal = original[i].point;
+ double[] xOriginal = original[i].getPoint();
double[] xTransformed = new double[n];
for (int j = 0; j < n; ++j) {
xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
@@ -111,7 +111,7 @@
// evaluate it
evaluateSimplex();
- return simplex[0].cost;
+ return simplex[0].getCost();
}
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
Sun Jan 20 09:30:18 2008
@@ -62,16 +62,16 @@
int n = simplex.length - 1;
// interesting costs
- double smallest = simplex[0].cost;
- double secondLargest = simplex[n-1].cost;
- double largest = simplex[n].cost;
- double[] xLargest = simplex[n].point;
+ double smallest = simplex[0].getCost();
+ double secondLargest = simplex[n-1].getCost();
+ double largest = simplex[n].getCost();
+ double[] xLargest = simplex[n].getPoint();
// compute the centroid of the best vertices
// (dismissing the worst point at index n)
double[] centroid = new double[n];
for (int i = 0; i < n; ++i) {
- double[] x = simplex[i].point;
+ double[] x = simplex[i].getPoint();
for (int j = 0; j < n; ++j) {
centroid[j] += x[j];
}
@@ -145,9 +145,9 @@
}
// perform a shrink
- double[] xSmallest = simplex[0].point;
+ double[] xSmallest = simplex[0].getPoint();
for (int i = 1; i < simplex.length; ++i) {
- double[] x = simplex[i].point;
+ double[] x = simplex[i].getPoint();
for (int j = 0; j < n; ++j) {
x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]);
}
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
Sun Jan 20 09:30:18 2008
@@ -33,10 +33,24 @@
this.cost = cost;
}
+ /** Get the point.
+ * @return the stored point
+ */
+ public double[] getPoint() {
+ return point;
+ }
+
+ /** Get the cost.
+ * @return the stored cost
+ */
+ public double getCost() {
+ return cost;
+ }
+
/** Point coordinates. */
- public final double[] point;
+ private final double[] point;
/** Cost associated to the point. */
- public final double cost;
+ private final double cost;
}
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
Sun Jan 20 09:30:18 2008
@@ -89,7 +89,7 @@
});
assertTrue(count > 60);
- assertTrue(optimum.cost > 0.01);
+ assertTrue(optimum.getCost() > 0.01);
}
@@ -114,7 +114,7 @@
new double[] { 3.0, -1.0, 0.0, 1.0 },
new double[] { 4.0, 0.0, 1.0, 2.0 });
assertTrue(count > 850);
- assertTrue(optimum.cost > 0.015);
+ assertTrue(optimum.getCost() > 0.015);
}
@@ -127,7 +127,7 @@
public boolean converged(PointCostPair[] simplex) {
PointCostPair smallest = simplex[0];
PointCostPair largest = simplex[simplex.length - 1];
- return (largest.cost - smallest.cost) < threshold;
+ return (largest.getCost() - smallest.getCost()) < threshold;
}
private double threshold;
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java?rev=613633&r1=613632&r2=613633&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
Sun Jan 20 09:30:18 2008
@@ -110,9 +110,9 @@
assertTrue(count > 700);
assertTrue(count < 800);
- assertEquals(0.0, optimum.cost, 5.0e-5);
- assertEquals(1.0, optimum.point[0], 0.01);
- assertEquals(1.0, optimum.point[1], 0.01);
+ assertEquals(0.0, optimum.getCost(), 5.0e-5);
+ assertEquals(1.0, optimum.getPoint()[0], 0.01);
+ assertEquals(1.0, optimum.getPoint()[1], 0.01);
PointCostPair[] minima = nm.getMinima();
assertEquals(10, minima.length);
@@ -125,7 +125,7 @@
}
} else {
if (i > 0) {
- assertTrue(minima[i-1].cost <= minima[i].cost);
+ assertTrue(minima[i-1].getCost() <= minima[i].getCost());
}
}
}
@@ -138,10 +138,10 @@
new UniformRandomGenerator(rg));
optimum =
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3), rvg);
- assertEquals(0.0, optimum.cost, 2.0e-4);
+ assertEquals(0.0, optimum.getCost(), 2.0e-4);
optimum =
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3), rvg, 3);
- assertEquals(0.0, optimum.cost, 3.0e-5);
+ assertEquals(0.0, optimum.getCost(), 3.0e-5);
}
@@ -168,11 +168,11 @@
new double[] { 4.0, 0.0, 1.0, 2.0 },
1, 1642738l);
assertTrue(count < 150);
- assertEquals(0.0, optimum.cost, 6.0e-4);
- assertEquals(0.0, optimum.point[0], 0.07);
- assertEquals(0.0, optimum.point[1], 0.07);
- assertEquals(0.0, optimum.point[2], 0.07);
- assertEquals(0.0, optimum.point[3], 0.07);
+ assertEquals(0.0, optimum.getCost(), 6.0e-4);
+ assertEquals(0.0, optimum.getPoint()[0], 0.07);
+ assertEquals(0.0, optimum.getPoint()[1], 0.07);
+ assertEquals(0.0, optimum.getPoint()[2], 0.07);
+ assertEquals(0.0, optimum.getPoint()[3], 0.07);
}
@@ -185,7 +185,7 @@
public boolean converged(PointCostPair[] simplex) {
PointCostPair smallest = simplex[0];
PointCostPair largest = simplex[simplex.length - 1];
- return (largest.cost - smallest.cost) < threshold;
+ return (largest.getCost() - smallest.getCost()) < threshold;
}
private double threshold;