fixed functions names (minimizes -> minimize)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@628000 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7f5355a3ea
commit
651cae8991
|
@ -58,12 +58,12 @@ import org.apache.commons.math.stat.descriptive.moment.VectorialMean;
|
||||||
* multi-start mode. Multi-start is a traditional way to try to avoid
|
* multi-start mode. Multi-start is a traditional way to try to avoid
|
||||||
* being trapped in a local minimum and miss the global minimum of a
|
* being trapped in a local minimum and miss the global minimum of a
|
||||||
* function. It can also be used to verify the convergence of an
|
* function. It can also be used to verify the convergence of an
|
||||||
* algorithm. The various multi-start-enabled <code>minimizes</code>
|
* algorithm. The various multi-start-enabled <code>minimize</code>
|
||||||
* methods return the best minimum found after all starts, and the
|
* methods return the best minimum found after all starts, and the
|
||||||
* {@link #getMinima getMinima} method can be used to retrieve all
|
* {@link #getMinima getMinima} method can be used to retrieve all
|
||||||
* minima from all starts (including the one already provided by the
|
* minima from all starts (including the one already provided by the
|
||||||
* {@link #minimizes(CostFunction, int, ConvergenceChecker, double[],
|
* {@link #minimize(CostFunction, int, ConvergenceChecker, double[],
|
||||||
* double[]) minimizes} method).</p>
|
* double[]) minimize} method).</p>
|
||||||
*
|
*
|
||||||
* <p>This class is the base class performing the boilerplate simplex
|
* <p>This class is the base class performing the boilerplate simplex
|
||||||
* initialization and handling. The simplex update by itself is
|
* initialization and handling. The simplex update by itself is
|
||||||
|
@ -107,9 +107,9 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
double[] vertexA, double[] vertexB)
|
double[] vertexA, double[] vertexB)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
// set up optimizer
|
// set up optimizer
|
||||||
|
@ -117,7 +117,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setSingleStart();
|
setSingleStart();
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,10 +149,10 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
double[] vertexA, double[] vertexB,
|
double[] vertexA, double[] vertexB,
|
||||||
int starts, long seed)
|
int starts, long seed)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
// set up the simplex traveling around the box
|
// set up the simplex traveling around the box
|
||||||
|
@ -176,7 +176,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setMultiStart(starts, rvg);
|
setMultiStart(starts, rvg);
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,9 +197,9 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
double[][] vertices)
|
double[][] vertices)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
// set up optimizer
|
// set up optimizer
|
||||||
|
@ -207,7 +207,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setSingleStart();
|
setSingleStart();
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,10 +234,10 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
double[][] vertices,
|
double[][] vertices,
|
||||||
int starts, long seed)
|
int starts, long seed)
|
||||||
throws NotPositiveDefiniteMatrixException,
|
throws NotPositiveDefiniteMatrixException,
|
||||||
CostException, ConvergenceException {
|
CostException, ConvergenceException {
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setMultiStart(starts, rvg);
|
setMultiStart(starts, rvg);
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
} catch (DimensionMismatchException dme) {
|
} catch (DimensionMismatchException dme) {
|
||||||
// this should not happen
|
// this should not happen
|
||||||
|
@ -291,9 +291,9 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
RandomVectorGenerator generator)
|
RandomVectorGenerator generator)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
// set up optimizer
|
// set up optimizer
|
||||||
|
@ -301,7 +301,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setSingleStart();
|
setSingleStart();
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,10 +325,10 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
public PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
public PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker,
|
ConvergenceChecker checker,
|
||||||
RandomVectorGenerator generator,
|
RandomVectorGenerator generator,
|
||||||
int starts)
|
int starts)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
// set up optimizer
|
// set up optimizer
|
||||||
|
@ -336,7 +336,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
setMultiStart(starts, generator);
|
setMultiStart(starts, generator);
|
||||||
|
|
||||||
// compute minimum
|
// compute minimum
|
||||||
return minimizes(f, maxEvaluations, checker);
|
return minimize(f, maxEvaluations, checker);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,27 +426,27 @@ public abstract class DirectSearchOptimizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get all the minima found during the last call to {@link
|
/** Get all the minima found during the last call to {@link
|
||||||
* #minimizes(CostFunction, int, ConvergenceChecker, double[], double[])
|
* #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
|
||||||
* minimizes}.
|
* minimize}.
|
||||||
* <p>The optimizer stores all the minima found during a set of
|
* <p>The optimizer stores all the minima found during a set of
|
||||||
* restarts when multi-start mode is enabled. The {@link
|
* restarts when multi-start mode is enabled. The {@link
|
||||||
* #minimizes(CostFunction, int, ConvergenceChecker, double[], double[])
|
* #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
|
||||||
* minimizes} method returns the best point only. This method
|
* minimize} method returns the best point only. This method
|
||||||
* returns all the points found at the end of each starts, including
|
* returns all the points found at the end of each starts, including
|
||||||
* the best one already returned by the {@link #minimizes(CostFunction,
|
* the best one already returned by the {@link #minimize(CostFunction,
|
||||||
* int, ConvergenceChecker, double[], double[]) minimizes} method.
|
* int, ConvergenceChecker, double[], double[]) minimize} method.
|
||||||
* The array as one element for each start as specified in the constructor
|
* The array as one element for each start as specified in the constructor
|
||||||
* (it has one element only if optimizer has been set up for single-start).</p>
|
* (it has one element only if optimizer has been set up for single-start).</p>
|
||||||
* <p>The array containing the minima is ordered with the results
|
* <p>The array containing the minima is ordered with the results
|
||||||
* from the runs that did converge first, sorted from lowest to
|
* from the runs that did converge first, sorted from lowest to
|
||||||
* highest minimum cost, and null elements corresponding to the runs
|
* highest minimum cost, and null elements corresponding to the runs
|
||||||
* that did not converge (all elements will be null if the {@link
|
* that did not converge (all elements will be null if the {@link
|
||||||
* #minimizes(CostFunction, int, ConvergenceChecker, double[], double[])
|
* #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
|
||||||
* minimizes} method did throw a {@link ConvergenceException
|
* minimize} method did throw a {@link ConvergenceException
|
||||||
* ConvergenceException}).</p>
|
* ConvergenceException}).</p>
|
||||||
* @return array containing the minima, or null if {@link
|
* @return array containing the minima, or null if {@link
|
||||||
* #minimizes(CostFunction, int, ConvergenceChecker, double[], double[])
|
* #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
|
||||||
* minimizes} has not been called
|
* minimize} has not been called
|
||||||
*/
|
*/
|
||||||
public PointCostPair[] getMinima() {
|
public PointCostPair[] getMinima() {
|
||||||
return (PointCostPair[]) minima.clone();
|
return (PointCostPair[]) minima.clone();
|
||||||
|
@ -466,7 +466,7 @@ public abstract class DirectSearchOptimizer {
|
||||||
* @exception ConvergenceException if none of the starts did
|
* @exception ConvergenceException if none of the starts did
|
||||||
* converge (it is not thrown if at least one start did converge)
|
* converge (it is not thrown if at least one start did converge)
|
||||||
*/
|
*/
|
||||||
private PointCostPair minimizes(CostFunction f, int maxEvaluations,
|
private PointCostPair minimize(CostFunction f, int maxEvaluations,
|
||||||
ConvergenceChecker checker)
|
ConvergenceChecker checker)
|
||||||
throws CostException, ConvergenceException {
|
throws CostException, ConvergenceException {
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class MultiDirectionalTest
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
new MultiDirectional(1.9, 0.4).minimizes(wrong, 10, new ValueChecker(1.0e-3),
|
new MultiDirectional(1.9, 0.4).minimize(wrong, 10, new ValueChecker(1.0e-3),
|
||||||
new double[] { -0.5 }, new double[] { 0.5 });
|
new double[] { -0.5 }, new double[] { 0.5 });
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (CostException ce) {
|
} catch (CostException ce) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
|
@ -57,8 +57,8 @@ public class MultiDirectionalTest
|
||||||
fail("wrong exception caught: " + e.getMessage());
|
fail("wrong exception caught: " + e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new MultiDirectional(1.9, 0.4).minimizes(wrong, 10, new ValueChecker(1.0e-3),
|
new MultiDirectional(1.9, 0.4).minimize(wrong, 10, new ValueChecker(1.0e-3),
|
||||||
new double[] { 0.5 }, new double[] { 1.5 });
|
new double[] { 0.5 }, new double[] { 1.5 });
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (CostException ce) {
|
} catch (CostException ce) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
|
@ -83,10 +83,10 @@ public class MultiDirectionalTest
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
PointCostPair optimum =
|
PointCostPair optimum =
|
||||||
new MultiDirectional().minimizes(rosenbrock, 100, new ValueChecker(1.0e-3),
|
new MultiDirectional().minimize(rosenbrock, 100, new ValueChecker(1.0e-3),
|
||||||
new double[][] {
|
new double[][] {
|
||||||
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
|
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
|
||||||
});
|
});
|
||||||
|
|
||||||
assertTrue(count > 60);
|
assertTrue(count > 60);
|
||||||
assertTrue(optimum.getCost() > 0.01);
|
assertTrue(optimum.getCost() > 0.01);
|
||||||
|
@ -110,9 +110,9 @@ public class MultiDirectionalTest
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
PointCostPair optimum =
|
PointCostPair optimum =
|
||||||
new MultiDirectional().minimizes(powell, 1000, new ValueChecker(1.0e-3),
|
new MultiDirectional().minimize(powell, 1000, new ValueChecker(1.0e-3),
|
||||||
new double[] { 3.0, -1.0, 0.0, 1.0 },
|
new double[] { 3.0, -1.0, 0.0, 1.0 },
|
||||||
new double[] { 4.0, 0.0, 1.0, 2.0 });
|
new double[] { 4.0, 0.0, 1.0, 2.0 });
|
||||||
assertTrue(count > 850);
|
assertTrue(count > 850);
|
||||||
assertTrue(optimum.getCost() > 0.015);
|
assertTrue(optimum.getCost() > 0.015);
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class NelderMeadTest
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
new NelderMead(0.9, 1.9, 0.4, 0.6).minimizes(wrong, 10, new ValueChecker(1.0e-3),
|
new NelderMead(0.9, 1.9, 0.4, 0.6).minimize(wrong, 10, new ValueChecker(1.0e-3),
|
||||||
new double[] { -0.5 }, new double[] { 0.5 });
|
new double[] { -0.5 }, new double[] { 0.5 });
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (CostException ce) {
|
} catch (CostException ce) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
|
@ -63,8 +63,8 @@ public class NelderMeadTest
|
||||||
fail("wrong exception caught: " + e.getMessage());
|
fail("wrong exception caught: " + e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new NelderMead(0.9, 1.9, 0.4, 0.6).minimizes(wrong, 10, new ValueChecker(1.0e-3),
|
new NelderMead(0.9, 1.9, 0.4, 0.6).minimize(wrong, 10, new ValueChecker(1.0e-3),
|
||||||
new double[] { 0.5 }, new double[] { 1.5 });
|
new double[] { 0.5 }, new double[] { 1.5 });
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (CostException ce) {
|
} catch (CostException ce) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
|
@ -90,10 +90,10 @@ public class NelderMeadTest
|
||||||
count = 0;
|
count = 0;
|
||||||
NelderMead nm = new NelderMead();
|
NelderMead nm = new NelderMead();
|
||||||
try {
|
try {
|
||||||
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3),
|
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3),
|
||||||
new double[][] {
|
new double[][] {
|
||||||
{ -1.2, 1.0 }, { 3.5, -2.3 }, { 0.4, 1.5 }
|
{ -1.2, 1.0 }, { 3.5, -2.3 }, { 0.4, 1.5 }
|
||||||
}, 1, 5384353l);
|
}, 1, 5384353l);
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (ConvergenceException ce) {
|
} catch (ConvergenceException ce) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
|
@ -103,10 +103,10 @@ public class NelderMeadTest
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
PointCostPair optimum =
|
PointCostPair optimum =
|
||||||
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3),
|
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3),
|
||||||
new double[][] {
|
new double[][] {
|
||||||
{ -1.2, 1.0 }, { 0.9, 1.2 }, { 3.5, -2.3 }
|
{ -1.2, 1.0 }, { 0.9, 1.2 }, { 3.5, -2.3 }
|
||||||
}, 10, 1642738l);
|
}, 10, 1642738l);
|
||||||
|
|
||||||
assertTrue(count > 700);
|
assertTrue(count > 700);
|
||||||
assertTrue(count < 800);
|
assertTrue(count < 800);
|
||||||
|
@ -137,10 +137,10 @@ public class NelderMeadTest
|
||||||
new double[] { 0.2, 0.2 },
|
new double[] { 0.2, 0.2 },
|
||||||
new UniformRandomGenerator(rg));
|
new UniformRandomGenerator(rg));
|
||||||
optimum =
|
optimum =
|
||||||
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3), rvg);
|
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3), rvg);
|
||||||
assertEquals(0.0, optimum.getCost(), 2.0e-4);
|
assertEquals(0.0, optimum.getCost(), 2.0e-4);
|
||||||
optimum =
|
optimum =
|
||||||
nm.minimizes(rosenbrock, 100, new ValueChecker(1.0e-3), rvg, 3);
|
nm.minimize(rosenbrock, 100, new ValueChecker(1.0e-3), rvg, 3);
|
||||||
assertEquals(0.0, optimum.getCost(), 3.0e-5);
|
assertEquals(0.0, optimum.getCost(), 3.0e-5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -163,10 +163,10 @@ public class NelderMeadTest
|
||||||
count = 0;
|
count = 0;
|
||||||
NelderMead nm = new NelderMead();
|
NelderMead nm = new NelderMead();
|
||||||
PointCostPair optimum =
|
PointCostPair optimum =
|
||||||
nm.minimizes(powell, 200, new ValueChecker(1.0e-3),
|
nm.minimize(powell, 200, new ValueChecker(1.0e-3),
|
||||||
new double[] { 3.0, -1.0, 0.0, 1.0 },
|
new double[] { 3.0, -1.0, 0.0, 1.0 },
|
||||||
new double[] { 4.0, 0.0, 1.0, 2.0 },
|
new double[] { 4.0, 0.0, 1.0, 2.0 },
|
||||||
1, 1642738l);
|
1, 1642738l);
|
||||||
assertTrue(count < 150);
|
assertTrue(count < 150);
|
||||||
assertEquals(0.0, optimum.getCost(), 6.0e-4);
|
assertEquals(0.0, optimum.getCost(), 6.0e-4);
|
||||||
assertEquals(0.0, optimum.getPoint()[0], 0.07);
|
assertEquals(0.0, optimum.getPoint()[0], 0.07);
|
||||||
|
|
Loading…
Reference in New Issue