You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/03/24 23:09:35 UTC
svn commit: r758049 - in
/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization:
./ univariate/
Author: luc
Date: Tue Mar 24 22:09:34 2009
New Revision: 758049
URL: http://svn.apache.org/viewvc?rev=758049&view=rev
Log:
improved consistency in class naming with respect to functions in the analysis package
Added:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java (contents, props changed)
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java (contents, props changed)
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java (contents, props changed)
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java (contents, props changed)
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartVectorialDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java (with props)
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultivariateRealOptimizer.java
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealConvergenceChecker.java
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarConvergenceChecker.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealPointValuePair.java
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarPointValuePair.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java
- copied, changed from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java
Removed:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartVectorialDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarConvergenceChecker.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarPointValuePair.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialDifferentiableOptimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizerImpl.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialConvergenceChecker.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialPointValuePair.java
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarDifferentiableOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarDifferentiableOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarDifferentiableOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -19,15 +19,20 @@
import java.io.Serializable;
+import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction;
+
/**
- * This interface represents an optimization algorithm for {@link ScalarDifferentiableObjectiveFunction
+ * This interface represents an optimization algorithm for {@link DifferentiableMultivariateRealFunction
* scalar differentiable objective functions}.
- * @see ScalarOptimizer
- * @see VectorialDifferentiableOptimizer
+ * <p>Optimization algorithms find the input point set that either {@link GoalType
+ * maximize or minimize} an objective function.</p>
+ * @see MultivariateRealOptimizer
+ * @see DifferentiableMultivariateVectorialOptimizer
* @version $Revision$ $Date$
* @since 2.0
*/
-public interface ScalarDifferentiableOptimizer extends Serializable {
+public interface DifferentiableMultivariateRealOptimizer extends Serializable {
/** Set the maximal number of iterations of the algorithm.
* @param maxIterations maximal number of function calls
@@ -42,7 +47,7 @@
/** Get the number of iterations realized by the algorithm.
* <p>
* The number of evaluations corresponds to the last call to the
- * {@link #optimize(ScalarDifferentiableObjectiveFunction, GoalType, double[]) optimize}
+ * {@link #optimize(DifferentiableMultivariateRealFunction, GoalType, double[]) optimize}
* method. It is 0 if the method has not been called yet.
* </p>
* @return number of iterations
@@ -52,7 +57,7 @@
/** Get the number of evaluations of the objective function.
* <p>
* The number of evaluations corresponds to the last call to the
- * {@link #optimize(ScalarDifferentiableObjectiveFunction, GoalType, double[]) optimize}
+ * {@link #optimize(DifferentiableMultivariateRealFunction, GoalType, double[]) optimize}
* method. It is 0 if the method has not been called yet.
* </p>
* @return number of evaluations of the objective function
@@ -62,7 +67,7 @@
/** Get the number of evaluations of the objective function gradient.
* <p>
* The number of evaluations corresponds to the last call to the
- * {@link #optimize(ScalarDifferentiableObjectiveFunction, GoalType, double[]) optimize}
+ * {@link #optimize(DifferentiableMultivariateRealFunction, GoalType, double[]) optimize}
* method. It is 0 if the method has not been called yet.
* </p>
* @return number of evaluations of the objective function gradient
@@ -72,12 +77,12 @@
/** Set the convergence checker.
* @param checker object to use to check for convergence
*/
- void setConvergenceChecker(ScalarConvergenceChecker checker);
+ void setConvergenceChecker(RealConvergenceChecker checker);
/** Get the convergence checker.
* @return object used to check for convergence
*/
- ScalarConvergenceChecker getConvergenceChecker();
+ RealConvergenceChecker getConvergenceChecker();
/** Optimizes an objective function.
* @param f objective function
@@ -85,14 +90,14 @@
* or {@link GoalType#MINIMIZE}
* @param startPoint the start point for optimization
* @return the point/value pair giving the optimal value for objective function
- * @exception ObjectiveException if the objective function throws one during
+ * @exception FunctionEvaluationException if the objective function throws one during
* the search
* @exception OptimizationException if the algorithm failed to converge
* @exception IllegalArgumentException if the start point dimension is wrong
*/
- ScalarPointValuePair optimize(ScalarDifferentiableObjectiveFunction f,
+ RealPointValuePair optimize(DifferentiableMultivariateRealFunction f,
GoalType goalType,
double[] startPoint)
- throws ObjectiveException, OptimizationException, IllegalArgumentException;
+ throws FunctionEvaluationException, OptimizationException, IllegalArgumentException;
}
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialDifferentiableOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialDifferentiableOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialDifferentiableOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java Tue Mar 24 22:09:34 2009
@@ -19,15 +19,20 @@
import java.io.Serializable;
+import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
+
/**
- * This interface represents an optimization algorithm for {@link VectorialDifferentiableObjectiveFunction
+ * This interface represents an optimization algorithm for {@link DifferentiableMultivariateVectorialFunction
* vectorial differentiable objective functions}.
- * @see ScalarOptimizer
- * @see ScalarDifferentiableOptimizer
+ * <p>Optimization algorithms find the input point set that either {@link GoalType
+ * maximize or minimize} an objective function.</p>
+ * @see MultivariateRealOptimizer
+ * @see DifferentiableMultivariateRealOptimizer
* @version $Revision$ $Date$
* @since 2.0
*/
-public interface VectorialDifferentiableOptimizer extends Serializable {
+public interface DifferentiableMultivariateVectorialOptimizer extends Serializable {
/** Set the maximal number of iterations of the algorithm.
* @param maxIterations maximal number of function calls
@@ -86,14 +91,14 @@
* @param weights weight for the least squares cost computation
* @param startPoint the start point for optimization
* @return the point/value pair giving the optimal value for objective function
- * @exception ObjectiveException if the objective function throws one during
+ * @exception FunctionEvaluationException if the objective function throws one during
* the search
* @exception OptimizationException if the algorithm failed to converge
* @exception IllegalArgumentException if the start point dimension is wrong
*/
- VectorialPointValuePair optimize(VectorialDifferentiableObjectiveFunction f,
+ VectorialPointValuePair optimize(DifferentiableMultivariateVectorialFunction f,
double[] target, double[] weights,
double[] startPoint)
- throws ObjectiveException, OptimizationException, IllegalArgumentException;
+ throws FunctionEvaluationException, OptimizationException, IllegalArgumentException;
}
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarDifferentiableOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarDifferentiableOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarDifferentiableOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -21,11 +21,14 @@
import java.util.Comparator;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.random.RandomVectorGenerator;
/**
- * Special implementation of the {@link ScalarDifferentiableOptimizer} interface adding
+ * Special implementation of the {@link DifferentiableMultivariateRealOptimizer} interface adding
* multi-start features to an existing optimizer.
* <p>
* This class wraps a classical optimizer to use it several times in
@@ -35,13 +38,14 @@
* @version $Revision$ $Date$
* @since 2.0
*/
-public class MultiStartScalarDifferentiableOptimizer implements ScalarDifferentiableOptimizer {
+public class MultiStartDifferentiableMultivariateRealOptimizer
+ implements DifferentiableMultivariateRealOptimizer {
/** Serializable version identifier. */
- private static final long serialVersionUID = 6185821146433609962L;
+ private static final long serialVersionUID = -3220364832729994537L;
/** Underlying classical optimizer. */
- private final ScalarDifferentiableOptimizer optimizer;
+ private final DifferentiableMultivariateRealOptimizer optimizer;
/** Maximal number of iterations allowed. */
private int maxIterations;
@@ -62,7 +66,7 @@
private RandomVectorGenerator generator;
/** Found optima. */
- private ScalarPointValuePair[] optima;
+ private RealPointValuePair[] optima;
/**
* Create a multi-start optimizer from a single-start optimizer
@@ -72,9 +76,9 @@
* equal to 1
* @param generator random vector generator to use for restarts
*/
- public MultiStartScalarDifferentiableOptimizer(final ScalarDifferentiableOptimizer optimizer,
- final int starts,
- final RandomVectorGenerator generator) {
+ public MultiStartDifferentiableMultivariateRealOptimizer(final DifferentiableMultivariateRealOptimizer optimizer,
+ final int starts,
+ final RandomVectorGenerator generator) {
this.optimizer = optimizer;
this.maxIterations = Integer.MAX_VALUE;
this.totalIterations = 0;
@@ -86,13 +90,13 @@
}
/** Get all the optima found during the last call to {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}.
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}.
* <p>The optimizer stores all the optima found during a set of
- * restarts. The {@link #optimize(ScalarObjectiveFunction, GoalType,
+ * restarts. The {@link #optimize(MultivariateRealFunction, GoalType,
* double[]) optimize} method returns the best point only. This
* method returns all the points found at the end of each starts,
* including the best one already returned by the {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
* method.
* </p>
* <p>
@@ -102,20 +106,20 @@
* objective value (i.e in ascending order if minimizing and in
* descending order if maximizing), followed by and null elements
* corresponding to the runs that did not converge. This means all
- * elements will be null if the {@link #optimize(ScalarObjectiveFunction,
+ * elements will be null if the {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} method did throw a {@link
* ConvergenceException ConvergenceException}). This also means that
* if the first element is non null, it is the best point found across
* all starts.</p>
* @return array containing the optima
- * @exception IllegalStateException if {@link #optimize(ScalarObjectiveFunction,
+ * @exception IllegalStateException if {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} has not been called
*/
- public ScalarPointValuePair[] getOptima() throws IllegalStateException {
+ public RealPointValuePair[] getOptima() throws IllegalStateException {
if (optima == null) {
throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
}
- return (ScalarPointValuePair[]) optima.clone();
+ return (RealPointValuePair[]) optima.clone();
}
/** {@inheritDoc} */
@@ -144,22 +148,22 @@
}
/** {@inheritDoc} */
- public void setConvergenceChecker(ScalarConvergenceChecker checker) {
+ public void setConvergenceChecker(RealConvergenceChecker checker) {
optimizer.setConvergenceChecker(checker);
}
/** {@inheritDoc} */
- public ScalarConvergenceChecker getConvergenceChecker() {
+ public RealConvergenceChecker getConvergenceChecker() {
return optimizer.getConvergenceChecker();
}
/** {@inheritDoc} */
- public ScalarPointValuePair optimize(final ScalarDifferentiableObjectiveFunction f,
+ public RealPointValuePair optimize(final DifferentiableMultivariateRealFunction f,
final GoalType goalType,
double[] startPoint)
- throws ObjectiveException, OptimizationException {
+ throws FunctionEvaluationException, OptimizationException {
- optima = new ScalarPointValuePair[starts];
+ optima = new RealPointValuePair[starts];
totalIterations = 0;
totalEvaluations = 0;
totalGradientEvaluations = 0;
@@ -171,9 +175,9 @@
optimizer.setMaxIterations(maxIterations - totalIterations);
optima[i] = optimizer.optimize(f, goalType,
(i == 0) ? startPoint : generator.nextVector());
- } catch (ObjectiveException obe) {
+ } catch (FunctionEvaluationException fee) {
optima[i] = null;
- } catch (OptimizationException ope) {
+ } catch (OptimizationException oe) {
optima[i] = null;
}
@@ -184,8 +188,8 @@
}
// sort the optima from best to worst, followed by null elements
- Arrays.sort(optima, new Comparator<ScalarPointValuePair>() {
- public int compare(final ScalarPointValuePair o1, final ScalarPointValuePair o2) {
+ Arrays.sort(optima, new Comparator<RealPointValuePair>() {
+ public int compare(final RealPointValuePair o1, final RealPointValuePair o2) {
if (o1 == null) {
return (o2 == null) ? 0 : +1;
} else if (o2 == null) {
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartVectorialDifferentiableOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartVectorialDifferentiableOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartVectorialDifferentiableOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java Tue Mar 24 22:09:34 2009
@@ -21,11 +21,14 @@
import java.util.Comparator;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.random.RandomVectorGenerator;
/**
- * Special implementation of the {@link VectorialDifferentiableOptimizer} interface adding
+ * Special implementation of the {@link DifferentiableMultivariateVectorialOptimizer} interface adding
* multi-start features to an existing optimizer.
* <p>
* This class wraps a classical optimizer to use it several times in
@@ -35,13 +38,14 @@
* @version $Revision$ $Date$
* @since 2.0
*/
-public class MultiStartVectorialDifferentiableOptimizer implements VectorialDifferentiableOptimizer {
+public class MultiStartDifferentiableMultivariateVectorialOptimizer
+ implements DifferentiableMultivariateVectorialOptimizer {
/** Serializable version identifier. */
- private static final long serialVersionUID = -9109278856437190136L;
+ private static final long serialVersionUID = 9206382258980561530L;
/** Underlying classical optimizer. */
- private final VectorialDifferentiableOptimizer optimizer;
+ private final DifferentiableMultivariateVectorialOptimizer optimizer;
/** Maximal number of iterations allowed. */
private int maxIterations;
@@ -72,9 +76,10 @@
* equal to 1
* @param generator random vector generator to use for restarts
*/
- public MultiStartVectorialDifferentiableOptimizer(final VectorialDifferentiableOptimizer optimizer,
- final int starts,
- final RandomVectorGenerator generator) {
+ public MultiStartDifferentiableMultivariateVectorialOptimizer(
+ final DifferentiableMultivariateVectorialOptimizer optimizer,
+ final int starts,
+ final RandomVectorGenerator generator) {
this.optimizer = optimizer;
this.maxIterations = Integer.MAX_VALUE;
this.totalIterations = 0;
@@ -86,13 +91,13 @@
}
/** Get all the optima found during the last call to {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}.
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}.
* <p>The optimizer stores all the optima found during a set of
- * restarts. The {@link #optimize(ScalarObjectiveFunction, GoalType,
+ * restarts. The {@link #optimize(MultivariateRealFunction, GoalType,
* double[]) optimize} method returns the best point only. This
* method returns all the points found at the end of each starts,
* including the best one already returned by the {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
* method.
* </p>
* <p>
@@ -102,13 +107,13 @@
* objective value (i.e in ascending order if minimizing and in
* descending order if maximizing), followed by and null elements
* corresponding to the runs that did not converge. This means all
- * elements will be null if the {@link #optimize(ScalarObjectiveFunction,
+ * elements will be null if the {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} method did throw a {@link
* ConvergenceException ConvergenceException}). This also means that
* if the first element is non null, it is the best point found across
* all starts.</p>
* @return array containing the optima
- * @exception IllegalStateException if {@link #optimize(ScalarObjectiveFunction,
+ * @exception IllegalStateException if {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} has not been called
*/
public VectorialPointValuePair[] getOptima() throws IllegalStateException {
@@ -154,10 +159,10 @@
}
/** {@inheritDoc} */
- public VectorialPointValuePair optimize(final VectorialDifferentiableObjectiveFunction f,
+ public VectorialPointValuePair optimize(final DifferentiableMultivariateVectorialFunction f,
final double[] target, final double[] weights,
final double[] startPoint)
- throws ObjectiveException, OptimizationException, IllegalArgumentException {
+ throws FunctionEvaluationException, OptimizationException, IllegalArgumentException {
optima = new VectorialPointValuePair[starts];
totalIterations = 0;
@@ -171,9 +176,9 @@
optimizer.setMaxIterations(maxIterations - totalIterations);
optima[i] = optimizer.optimize(f, target, weights,
(i == 0) ? startPoint : generator.nextVector());
- } catch (ObjectiveException obe) {
+ } catch (FunctionEvaluationException fee) {
optima[i] = null;
- } catch (OptimizationException ope) {
+ } catch (OptimizationException oe) {
optima[i] = null;
}
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizer.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartScalarOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -21,11 +21,13 @@
import java.util.Comparator;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
import org.apache.commons.math.random.RandomVectorGenerator;
/**
- * Special implementation of the {@link ScalarOptimizer} interface adding
+ * Special implementation of the {@link MultivariateRealOptimizer} interface adding
* multi-start features to an existing optimizer.
* <p>
* This class wraps a classical optimizer to use it several times in
@@ -35,13 +37,13 @@
* @version $Revision$ $Date$
* @since 2.0
*/
-public class MultiStartScalarOptimizer implements ScalarOptimizer {
+public class MultiStartMultivariateRealOptimizer implements MultivariateRealOptimizer {
/** Serializable version identifier. */
- private static final long serialVersionUID = -7333253288301713047L;
+ private static final long serialVersionUID = 5983375963110961019L;
/** Underlying classical optimizer. */
- private final ScalarOptimizer optimizer;
+ private final MultivariateRealOptimizer optimizer;
/** Maximal number of iterations allowed. */
private int maxIterations;
@@ -59,7 +61,7 @@
private RandomVectorGenerator generator;
/** Found optima. */
- private ScalarPointValuePair[] optima;
+ private RealPointValuePair[] optima;
/**
* Create a multi-start optimizer from a single-start optimizer
@@ -69,8 +71,9 @@
* equal to 1
* @param generator random vector generator to use for restarts
*/
- public MultiStartScalarOptimizer(final ScalarOptimizer optimizer, final int starts,
- final RandomVectorGenerator generator) {
+ public MultiStartMultivariateRealOptimizer(final MultivariateRealOptimizer optimizer,
+ final int starts,
+ final RandomVectorGenerator generator) {
this.optimizer = optimizer;
this.maxIterations = Integer.MAX_VALUE;
this.totalIterations = 0;
@@ -81,13 +84,13 @@
}
/** Get all the optima found during the last call to {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}.
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}.
* <p>The optimizer stores all the optima found during a set of
- * restarts. The {@link #optimize(ScalarObjectiveFunction, GoalType,
+ * restarts. The {@link #optimize(MultivariateRealFunction, GoalType,
* double[]) optimize} method returns the best point only. This
* method returns all the points found at the end of each starts,
* including the best one already returned by the {@link
- * #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
* method.
* </p>
* <p>
@@ -97,20 +100,20 @@
* objective value (i.e in ascending order if minimizing and in
* descending order if maximizing), followed by and null elements
* corresponding to the runs that did not converge. This means all
- * elements will be null if the {@link #optimize(ScalarObjectiveFunction,
+ * elements will be null if the {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} method did throw a {@link
* ConvergenceException ConvergenceException}). This also means that
* if the first element is non null, it is the best point found across
* all starts.</p>
* @return array containing the optima
- * @exception IllegalStateException if {@link #optimize(ScalarObjectiveFunction,
+ * @exception IllegalStateException if {@link #optimize(MultivariateRealFunction,
* GoalType, double[]) optimize} has not been called
*/
- public ScalarPointValuePair[] getOptima() throws IllegalStateException {
+ public RealPointValuePair[] getOptima() throws IllegalStateException {
if (optima == null) {
throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
}
- return (ScalarPointValuePair[]) optima.clone();
+ return (RealPointValuePair[]) optima.clone();
}
/** {@inheritDoc} */
@@ -134,22 +137,22 @@
}
/** {@inheritDoc} */
- public void setConvergenceChecker(ScalarConvergenceChecker checker) {
+ public void setConvergenceChecker(RealConvergenceChecker checker) {
optimizer.setConvergenceChecker(checker);
}
/** {@inheritDoc} */
- public ScalarConvergenceChecker getConvergenceChecker() {
+ public RealConvergenceChecker getConvergenceChecker() {
return optimizer.getConvergenceChecker();
}
/** {@inheritDoc} */
- public ScalarPointValuePair optimize(final ScalarObjectiveFunction f,
+ public RealPointValuePair optimize(final MultivariateRealFunction f,
final GoalType goalType,
double[] startPoint)
- throws ObjectiveException, OptimizationException {
+ throws FunctionEvaluationException, OptimizationException {
- optima = new ScalarPointValuePair[starts];
+ optima = new RealPointValuePair[starts];
totalIterations = 0;
totalEvaluations = 0;
@@ -160,9 +163,9 @@
optimizer.setMaxIterations(maxIterations - totalIterations);
optima[i] = optimizer.optimize(f, goalType,
(i == 0) ? startPoint : generator.nextVector());
- } catch (ObjectiveException obe) {
+ } catch (FunctionEvaluationException fee) {
optima[i] = null;
- } catch (OptimizationException ope) {
+ } catch (OptimizationException oe) {
optima[i] = null;
}
@@ -172,8 +175,8 @@
}
// sort the optima from best to worst, followed by null elements
- Arrays.sort(optima, new Comparator<ScalarPointValuePair>() {
- public int compare(final ScalarPointValuePair o1, final ScalarPointValuePair o2) {
+ Arrays.sort(optima, new Comparator<RealPointValuePair>() {
+ public int compare(final RealPointValuePair o1, final RealPointValuePair o2) {
if (o1 == null) {
return (o2 == null) ? 0 : +1;
} else if (o2 == null) {
Added: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java?rev=758049&view=auto
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java (added)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.optimization;
+
+import java.util.Arrays;
+
+import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.random.RandomGenerator;
+
+/**
+ * Special implementation of the {@link UnivariateRealOptimizer} interface adding
+ * multi-start features to an existing optimizer.
+ * <p>
+ * This class wraps a classical optimizer to use it several times in
+ * turn with different starting points in order to avoid being trapped
+ * into a local extremum when looking for a global one.
+ * </p>
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public class MultiStartUnivariateRealOptimizer implements UnivariateRealOptimizer {
+
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = 5983375963110961019L;
+
+ /** Underlying classical optimizer. */
+ private final UnivariateRealOptimizer optimizer;
+
+ /** Maximal number of iterations allowed. */
+ private int maxIterations;
+
+ /** Number of iterations already performed for all starts. */
+ private int totalIterations;
+
+ /** Number of starts to go. */
+ private int starts;
+
+ /** Random generator for multi-start. */
+ private RandomGenerator generator;
+
+ /** Found optima. */
+ private double[] optima;
+
+ /**
+ * Create a multi-start optimizer from a single-start optimizer
+ * @param optimizer single-start optimizer to wrap
+ * @param starts number of starts to perform (including the
+ * first one), multi-start is disabled if value is less than or
+ * equal to 1
+ * @param generator random generator to use for restarts
+ */
+ public MultiStartUnivariateRealOptimizer(final UnivariateRealOptimizer optimizer,
+ final int starts,
+ final RandomGenerator generator) {
+ this.optimizer = optimizer;
+ this.maxIterations = Integer.MAX_VALUE;
+ this.totalIterations = 0;
+ this.starts = starts;
+ this.generator = generator;
+ this.optima = null;
+ }
+
+ /** {@inheritDoc} */
+ public double getFunctionValue() {
+ return optimizer.getFunctionValue();
+ }
+
+ /** {@inheritDoc} */
+ public double getResult() {
+ return optimizer.getResult();
+ }
+
+ /** {@inheritDoc} */
+ public double getAbsoluteAccuracy() {
+ return optimizer.getAbsoluteAccuracy();
+ }
+
+ /** {@inheritDoc} */
+ public int getIterationCount() {
+ return totalIterations;
+ }
+
+ /** {@inheritDoc} */
+ public int getMaximalIterationCount() {
+ return maxIterations;
+ }
+
+ /** {@inheritDoc} */
+ public double getRelativeAccuracy() {
+ return optimizer.getRelativeAccuracy();
+ }
+
+ /** {@inheritDoc} */
+ public void resetAbsoluteAccuracy() {
+ optimizer.resetAbsoluteAccuracy();
+ }
+
+ /** {@inheritDoc} */
+ public void resetMaximalIterationCount() {
+ optimizer.resetMaximalIterationCount();
+ }
+
+ /** {@inheritDoc} */
+ public void resetRelativeAccuracy() {
+ optimizer.resetRelativeAccuracy();
+ }
+
+ /** {@inheritDoc} */
+ public void setAbsoluteAccuracy(double accuracy) {
+ optimizer.setAbsoluteAccuracy(accuracy);
+ }
+
+ /** {@inheritDoc} */
+ public void setMaximalIterationCount(int count) {
+ this.maxIterations = count;
+ }
+
+ /** {@inheritDoc} */
+ public void setRelativeAccuracy(double accuracy) {
+ optimizer.setRelativeAccuracy(accuracy);
+ }
+
+ /** Get all the optima found during the last call to {@link
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}.
+ * <p>The optimizer stores all the optima found during a set of
+ * restarts. The {@link #optimize(MultivariateRealFunction, GoalType,
+ * double[]) optimize} method returns the best point only. This
+ * method returns all the points found at the end of each starts,
+ * including the best one already returned by the {@link
+ * #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
+ * method.
+ * </p>
+ * <p>
+ * The returned array as one element for each start as specified
+ * in the constructor. It is ordered with the results from the
+ * runs that did converge first, sorted from best to worst
+ * objective value (i.e in ascending order if minimizing and in
+ * descending order if maximizing), followed by and null elements
+ * corresponding to the runs that did not converge. This means all
+ * elements will be null if the {@link #optimize(MultivariateRealFunction,
+ * GoalType, double[]) optimize} method did throw a {@link
+ * ConvergenceException ConvergenceException}). This also means that
+ * if the first element is non null, it is the best point found across
+ * all starts.</p>
+ * @return array containing the optima
+ * @exception IllegalStateException if {@link #optimize(MultivariateRealFunction,
+ * GoalType, double[]) optimize} has not been called
+ */
+ public double[] getOptima() throws IllegalStateException {
+ if (optima == null) {
+ throw MathRuntimeException.createIllegalStateException("no optimum computed yet");
+ }
+ return optima.clone();
+ }
+
+ /** {@inheritDoc} */
+ public double optimize(final UnivariateRealFunction f, final GoalType goalType,
+ final double min, final double max)
+ throws ConvergenceException,
+ FunctionEvaluationException {
+ return optimize(f, goalType, min, max, min + generator.nextDouble() * (max - min));
+ }
+
+ /** {@inheritDoc} */
+ public double optimize(final UnivariateRealFunction f, final GoalType goalType,
+ final double min, final double max, final double startValue)
+ throws ConvergenceException, FunctionEvaluationException {
+
+ optima = new double[starts];
+ totalIterations = 0;
+
+ // multi-start loop
+ for (int i = 0; i < starts; ++i) {
+
+ try {
+ optimizer.setMaximalIterationCount(maxIterations - totalIterations);
+ optima[i] = optimizer.optimize(f, goalType, min, max,
+ (i == 0) ? startValue : generator.nextDouble() * (max - min));
+ } catch (FunctionEvaluationException fee) {
+ optima[i] = Double.NaN;
+ } catch (ConvergenceException ce) {
+ optima[i] = Double.NaN;
+ }
+
+ totalIterations += optimizer.getIterationCount();
+
+ }
+
+ // sort the optima from best to worst, followed by NaN elements
+ int lastNaN = optima.length;
+ for (int i = 0; i < lastNaN; ++i) {
+ if (Double.isNaN(optima[i])) {
+ optima[i] = optima[--lastNaN];
+ optima[lastNaN + 1] = Double.NaN;
+ }
+ }
+ Arrays.sort(optima, 0, lastNaN);
+ if (goalType == GoalType.MAXIMIZE) {
+ for (int i = 0, j = lastNaN - 1; i < j; ++i, --j) {
+ double tmp = optima[i];
+ optima[i] = optima[j];
+ optima[j] = tmp;
+ }
+ }
+
+ if (Double.isNaN(optima[0])) {
+ throw new OptimizationException(
+ "none of the {0} start points lead to convergence",
+ starts);
+ }
+
+ // return the found point given the best objective function value
+ return optima[0];
+
+ }
+
+}
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultivariateRealOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultivariateRealOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultivariateRealOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarOptimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -19,15 +19,20 @@
import java.io.Serializable;
+import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
+
/**
- * This interface represents an optimization algorithm for {@link ScalarObjectiveFunction
+ * This interface represents an optimization algorithm for {@link MultivariateRealFunction
* scalar objective functions}.
- * @see ScalarDifferentiableOptimizer
- * @see VectorialDifferentiableOptimizer
+ * <p>Optimization algorithms find the input point set that either {@link GoalType
+ * maximize or minimize} an objective function.</p>
+ * @see DifferentiableMultivariateRealOptimizer
+ * @see DifferentiableMultivariateVectorialOptimizer
* @version $Revision$ $Date$
* @since 2.0
*/
-public interface ScalarOptimizer extends Serializable {
+public interface MultivariateRealOptimizer extends Serializable {
/** Set the maximal number of iterations of the algorithm.
* @param maxIterations maximal number of function calls
@@ -42,7 +47,7 @@
/** Get the number of iterations realized by the algorithm.
* <p>
* The number of evaluations corresponds to the last call to the
- * {@link #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}
+ * {@link #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
* method. It is 0 if the method has not been called yet.
* </p>
* @return number of iterations
@@ -52,7 +57,7 @@
/** Get the number of evaluations of the objective function.
* <p>
* The number of evaluations corresponds to the last call to the
- * {@link #optimize(ScalarObjectiveFunction, GoalType, double[]) optimize}
+ * {@link #optimize(MultivariateRealFunction, GoalType, double[]) optimize}
* method. It is 0 if the method has not been called yet.
* </p>
* @return number of evaluations of the objective function
@@ -62,12 +67,12 @@
/** Set the convergence checker.
* @param checker object to use to check for convergence
*/
- void setConvergenceChecker(ScalarConvergenceChecker checker);
+ void setConvergenceChecker(RealConvergenceChecker checker);
/** Get the convergence checker.
* @return object used to check for convergence
*/
- ScalarConvergenceChecker getConvergenceChecker();
+ RealConvergenceChecker getConvergenceChecker();
/** Optimizes an objective function.
* @param f objective function
@@ -75,14 +80,14 @@
* or {@link GoalType#MINIMIZE}
* @param startPoint the start point for optimization
* @return the point/value pair giving the optimal value for objective function
- * @exception ObjectiveException if the objective function throws one during
+ * @exception FunctionEvaluationException if the objective function throws one during
* the search
* @exception OptimizationException if the algorithm failed to converge
* @exception IllegalArgumentException if the start point dimension is wrong
*/
- ScalarPointValuePair optimize(ScalarObjectiveFunction f,
+ RealPointValuePair optimize(MultivariateRealFunction f,
GoalType goalType,
double[] startPoint)
- throws ObjectiveException, OptimizationException, IllegalArgumentException;
+ throws FunctionEvaluationException, OptimizationException, IllegalArgumentException;
}
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealConvergenceChecker.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarConvergenceChecker.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealConvergenceChecker.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealConvergenceChecker.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarConvergenceChecker.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarConvergenceChecker.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealConvergenceChecker.java Tue Mar 24 22:09:34 2009
@@ -19,19 +19,24 @@
import java.io.Serializable;
-/** This interface specifies how to check if an {@link ScalarOptimizer optimization
+/** This interface specifies how to check if an {@link MultivariateRealOptimizer optimization
* algorithm} has converged.
*
- * <p>Deciding if convergence has been reached is a problem-dependent
- * issue. The user should provide a class implementing this interface
- * to allow the optimization algorithm to stop its search according to
- * the problem at hand.</p>
+ * <p>Deciding if convergence has been reached is a problem-dependent issue. The
+ * user should provide a class implementing this interface to allow the optimization
+ * algorithm to stop its search according to the problem at hand.</p>
+ * <p>For convenience, two implementations that fit simple needs are already provided:
+ * {@link SimpleScalarValueChecker} and {@link SimpleScalarPointChecker}. The first
+ * one considers convergence is reached when the objective function value does not
+ * change much anymore, it does not use the point set at all. The second one
+ * considers convergence is reached when the input point set does not change
+ * much anymore, it does not use objective function value at all.</p>
*
* @version $Revision$ $Date$
* @since 2.0
*/
-public interface ScalarConvergenceChecker extends Serializable {
+public interface RealConvergenceChecker extends Serializable {
/** Check if the optimization algorithm has converged considering the last points.
* <p>
@@ -47,6 +52,6 @@
* @param current point from current iteration
* @return true if the algorithm is considered to have converged
*/
- boolean converged(int iteration, ScalarPointValuePair previous, ScalarPointValuePair current);
+ boolean converged(int iteration, RealPointValuePair previous, RealPointValuePair current);
}
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealPointValuePair.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarPointValuePair.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealPointValuePair.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealPointValuePair.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarPointValuePair.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ScalarPointValuePair.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/RealPointValuePair.java Tue Mar 24 22:09:34 2009
@@ -19,15 +19,17 @@
import java.io.Serializable;
+import org.apache.commons.math.analysis.MultivariateRealFunction;
+
/**
* This class holds a point and the value of an objective function at this point.
* <p>This is a simple immutable container.</p>
* @see VectorialPointValuePair
- * @see ScalarObjectiveFunction
+ * @see MultivariateRealFunction
* @version $Revision$ $Date$
* @since 2.0
*/
-public class ScalarPointValuePair implements Serializable {
+public class RealPointValuePair implements Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 1003888396256744753L;
@@ -43,7 +45,7 @@
* a copy of the array, not the array passed as argument)
* @param value value of an objective function at the point
*/
- public ScalarPointValuePair(final double[] point, final double value) {
+ public RealPointValuePair(final double[] point, final double value) {
this.point = point.clone();
this.value = value;
}
@@ -55,7 +57,7 @@
* @param copyArray if true, the input array will be copied, otherwise
* it will be referenced
*/
- public ScalarPointValuePair(final double[] point, final double value,
+ public RealPointValuePair(final double[] point, final double value,
final boolean copyArray) {
this.point = copyArray ? point.clone() : point;
this.value = value;
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java?rev=758049&r1=758048&r2=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java Tue Mar 24 22:09:34 2009
@@ -20,7 +20,7 @@
import org.apache.commons.math.util.MathUtils;
/**
- * Simple implementation of the {@link ScalarConvergenceChecker} interface using
+ * Simple implementation of the {@link RealConvergenceChecker} interface using
* only objective function values.
* <p>
* Convergence is considered to have been reached if either the relative
@@ -31,7 +31,7 @@
* @version $Revision$ $Date$
* @since 2.0
*/
-public class SimpleScalarValueChecker implements ScalarConvergenceChecker {
+public class SimpleScalarValueChecker implements RealConvergenceChecker {
/** Serializable version identifier. */
private static final long serialVersionUID = 2490271385513842607L;
@@ -72,8 +72,8 @@
/** {@inheritDoc} */
public boolean converged(final int iteration,
- final ScalarPointValuePair previous,
- final ScalarPointValuePair current) {
+ final RealPointValuePair previous,
+ final RealPointValuePair current) {
final double p = previous.getValue();
final double c = current.getValue();
final double difference = Math.abs(p - c);
Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java (from r757188, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java&r1=757188&r2=758049&rev=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/UnivariateRealOptimizer.java Tue Mar 24 22:09:34 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.optimization.univariate;
+package org.apache.commons.math.optimization;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.ConvergingAlgorithm;
@@ -23,54 +23,60 @@
/**
- * Interface for (univariate real) minimization algorithms.
+ * Interface for (univariate real) optimization algorithms.
*
* @version $Revision$ $Date$
* @since 2.0
*/
-public interface UnivariateRealMinimizer extends ConvergingAlgorithm {
+public interface UnivariateRealOptimizer extends ConvergingAlgorithm {
/**
- * Find a minimum in the given interval.
+ * Find an optimum in the given interval.
* <p>
- * A minimizer may require that the interval brackets a single minimum.
+ * An optimizer may require that the interval brackets a single optimum.
* </p>
- * @param f the function to minimize.
+ * @param f the function to optimize.
+ * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE}
+ * or {@link GoalType#MINIMIZE}
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
- * @return a value where the function is minimum
+ * @return a value where the function is optimum
* @throws ConvergenceException if the maximum iteration count is exceeded
- * or the minimizer detects convergence problems otherwise.
+ * or the optimizer detects convergence problems otherwise.
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* @throws IllegalArgumentException if min > max or the endpoints do not
- * satisfy the requirements specified by the minimizer
+ * satisfy the requirements specified by the optimizer
*/
- double minimize(UnivariateRealFunction f, double min, double max)
+ double optimize(UnivariateRealFunction f, GoalType goalType,
+ double min, double max)
throws ConvergenceException, FunctionEvaluationException;
/**
- * Find a minimum in the given interval, start at startValue.
+ * Find an optimum in the given interval, start at startValue.
* <p>
- * A minimizer may require that the interval brackets a single minimum.
+ * An optimizer may require that the interval brackets a single optimum.
* </p>
- * @param f the function to minimize.
+ * @param f the function to optimize.
+ * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE}
+ * or {@link GoalType#MINIMIZE}
* @param min the lower bound for the interval.
* @param max the upper bound for the interval.
* @param startValue the start value to use
- * @return a value where the function is minimum
+ * @return a value where the function is optimum
* @throws ConvergenceException if the maximum iteration count is exceeded
- * or the minimizer detects convergence problems otherwise.
+ * or the optimizer detects convergence problems otherwise.
* @throws FunctionEvaluationException if an error occurs evaluating the
* function
* @throws IllegalArgumentException if min > max or the arguments do not
- * satisfy the requirements specified by the minimizer
+ * satisfy the requirements specified by the optimizer
*/
- double minimize(UnivariateRealFunction f, double min, double max, double startValue)
+ double optimize(UnivariateRealFunction f, GoalType goalType,
+ double min, double max, double startValue)
throws ConvergenceException, FunctionEvaluationException;
/**
- * Get the result of the last run of the minimizer.
+ * Get the result of the last run of the optimizer.
*
* @return the last result.
* @throws IllegalStateException if there is no result available, either
@@ -79,7 +85,7 @@
double getResult();
/**
- * Get the result of the last run of the minimizer.
+ * Get the result of the last run of the optimizer.
*
* @return the value of the function at the last result.
* @throws IllegalStateException if there is no result available, either
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialConvergenceChecker.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialConvergenceChecker.java?rev=758049&r1=758048&r2=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialConvergenceChecker.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialConvergenceChecker.java Tue Mar 24 22:09:34 2009
@@ -22,10 +22,15 @@
/** This interface specifies how to check if an {@link VectorialOptimizer optimization
* algorithm} has converged.
*
- * <p>Deciding if convergence has been reached is a problem-dependent
- * issue. The user should provide a class implementing this interface
- * to allow the optimization algorithm to stop its search according to
- * the problem at hand.</p>
+ * <p>Deciding if convergence has been reached is a problem-dependent issue. The
+ * user should provide a class implementing this interface to allow the optimization
+ * algorithm to stop its search according to the problem at hand.</p>
+ * <p>For convenience, two implementations that fit simple needs are already provided:
+ * {@link SimpleVectorialValueChecker} and {@link SimpleVectorialPointChecker}. The first
+ * one considers convergence is reached when the objective function value does not
+ * change much anymore, it does not use the point set at all. The second one
+ * considers convergence is reached when the input point set does not change
+ * much anymore, it does not use objective function value at all.</p>
*
* @version $Revision$ $Date$
* @since 2.0
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialPointValuePair.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialPointValuePair.java?rev=758049&r1=758048&r2=758049&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialPointValuePair.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/VectorialPointValuePair.java Tue Mar 24 22:09:34 2009
@@ -19,11 +19,13 @@
import java.io.Serializable;
+import org.apache.commons.math.analysis.MultivariateVectorialFunction;
+
/**
* This class holds a point and the vectorial value of an objective function at this point.
* <p>This is a simple immutable container.</p>
- * @see ScalarPointValuePair
- * @see VectorialObjectiveFunction
+ * @see RealPointValuePair
+ * @see MultivariateVectorialFunction
* @version $Revision$ $Date$
* @since 2.0
*/