MATH-707
Class name change: "MultiStartDifferentiableMultivariateVectorialOptimizer" -> "DifferentiableMultivariateVectorMultiStartOptimizer" "DifferentiableMultivariateVectorialOptimizer" -> "DifferentiableMultivariateVectorOptimizer" "BaseMultiStartMultivariateVectorialOptimizer" -> "BaseMultivariateVectorMultiStartOptimizer" "BaseMultivariateVectorialOptimizer" -> "BaseMultivariateVectorOptimizer" git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1212361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bb322e8ffb
commit
497d025e1e
|
@ -33,17 +33,17 @@ import org.apache.commons.math.random.RandomVectorGenerator;
|
|||
*
|
||||
* This interface is mainly intended to enforce the internal coherence of
|
||||
* Commons-Math. Users of the API are advised to base their code on
|
||||
* {@link MultiStartDifferentiableMultivariateVectorialOptimizer}.
|
||||
* {@link DifferentiableMultivariateVectorMultiStartOptimizer}.
|
||||
*
|
||||
* @param <FUNC> Type of the objective function to be optimized.
|
||||
*
|
||||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public class BaseMultiStartMultivariateVectorialOptimizer<FUNC extends MultivariateVectorFunction>
|
||||
implements BaseMultivariateVectorialOptimizer<FUNC> {
|
||||
public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends MultivariateVectorFunction>
|
||||
implements BaseMultivariateVectorOptimizer<FUNC> {
|
||||
/** Underlying classical optimizer. */
|
||||
private final BaseMultivariateVectorialOptimizer<FUNC> optimizer;
|
||||
private final BaseMultivariateVectorOptimizer<FUNC> optimizer;
|
||||
/** Maximal number of evaluations allowed. */
|
||||
private int maxEvaluations;
|
||||
/** Number of evaluations already performed for all starts. */
|
||||
|
@ -67,7 +67,7 @@ public class BaseMultiStartMultivariateVectorialOptimizer<FUNC extends Multivari
|
|||
* is {@code null}.
|
||||
* @throws NotStrictlyPositiveException if {@code starts < 1}.
|
||||
*/
|
||||
protected BaseMultiStartMultivariateVectorialOptimizer(final BaseMultivariateVectorialOptimizer<FUNC> optimizer,
|
||||
protected BaseMultivariateVectorMultiStartOptimizer(final BaseMultivariateVectorOptimizer<FUNC> optimizer,
|
||||
final int starts,
|
||||
final RandomVectorGenerator generator) {
|
||||
if (optimizer == null ||
|
|
@ -24,7 +24,7 @@ import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
|||
* Commons-Math. Users of the API are advised to base their code on
|
||||
* the following interfaces:
|
||||
* <ul>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param <FUNC> Type of the objective function to be optimized.
|
||||
|
@ -32,7 +32,7 @@ import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
|||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface BaseMultivariateVectorialOptimizer<FUNC extends MultivariateVectorFunction>
|
||||
public interface BaseMultivariateVectorOptimizer<FUNC extends MultivariateVectorFunction>
|
||||
extends BaseOptimizer<VectorialPointValuePair> {
|
||||
/**
|
||||
* Optimize an objective function.
|
|
@ -24,7 +24,7 @@ package org.apache.commons.math.optimization;
|
|||
* <ul>
|
||||
* <li>{@link org.apache.commons.math.optimization.MultivariateRealOptimizer}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateRealOptimizer}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.univariate.UnivariateRealOptimizer}</li>
|
||||
* </ul>
|
||||
*
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateFunction;
|
|||
* maximize or minimize} an objective function.
|
||||
*
|
||||
* @see MultivariateRealOptimizer
|
||||
* @see DifferentiableMultivariateVectorialOptimizer
|
||||
* @see DifferentiableMultivariateVectorOptimizer
|
||||
*
|
||||
* @version $Id$
|
||||
* @since 2.0
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction
|
|||
import org.apache.commons.math.random.RandomVectorGenerator;
|
||||
|
||||
/**
|
||||
* Special implementation of the {@link DifferentiableMultivariateVectorialOptimizer}
|
||||
* Special implementation of the {@link DifferentiableMultivariateVectorOptimizer}
|
||||
* interface addind multi-start features to an existing optimizer.
|
||||
*
|
||||
* This class wraps a classical optimizer to use it several times in
|
||||
|
@ -31,9 +31,9 @@ import org.apache.commons.math.random.RandomVectorGenerator;
|
|||
* @version $Id$
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MultiStartDifferentiableMultivariateVectorialOptimizer
|
||||
extends BaseMultiStartMultivariateVectorialOptimizer<DifferentiableMultivariateVectorFunction>
|
||||
implements DifferentiableMultivariateVectorialOptimizer {
|
||||
public class DifferentiableMultivariateVectorMultiStartOptimizer
|
||||
extends BaseMultivariateVectorMultiStartOptimizer<DifferentiableMultivariateVectorFunction>
|
||||
implements DifferentiableMultivariateVectorOptimizer {
|
||||
/**
|
||||
* Create a multi-start optimizer from a single-start optimizer.
|
||||
*
|
||||
|
@ -43,8 +43,8 @@ public class MultiStartDifferentiableMultivariateVectorialOptimizer
|
|||
* equal to 1.
|
||||
* @param generator Random vector generator to use for restarts.
|
||||
*/
|
||||
public MultiStartDifferentiableMultivariateVectorialOptimizer(
|
||||
final DifferentiableMultivariateVectorialOptimizer optimizer,
|
||||
public DifferentiableMultivariateVectorMultiStartOptimizer(
|
||||
final DifferentiableMultivariateVectorOptimizer optimizer,
|
||||
final int starts,
|
||||
final RandomVectorGenerator generator) {
|
||||
super(optimizer, starts, generator);
|
|
@ -27,5 +27,5 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction
|
|||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface DifferentiableMultivariateVectorialOptimizer
|
||||
extends BaseMultivariateVectorialOptimizer<DifferentiableMultivariateVectorFunction> {}
|
||||
public interface DifferentiableMultivariateVectorOptimizer
|
||||
extends BaseMultivariateVectorOptimizer<DifferentiableMultivariateVectorFunction> {}
|
|
@ -26,7 +26,7 @@ import org.apache.commons.math.analysis.MultivariateFunction;
|
|||
* maximize or minimize} an objective function.</p>
|
||||
*
|
||||
* @see DifferentiableMultivariateRealOptimizer
|
||||
* @see DifferentiableMultivariateVectorialOptimizer
|
||||
* @see DifferentiableMultivariateVectorOptimizer
|
||||
* @version $Id$
|
||||
* @since 2.0
|
||||
*/
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.commons.math.optimization;
|
||||
|
||||
/** This interface specifies how to check if a {@link
|
||||
* DifferentiableMultivariateVectorialOptimizer optimization algorithm} has converged.
|
||||
* DifferentiableMultivariateVectorOptimizer 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
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.commons.math.exception.TooManyEvaluationsException;
|
|||
import org.apache.commons.math.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math.exception.NullArgumentException;
|
||||
import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
||||
import org.apache.commons.math.optimization.BaseMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.BaseMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
||||
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
||||
|
@ -39,7 +39,7 @@ import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
|||
* @since 3.0
|
||||
*/
|
||||
public abstract class BaseAbstractVectorialOptimizer<FUNC extends MultivariateVectorFunction>
|
||||
implements BaseMultivariateVectorialOptimizer<FUNC> {
|
||||
implements BaseMultivariateVectorOptimizer<FUNC> {
|
||||
/** Evaluations counter. */
|
||||
protected final Incrementor evaluations = new Incrementor();
|
||||
/** Convergence checker. */
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction;
|
||||
import org.apache.commons.math.analysis.ParametricUnivariateFunction;
|
||||
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
||||
|
||||
/** Fitter for parametric univariate real functions y = f(x).
|
||||
|
@ -41,14 +41,14 @@ import org.apache.commons.math.optimization.VectorialPointValuePair;
|
|||
*/
|
||||
public class CurveFitter {
|
||||
/** Optimizer to use for the fitting. */
|
||||
private final DifferentiableMultivariateVectorialOptimizer optimizer;
|
||||
private final DifferentiableMultivariateVectorOptimizer optimizer;
|
||||
/** Observed points. */
|
||||
private final List<WeightedObservedPoint> observations;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param optimizer optimizer to use for the fitting
|
||||
*/
|
||||
public CurveFitter(final DifferentiableMultivariateVectorialOptimizer optimizer) {
|
||||
public CurveFitter(final DifferentiableMultivariateVectorOptimizer optimizer) {
|
||||
this.optimizer = optimizer;
|
||||
observations = new ArrayList<WeightedObservedPoint>();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.math.exception.OutOfRangeException;
|
|||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.optimization.fitting.CurveFitter;
|
||||
import org.apache.commons.math.optimization.fitting.WeightedObservedPoint;
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class GaussianFitter extends CurveFitter {
|
|||
*
|
||||
* @param optimizer Optimizer to use for the fitting.
|
||||
*/
|
||||
public GaussianFitter(DifferentiableMultivariateVectorialOptimizer optimizer) {
|
||||
public GaussianFitter(DifferentiableMultivariateVectorOptimizer optimizer) {
|
||||
super(optimizer);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package org.apache.commons.math.optimization.fitting;
|
||||
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.analysis.function.HarmonicOscillator;
|
||||
import org.apache.commons.math.exception.ZeroException;
|
||||
import org.apache.commons.math.exception.NumberIsTooSmallException;
|
||||
|
@ -41,7 +41,7 @@ public class HarmonicFitter extends CurveFitter {
|
|||
* Simple constructor.
|
||||
* @param optimizer Optimizer to use for the fitting.
|
||||
*/
|
||||
public HarmonicFitter(final DifferentiableMultivariateVectorialOptimizer optimizer) {
|
||||
public HarmonicFitter(final DifferentiableMultivariateVectorOptimizer optimizer) {
|
||||
super(optimizer);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.commons.math.optimization.fitting;
|
||||
|
||||
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
|
||||
/** This class implements a curve fitting specialized for polynomials.
|
||||
* <p>Polynomial fitting is a very simple case of curve fitting. The
|
||||
|
@ -40,7 +40,7 @@ public class PolynomialFitter extends CurveFitter {
|
|||
* @param degree Maximal degree of the polynomial.
|
||||
* @param optimizer Optimizer to use for the fitting.
|
||||
*/
|
||||
public PolynomialFitter(int degree, final DifferentiableMultivariateVectorialOptimizer optimizer) {
|
||||
public PolynomialFitter(int degree, final DifferentiableMultivariateVectorOptimizer optimizer) {
|
||||
super(optimizer);
|
||||
this.degree = degree;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.commons.math.linear.LUDecomposition;
|
|||
import org.apache.commons.math.linear.DecompositionSolver;
|
||||
import org.apache.commons.math.linear.MatrixUtils;
|
||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
||||
import org.apache.commons.math.optimization.direct.BaseAbstractVectorialOptimizer;
|
||||
import org.apache.commons.math.util.FastMath;
|
||||
|
@ -50,7 +50,7 @@ import org.apache.commons.math.util.FastMath;
|
|||
*/
|
||||
public abstract class AbstractLeastSquaresOptimizer
|
||||
extends BaseAbstractVectorialOptimizer<DifferentiableMultivariateVectorFunction>
|
||||
implements DifferentiableMultivariateVectorialOptimizer {
|
||||
implements DifferentiableMultivariateVectorOptimizer {
|
||||
/** Singularity threshold (cf. {@link #getCovariances(double)}). */
|
||||
private static final double DEFAULT_SINGULARITY_THRESHOLD = 1e-14;
|
||||
/**
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
* DifferentiableMultivariateRealOptimizer} for {@link
|
||||
* org.apache.commons.math.analysis.DifferentiableMultivariateFunction
|
||||
* differentiable multivariate real functions}</li>
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer
|
||||
* DifferentiableMultivariateVectorialOptimizer} for {@link
|
||||
* <li>{@link org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer
|
||||
* DifferentiableMultivariateVectorOptimizer} for {@link
|
||||
* org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction
|
||||
* differentiable multivariate vectorial functions}</li>
|
||||
* </ul>
|
||||
|
|
|
@ -93,21 +93,21 @@ import org.junit.Test;
|
|||
* @author Jorge J. More (original fortran minpack tests)
|
||||
* @author Luc Maisonobe (non-minpack tests and minpack tests Java translation)
|
||||
*/
|
||||
public class MultiStartDifferentiableMultivariateVectorialOptimizerTest {
|
||||
public class DifferentiableMultivariateVectorMultiStartOptimizerTest {
|
||||
|
||||
@Test
|
||||
public void testTrivial() {
|
||||
LinearProblem problem =
|
||||
new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
|
||||
DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
|
||||
DifferentiableMultivariateVectorOptimizer underlyingOptimizer =
|
||||
new GaussNewtonOptimizer(true,
|
||||
new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||
JDKRandomGenerator g = new JDKRandomGenerator();
|
||||
g.setSeed(16069223052l);
|
||||
RandomVectorGenerator generator =
|
||||
new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
|
||||
MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
|
||||
new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
|
||||
DifferentiableMultivariateVectorMultiStartOptimizer optimizer =
|
||||
new DifferentiableMultivariateVectorMultiStartOptimizer(underlyingOptimizer,
|
||||
10, generator);
|
||||
|
||||
// no optima before first optimization attempt
|
||||
|
@ -134,15 +134,15 @@ public class MultiStartDifferentiableMultivariateVectorialOptimizerTest {
|
|||
|
||||
@Test(expected=TestException.class)
|
||||
public void testNoOptimum() {
|
||||
DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
|
||||
DifferentiableMultivariateVectorOptimizer underlyingOptimizer =
|
||||
new GaussNewtonOptimizer(true,
|
||||
new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||
JDKRandomGenerator g = new JDKRandomGenerator();
|
||||
g.setSeed(12373523445l);
|
||||
RandomVectorGenerator generator =
|
||||
new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
|
||||
MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
|
||||
new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
|
||||
DifferentiableMultivariateVectorMultiStartOptimizer optimizer =
|
||||
new DifferentiableMultivariateVectorMultiStartOptimizer(underlyingOptimizer,
|
||||
10, generator);
|
||||
optimizer.optimize(100, new DifferentiableMultivariateVectorFunction() {
|
||||
public MultivariateMatrixFunction jacobian() {
|
|
@ -21,7 +21,7 @@ import java.util.Random;
|
|||
|
||||
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
|
||||
import org.apache.commons.math.exception.ConvergenceException;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
|
||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||
import org.apache.commons.math.optimization.general.GaussNewtonOptimizer;
|
||||
import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer;
|
||||
import org.apache.commons.math.util.FastMath;
|
||||
|
@ -89,12 +89,12 @@ public class PolynomialFitterTest {
|
|||
@Test
|
||||
public void testRedundantUnsolvable() {
|
||||
// Gauss-Newton should not be able to solve redundant information
|
||||
DifferentiableMultivariateVectorialOptimizer optimizer =
|
||||
DifferentiableMultivariateVectorOptimizer optimizer =
|
||||
new GaussNewtonOptimizer(true);
|
||||
checkUnsolvableProblem(optimizer, false);
|
||||
}
|
||||
|
||||
private void checkUnsolvableProblem(DifferentiableMultivariateVectorialOptimizer optimizer,
|
||||
private void checkUnsolvableProblem(DifferentiableMultivariateVectorOptimizer optimizer,
|
||||
boolean solvable) {
|
||||
Random randomizer = new Random(1248788532l);
|
||||
for (int degree = 0; degree < 10; ++degree) {
|
||||
|
|
Loading…
Reference in New Issue