MATH-707
Renamed "VectorialPointValuePair" to "PointVectorValuePair" and made it a subclass of "Pair<double[], double[]>". git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1243310 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3390941cd1
commit
7921608dec
|
@ -53,7 +53,7 @@ public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends Multivariate
|
||||||
/** Random generator for multi-start. */
|
/** Random generator for multi-start. */
|
||||||
private RandomVectorGenerator generator;
|
private RandomVectorGenerator generator;
|
||||||
/** Found optima. */
|
/** Found optima. */
|
||||||
private VectorialPointValuePair[] optima;
|
private PointVectorValuePair[] optima;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a multi-start optimizer from a single-start optimizer.
|
* Create a multi-start optimizer from a single-start optimizer.
|
||||||
|
@ -110,7 +110,7 @@ public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends Multivariate
|
||||||
* #optimize(int,MultivariateVectorFunction,double[],double[],double[]) optimize} has not been
|
* #optimize(int,MultivariateVectorFunction,double[],double[],double[]) optimize} has not been
|
||||||
* called.
|
* called.
|
||||||
*/
|
*/
|
||||||
public VectorialPointValuePair[] getOptima() {
|
public PointVectorValuePair[] getOptima() {
|
||||||
if (optima == null) {
|
if (optima == null) {
|
||||||
throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET);
|
throw new MathIllegalStateException(LocalizedFormats.NO_OPTIMUM_COMPUTED_YET);
|
||||||
}
|
}
|
||||||
|
@ -128,19 +128,19 @@ public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends Multivariate
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public ConvergenceChecker<VectorialPointValuePair> getConvergenceChecker() {
|
public ConvergenceChecker<PointVectorValuePair> getConvergenceChecker() {
|
||||||
return optimizer.getConvergenceChecker();
|
return optimizer.getConvergenceChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public VectorialPointValuePair optimize(int maxEval, final FUNC f,
|
public PointVectorValuePair optimize(int maxEval, final FUNC f,
|
||||||
double[] target, double[] weights,
|
double[] target, double[] weights,
|
||||||
double[] startPoint) {
|
double[] startPoint) {
|
||||||
maxEvaluations = maxEval;
|
maxEvaluations = maxEval;
|
||||||
RuntimeException lastException = null;
|
RuntimeException lastException = null;
|
||||||
optima = new VectorialPointValuePair[starts];
|
optima = new PointVectorValuePair[starts];
|
||||||
totalEvaluations = 0;
|
totalEvaluations = 0;
|
||||||
|
|
||||||
// Multi-start loop.
|
// Multi-start loop.
|
||||||
|
@ -179,9 +179,9 @@ public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends Multivariate
|
||||||
*/
|
*/
|
||||||
private void sortPairs(final double[] target,
|
private void sortPairs(final double[] target,
|
||||||
final double[] weights) {
|
final double[] weights) {
|
||||||
Arrays.sort(optima, new Comparator<VectorialPointValuePair>() {
|
Arrays.sort(optima, new Comparator<PointVectorValuePair>() {
|
||||||
public int compare(final VectorialPointValuePair o1,
|
public int compare(final PointVectorValuePair o1,
|
||||||
final VectorialPointValuePair o2) {
|
final PointVectorValuePair o2) {
|
||||||
if (o1 == null) {
|
if (o1 == null) {
|
||||||
return (o2 == null) ? 0 : 1;
|
return (o2 == null) ? 0 : 1;
|
||||||
} else if (o2 == null) {
|
} else if (o2 == null) {
|
||||||
|
@ -189,7 +189,7 @@ public class BaseMultivariateVectorMultiStartOptimizer<FUNC extends Multivariate
|
||||||
}
|
}
|
||||||
return Double.compare(weightedResidual(o1), weightedResidual(o2));
|
return Double.compare(weightedResidual(o1), weightedResidual(o2));
|
||||||
}
|
}
|
||||||
private double weightedResidual(final VectorialPointValuePair pv) {
|
private double weightedResidual(final PointVectorValuePair pv) {
|
||||||
final double[] value = pv.getValueRef();
|
final double[] value = pv.getValueRef();
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (int i = 0; i < value.length; ++i) {
|
for (int i = 0; i < value.length; ++i) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public interface BaseMultivariateVectorOptimizer<FUNC extends MultivariateVectorFunction>
|
public interface BaseMultivariateVectorOptimizer<FUNC extends MultivariateVectorFunction>
|
||||||
extends BaseOptimizer<VectorialPointValuePair> {
|
extends BaseOptimizer<PointVectorValuePair> {
|
||||||
/**
|
/**
|
||||||
* Optimize an objective function.
|
* Optimize an objective function.
|
||||||
* Optimization is considered to be a weighted least-squares minimization.
|
* Optimization is considered to be a weighted least-squares minimization.
|
||||||
|
@ -54,6 +54,6 @@ public interface BaseMultivariateVectorOptimizer<FUNC extends MultivariateVector
|
||||||
* @throws org.apache.commons.math.exception.NullArgumentException if
|
* @throws org.apache.commons.math.exception.NullArgumentException if
|
||||||
* any argument is {@code null}.
|
* any argument is {@code null}.
|
||||||
*/
|
*/
|
||||||
VectorialPointValuePair optimize(int maxEval, FUNC f, double[] target,
|
PointVectorValuePair optimize(int maxEval, FUNC f, double[] target,
|
||||||
double[] weight, double[] startPoint);
|
double[] weight, double[] startPoint);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.commons.math.util.Pair;
|
||||||
* This class holds a point and the value of an objective function at
|
* This class holds a point and the value of an objective function at
|
||||||
* that point.
|
* that point.
|
||||||
*
|
*
|
||||||
|
* @see PointVectorValuePair
|
||||||
* @see org.apache.commons.math.analysis.MultivariateFunction
|
* @see org.apache.commons.math.analysis.MultivariateFunction
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
@ -31,8 +32,8 @@ public class PointValuePair extends Pair<double[], Double> {
|
||||||
/**
|
/**
|
||||||
* Builds a point/objective function value pair.
|
* Builds a point/objective function value pair.
|
||||||
*
|
*
|
||||||
* @param point Point coordinates (this instance will store
|
* @param point Point coordinates. This instance will store
|
||||||
* a copy of the array, not the array passed as argument).
|
* a copy of the array, not the array passed as argument.
|
||||||
* @param value Value of the objective function at the point.
|
* @param value Value of the objective function at the point.
|
||||||
*/
|
*/
|
||||||
public PointValuePair(final double[] point,
|
public PointValuePair(final double[] point,
|
||||||
|
@ -63,7 +64,8 @@ public class PointValuePair extends Pair<double[], Double> {
|
||||||
* @return a copy of the stored point.
|
* @return a copy of the stored point.
|
||||||
*/
|
*/
|
||||||
public double[] getPoint() {
|
public double[] getPoint() {
|
||||||
return getKey().clone();
|
final double[] p = getKey();
|
||||||
|
return p == null ? null : p.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* 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 org.apache.commons.math.util.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds a point and the vectorial value of an objective function at
|
||||||
|
* that point.
|
||||||
|
*
|
||||||
|
* @see PointValuePair
|
||||||
|
* @see org.apache.commons.math.analysis.MultivariateVectorFunction
|
||||||
|
* @version $Id$
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public class PointVectorValuePair extends Pair<double[], double[]> {
|
||||||
|
/**
|
||||||
|
* Builds a point/objective function value pair.
|
||||||
|
*
|
||||||
|
* @param point Point coordinates. This instance will store
|
||||||
|
* a copy of the array, not the array passed as argument.
|
||||||
|
* @param value Value of the objective function at the point.
|
||||||
|
*/
|
||||||
|
public PointVectorValuePair(final double[] point,
|
||||||
|
final double[] value) {
|
||||||
|
this(point, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a point/objective function value pair.
|
||||||
|
*
|
||||||
|
* @param point Point coordinates.
|
||||||
|
* @param value Value of the objective function at the point.
|
||||||
|
* @param copyArray if {@code true}, the input arrays will be copied,
|
||||||
|
* otherwise they will be referenced.
|
||||||
|
*/
|
||||||
|
public PointVectorValuePair(final double[] point,
|
||||||
|
final double[] value,
|
||||||
|
final boolean copyArray) {
|
||||||
|
super(copyArray ?
|
||||||
|
((point == null) ? null :
|
||||||
|
point.clone()) :
|
||||||
|
point,
|
||||||
|
copyArray ?
|
||||||
|
((value == null) ? null :
|
||||||
|
value.clone()) :
|
||||||
|
value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the point.
|
||||||
|
*
|
||||||
|
* @return a copy of the stored point.
|
||||||
|
*/
|
||||||
|
public double[] getPoint() {
|
||||||
|
final double[] p = getKey();
|
||||||
|
return p == null ? null : p.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a reference to the point.
|
||||||
|
*
|
||||||
|
* @return a reference to the internal array storing the point.
|
||||||
|
*/
|
||||||
|
public double[] getPointRef() {
|
||||||
|
return getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the objective function.
|
||||||
|
*
|
||||||
|
* @return a copy of the stored value of the objective function.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double[] getValue() {
|
||||||
|
final double[] v = super.getValue();
|
||||||
|
return v == null ? null : v.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a reference to the value of the objective function.
|
||||||
|
*
|
||||||
|
* @return a reference to the internal array storing the value of
|
||||||
|
* the objective function.
|
||||||
|
*/
|
||||||
|
public double[] getValueRef() {
|
||||||
|
return super.getValue();
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ package org.apache.commons.math.optimization;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class SimpleVectorialPointChecker
|
public class SimpleVectorialPointChecker
|
||||||
extends AbstractConvergenceChecker<VectorialPointValuePair> {
|
extends AbstractConvergenceChecker<PointVectorValuePair> {
|
||||||
/**
|
/**
|
||||||
* Build an instance with default threshold.
|
* Build an instance with default threshold.
|
||||||
*/
|
*/
|
||||||
|
@ -69,8 +69,8 @@ public class SimpleVectorialPointChecker
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean converged(final int iteration,
|
public boolean converged(final int iteration,
|
||||||
final VectorialPointValuePair previous,
|
final PointVectorValuePair previous,
|
||||||
final VectorialPointValuePair current) {
|
final PointVectorValuePair current) {
|
||||||
final double[] p = previous.getPointRef();
|
final double[] p = previous.getPointRef();
|
||||||
final double[] c = current.getPointRef();
|
final double[] c = current.getPointRef();
|
||||||
for (int i = 0; i < p.length; ++i) {
|
for (int i = 0; i < p.length; ++i) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class SimpleVectorialValueChecker
|
public class SimpleVectorialValueChecker
|
||||||
extends AbstractConvergenceChecker<VectorialPointValuePair> {
|
extends AbstractConvergenceChecker<PointVectorValuePair> {
|
||||||
/**
|
/**
|
||||||
* Build an instance with default thresholds.
|
* Build an instance with default thresholds.
|
||||||
*/
|
*/
|
||||||
|
@ -71,8 +71,8 @@ public class SimpleVectorialValueChecker
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean converged(final int iteration,
|
public boolean converged(final int iteration,
|
||||||
final VectorialPointValuePair previous,
|
final PointVectorValuePair previous,
|
||||||
final VectorialPointValuePair current) {
|
final PointVectorValuePair current) {
|
||||||
final double[] p = previous.getValueRef();
|
final double[] p = previous.getValueRef();
|
||||||
final double[] c = current.getValueRef();
|
final double[] c = current.getValueRef();
|
||||||
for (int i = 0; i < p.length; ++i) {
|
for (int i = 0; i < p.length; ++i) {
|
||||||
|
|
|
@ -50,6 +50,6 @@ public interface VectorialConvergenceChecker {
|
||||||
* @param current point from current iteration
|
* @param current point from current iteration
|
||||||
* @return true if the algorithm is considered to have converged
|
* @return true if the algorithm is considered to have converged
|
||||||
*/
|
*/
|
||||||
boolean converged(int iteration, VectorialPointValuePair previous, VectorialPointValuePair current);
|
boolean converged(int iteration, PointVectorValuePair previous, PointVectorValuePair current);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 PointValuePair
|
|
||||||
* @see org.apache.commons.math.analysis.MultivariateVectorFunction
|
|
||||||
* @version $Id$
|
|
||||||
* @since 2.0
|
|
||||||
*/
|
|
||||||
public class VectorialPointValuePair implements Serializable {
|
|
||||||
|
|
||||||
/** Serializable version identifier. */
|
|
||||||
private static final long serialVersionUID = 1003888396256744753L;
|
|
||||||
|
|
||||||
/** Point coordinates. */
|
|
||||||
private final double[] point;
|
|
||||||
|
|
||||||
/** Vectorial value of the objective function at the point. */
|
|
||||||
private final double[] value;
|
|
||||||
|
|
||||||
/** Build a point/objective function value pair.
|
|
||||||
* @param point point coordinates (the built instance will store
|
|
||||||
* a copy of the array, not the array passed as argument)
|
|
||||||
* @param value value of an objective function at the point
|
|
||||||
*/
|
|
||||||
public VectorialPointValuePair(final double[] point, final double[] value) {
|
|
||||||
this.point = (point == null) ? null : point.clone();
|
|
||||||
this.value = (value == null) ? null : value.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Build a point/objective function value pair.
|
|
||||||
* @param point point coordinates (the built instance will store
|
|
||||||
* a copy of the array, not the array passed as argument)
|
|
||||||
* @param value value of an objective function at the point
|
|
||||||
* @param copyArray if true, the input arrays will be copied, otherwise
|
|
||||||
* they will be referenced
|
|
||||||
*/
|
|
||||||
public VectorialPointValuePair(final double[] point, final double[] value,
|
|
||||||
final boolean copyArray) {
|
|
||||||
this.point = copyArray ?
|
|
||||||
((point == null) ? null : point.clone()) :
|
|
||||||
point;
|
|
||||||
this.value = copyArray ?
|
|
||||||
((value == null) ? null : value.clone()) :
|
|
||||||
value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the point.
|
|
||||||
* @return a copy of the stored point
|
|
||||||
*/
|
|
||||||
public double[] getPoint() {
|
|
||||||
return (point == null) ? null : point.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get a reference to the point.
|
|
||||||
* <p>This method is provided as a convenience to avoid copying
|
|
||||||
* the array, the elements of the array should <em>not</em> be modified.</p>
|
|
||||||
* @return a reference to the internal array storing the point
|
|
||||||
*/
|
|
||||||
public double[] getPointRef() {
|
|
||||||
return point;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the value of the objective function.
|
|
||||||
* @return a copy of the stored value of the objective function
|
|
||||||
*/
|
|
||||||
public double[] getValue() {
|
|
||||||
return (value == null) ? null : value.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get a reference to the value of the objective function.
|
|
||||||
* <p>This method is provided as a convenience to avoid copying
|
|
||||||
* the array, the elements of the array should <em>not</em> be modified.</p>
|
|
||||||
* @return a reference to the internal array storing the value of the objective function
|
|
||||||
*/
|
|
||||||
public double[] getValueRef() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -25,7 +25,7 @@ import org.apache.commons.math.exception.NullArgumentException;
|
||||||
import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
import org.apache.commons.math.analysis.MultivariateVectorFunction;
|
||||||
import org.apache.commons.math.optimization.BaseMultivariateVectorOptimizer;
|
import org.apache.commons.math.optimization.BaseMultivariateVectorOptimizer;
|
||||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends Multi
|
||||||
/** Evaluations counter. */
|
/** Evaluations counter. */
|
||||||
protected final Incrementor evaluations = new Incrementor();
|
protected final Incrementor evaluations = new Incrementor();
|
||||||
/** Convergence checker. */
|
/** Convergence checker. */
|
||||||
private ConvergenceChecker<VectorialPointValuePair> checker;
|
private ConvergenceChecker<PointVectorValuePair> checker;
|
||||||
/** Target value for the objective functions at optimum. */
|
/** Target value for the objective functions at optimum. */
|
||||||
private double[] target;
|
private double[] target;
|
||||||
/** Weight for the least squares cost computation. */
|
/** Weight for the least squares cost computation. */
|
||||||
|
@ -64,7 +64,7 @@ public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends Multi
|
||||||
/**
|
/**
|
||||||
* @param checker Convergence checker.
|
* @param checker Convergence checker.
|
||||||
*/
|
*/
|
||||||
protected BaseAbstractMultivariateVectorOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
|
protected BaseAbstractMultivariateVectorOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
|
||||||
this.checker = checker;
|
this.checker = checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends Multi
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public ConvergenceChecker<VectorialPointValuePair> getConvergenceChecker() {
|
public ConvergenceChecker<PointVectorValuePair> getConvergenceChecker() {
|
||||||
return checker;
|
return checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends Multi
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public VectorialPointValuePair optimize(int maxEval, FUNC f, double[] t, double[] w,
|
public PointVectorValuePair optimize(int maxEval, FUNC f, double[] t, double[] w,
|
||||||
double[] startPoint) {
|
double[] startPoint) {
|
||||||
// Checks.
|
// Checks.
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
|
@ -147,7 +147,7 @@ public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends Multi
|
||||||
* @return the point/value pair giving the optimal value for the
|
* @return the point/value pair giving the optimal value for the
|
||||||
* objective function.
|
* objective function.
|
||||||
*/
|
*/
|
||||||
protected abstract VectorialPointValuePair doOptimize();
|
protected abstract PointVectorValuePair doOptimize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a reference to the {@link #target array}.
|
* @return a reference to the {@link #target array}.
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction
|
||||||
import org.apache.commons.math.analysis.ParametricUnivariateFunction;
|
import org.apache.commons.math.analysis.ParametricUnivariateFunction;
|
||||||
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
||||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
|
|
||||||
/** Fitter for parametric univariate real functions y = f(x).
|
/** Fitter for parametric univariate real functions y = f(x).
|
||||||
* <p>When a univariate real function y = f(x) does depend on some
|
* <p>When a univariate real function y = f(x) does depend on some
|
||||||
|
@ -154,7 +154,7 @@ public class CurveFitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform the fit
|
// perform the fit
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(maxEval, new TheoreticalValuesFunction(f),
|
optimizer.optimize(maxEval, new TheoreticalValuesFunction(f),
|
||||||
target, weights, initialGuess);
|
target, weights, initialGuess);
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.commons.math.linear.DecompositionSolver;
|
||||||
import org.apache.commons.math.linear.MatrixUtils;
|
import org.apache.commons.math.linear.MatrixUtils;
|
||||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||||
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
import org.apache.commons.math.optimization.DifferentiableMultivariateVectorOptimizer;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.optimization.direct.BaseAbstractMultivariateVectorOptimizer;
|
import org.apache.commons.math.optimization.direct.BaseAbstractMultivariateVectorOptimizer;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public abstract class AbstractLeastSquaresOptimizer
|
||||||
/**
|
/**
|
||||||
* @param checker Convergence checker.
|
* @param checker Convergence checker.
|
||||||
*/
|
*/
|
||||||
protected AbstractLeastSquaresOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
|
protected AbstractLeastSquaresOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
|
||||||
super(checker);
|
super(checker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ public abstract class AbstractLeastSquaresOptimizer
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public VectorialPointValuePair optimize(int maxEval,
|
public PointVectorValuePair optimize(int maxEval,
|
||||||
final DifferentiableMultivariateVectorFunction f,
|
final DifferentiableMultivariateVectorFunction f,
|
||||||
final double[] target, final double[] weights,
|
final double[] target, final double[] weights,
|
||||||
final double[] startPoint) {
|
final double[] startPoint) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.linear.SingularMatrixException;
|
import org.apache.commons.math.linear.SingularMatrixException;
|
||||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||||
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gauss-Newton least-squares solver.
|
* Gauss-Newton least-squares solver.
|
||||||
|
@ -64,7 +64,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
*
|
*
|
||||||
* @param checker Convergence checker.
|
* @param checker Convergence checker.
|
||||||
*/
|
*/
|
||||||
public GaussNewtonOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
|
public GaussNewtonOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
|
||||||
this(true, checker);
|
this(true, checker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,29 +88,29 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
* @param checker Convergence checker.
|
* @param checker Convergence checker.
|
||||||
*/
|
*/
|
||||||
public GaussNewtonOptimizer(final boolean useLU,
|
public GaussNewtonOptimizer(final boolean useLU,
|
||||||
ConvergenceChecker<VectorialPointValuePair> checker) {
|
ConvergenceChecker<PointVectorValuePair> checker) {
|
||||||
super(checker);
|
super(checker);
|
||||||
this.useLU = useLU;
|
this.useLU = useLU;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public VectorialPointValuePair doOptimize() {
|
public PointVectorValuePair doOptimize() {
|
||||||
|
|
||||||
final ConvergenceChecker<VectorialPointValuePair> checker
|
final ConvergenceChecker<PointVectorValuePair> checker
|
||||||
= getConvergenceChecker();
|
= getConvergenceChecker();
|
||||||
|
|
||||||
// iterate until convergence is reached
|
// iterate until convergence is reached
|
||||||
VectorialPointValuePair current = null;
|
PointVectorValuePair current = null;
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
for (boolean converged = false; !converged;) {
|
for (boolean converged = false; !converged;) {
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
// evaluate the objective function and its jacobian
|
// evaluate the objective function and its jacobian
|
||||||
VectorialPointValuePair previous = current;
|
PointVectorValuePair previous = current;
|
||||||
updateResidualsAndCost();
|
updateResidualsAndCost();
|
||||||
updateJacobian();
|
updateJacobian();
|
||||||
current = new VectorialPointValuePair(point, objective);
|
current = new PointVectorValuePair(point, objective);
|
||||||
|
|
||||||
final double[] targetValues = getTargetRef();
|
final double[] targetValues = getTargetRef();
|
||||||
final double[] residualsWeights = getWeightRef();
|
final double[] residualsWeights = getWeightRef();
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.math.exception.ConvergenceException;
|
import org.apache.commons.math.exception.ConvergenceException;
|
||||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.optimization.ConvergenceChecker;
|
import org.apache.commons.math.optimization.ConvergenceChecker;
|
||||||
import org.apache.commons.math.util.Precision;
|
import org.apache.commons.math.util.Precision;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
|
@ -166,7 +166,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
*
|
*
|
||||||
* @param checker Convergence checker.
|
* @param checker Convergence checker.
|
||||||
*/
|
*/
|
||||||
public LevenbergMarquardtOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
|
public LevenbergMarquardtOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
|
||||||
this(100, checker, 1e-10, 1e-10, 1e-10, Precision.SAFE_MIN);
|
this(100, checker, 1e-10, 1e-10, 1e-10, Precision.SAFE_MIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
* of the matrix is reduced.
|
* of the matrix is reduced.
|
||||||
*/
|
*/
|
||||||
public LevenbergMarquardtOptimizer(double initialStepBoundFactor,
|
public LevenbergMarquardtOptimizer(double initialStepBoundFactor,
|
||||||
ConvergenceChecker<VectorialPointValuePair> checker,
|
ConvergenceChecker<PointVectorValuePair> checker,
|
||||||
double costRelativeTolerance,
|
double costRelativeTolerance,
|
||||||
double parRelativeTolerance,
|
double parRelativeTolerance,
|
||||||
double orthoTolerance,
|
double orthoTolerance,
|
||||||
|
@ -269,7 +269,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
protected VectorialPointValuePair doOptimize() {
|
protected PointVectorValuePair doOptimize() {
|
||||||
// arrays shared with the other private methods
|
// arrays shared with the other private methods
|
||||||
solvedCols = FastMath.min(rows, cols);
|
solvedCols = FastMath.min(rows, cols);
|
||||||
diagR = new double[cols];
|
diagR = new double[cols];
|
||||||
|
@ -296,9 +296,9 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
// outer loop
|
// outer loop
|
||||||
lmPar = 0;
|
lmPar = 0;
|
||||||
boolean firstIteration = true;
|
boolean firstIteration = true;
|
||||||
VectorialPointValuePair current = new VectorialPointValuePair(point, objective);
|
PointVectorValuePair current = new PointVectorValuePair(point, objective);
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
final ConvergenceChecker<VectorialPointValuePair> checker = getConvergenceChecker();
|
final ConvergenceChecker<PointVectorValuePair> checker = getConvergenceChecker();
|
||||||
while (true) {
|
while (true) {
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute the Q.R. decomposition of the jacobian matrix
|
// compute the Q.R. decomposition of the jacobian matrix
|
||||||
VectorialPointValuePair previous = current;
|
PointVectorValuePair previous = current;
|
||||||
updateJacobian();
|
updateJacobian();
|
||||||
qrDecomposition();
|
qrDecomposition();
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
if (maxCosine <= orthoTolerance) {
|
if (maxCosine <= orthoTolerance) {
|
||||||
// convergence has been reached
|
// convergence has been reached
|
||||||
updateResidualsAndCost();
|
updateResidualsAndCost();
|
||||||
current = new VectorialPointValuePair(point, objective);
|
current = new PointVectorValuePair(point, objective);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
xNorm += xK * xK;
|
xNorm += xK * xK;
|
||||||
}
|
}
|
||||||
xNorm = FastMath.sqrt(xNorm);
|
xNorm = FastMath.sqrt(xNorm);
|
||||||
current = new VectorialPointValuePair(point, objective);
|
current = new PointVectorValuePair(point, objective);
|
||||||
|
|
||||||
// tests for convergence.
|
// tests for convergence.
|
||||||
if (checker != null) {
|
if (checker != null) {
|
||||||
|
|
|
@ -117,11 +117,11 @@ public class DifferentiableMultivariateVectorMultiStartOptimizerTest {
|
||||||
} catch (MathIllegalStateException ise) {
|
} catch (MathIllegalStateException ise) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
||||||
Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
|
||||||
Assert.assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
|
Assert.assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
|
||||||
VectorialPointValuePair[] optima = optimizer.getOptima();
|
PointVectorValuePair[] optima = optimizer.getOptima();
|
||||||
Assert.assertEquals(10, optima.length);
|
Assert.assertEquals(10, optima.length);
|
||||||
for (int i = 0; i < optima.length; ++i) {
|
for (int i = 0; i < optima.length; ++i) {
|
||||||
Assert.assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10);
|
Assert.assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
||||||
import org.apache.commons.math.linear.BlockRealMatrix;
|
import org.apache.commons.math.linear.BlockRealMatrix;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -107,7 +107,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -124,7 +124,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -149,7 +149,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
||||||
new double[] { 0, 0, 0, 0, 0, 0 });
|
new double[] { 0, 0, 0, 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -170,7 +170,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -194,7 +194,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
||||||
new double[] { 0, 0, 0, 0, 0, 0 });
|
new double[] { 0, 0, 0, 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -234,7 +234,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum1 =
|
PointVectorValuePair optimum1 =
|
||||||
optimizer.optimize(100, problem1, problem1.target, new double[] { 1, 1, 1, 1 },
|
optimizer.optimize(100, problem1, problem1.target, new double[] { 1, 1, 1, 1 },
|
||||||
new double[] { 0, 1, 2, 3 });
|
new double[] { 0, 1, 2, 3 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -249,7 +249,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
{ 8.00, 5.98, 9.89, 9.00 },
|
{ 8.00, 5.98, 9.89, 9.00 },
|
||||||
{ 6.99, 4.99, 9.00, 9.98 }
|
{ 6.99, 4.99, 9.00, 9.98 }
|
||||||
}, new double[] { 32, 23, 33, 31 });
|
}, new double[] { 32, 23, 33, 31 });
|
||||||
VectorialPointValuePair optimum2 =
|
PointVectorValuePair optimum2 =
|
||||||
optimizer.optimize(100, problem2, problem2.target, new double[] { 1, 1, 1, 1 },
|
optimizer.optimize(100, problem2, problem2.target, new double[] { 1, 1, 1, 1 },
|
||||||
new double[] { 0, 1, 2, 3 });
|
new double[] { 0, 1, 2, 3 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -304,7 +304,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 },
|
||||||
new double[] { 1, 1 });
|
new double[] { 1, 1 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -336,7 +336,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -355,7 +355,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -395,7 +395,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-13, 1.0e-13));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-13, 1.0e-13));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 },
|
optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 },
|
||||||
new double[] { 1, 1, 1, 1, 1 },
|
new double[] { 1, 1, 1, 1, 1 },
|
||||||
new double[] { 98.680, 47.345 });
|
new double[] { 98.680, 47.345 });
|
||||||
|
@ -439,7 +439,7 @@ public class GaussNewtonOptimizerTest {
|
||||||
GaussNewtonOptimizer optimizer
|
GaussNewtonOptimizer optimizer
|
||||||
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
= new GaussNewtonOptimizer(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, circle, target, weights, new double[] { 0, 0 });
|
optimizer.optimize(100, circle, target, weights, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(-0.1517383071957963, optimum.getPointRef()[0], 1.0e-6);
|
Assert.assertEquals(-0.1517383071957963, optimum.getPointRef()[0], 1.0e-6);
|
||||||
Assert.assertEquals(0.2074999736353867, optimum.getPointRef()[1], 1.0e-6);
|
Assert.assertEquals(0.2074999736353867, optimum.getPointRef()[1], 1.0e-6);
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.commons.math.linear.BlockRealMatrix;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.linear.SingularMatrixException;
|
import org.apache.commons.math.linear.SingularMatrixException;
|
||||||
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.util.Precision;
|
import org.apache.commons.math.util.Precision;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -109,7 +109,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
LinearProblem problem =
|
LinearProblem problem =
|
||||||
new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
|
new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
try {
|
try {
|
||||||
|
@ -130,7 +130,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
new double[] { 4.0, 6.0, 1.0 });
|
new double[] { 4.0, 6.0, 1.0 });
|
||||||
|
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -151,7 +151,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
{ 0, 0, 0, 0, 0, 2 }
|
{ 0, 0, 0, 0, 0, 2 }
|
||||||
}, new double[] { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5 });
|
}, new double[] { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5 });
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
||||||
new double[] { 0, 0, 0, 0, 0, 0 });
|
new double[] { 0, 0, 0, 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -169,7 +169,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
{ 0, -1, 1 }
|
{ 0, -1, 1 }
|
||||||
}, new double[] { 1, 1, 1});
|
}, new double[] { 1, 1, 1});
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 }, new double[] { 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -190,7 +190,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
}, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2});
|
}, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2});
|
||||||
|
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1, 1 },
|
||||||
new double[] { 0, 0, 0, 0, 0, 0 });
|
new double[] { 0, 0, 0, 0, 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -230,7 +230,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
{ 7.0, 5.0, 9.0, 10.0 }
|
{ 7.0, 5.0, 9.0, 10.0 }
|
||||||
}, new double[] { 32, 23, 33, 31 });
|
}, new double[] { 32, 23, 33, 31 });
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum1 =
|
PointVectorValuePair optimum1 =
|
||||||
optimizer.optimize(100, problem1, problem1.target, new double[] { 1, 1, 1, 1 },
|
optimizer.optimize(100, problem1, problem1.target, new double[] { 1, 1, 1, 1 },
|
||||||
new double[] { 0, 1, 2, 3 });
|
new double[] { 0, 1, 2, 3 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -245,7 +245,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
{ 8.00, 5.98, 9.89, 9.00 },
|
{ 8.00, 5.98, 9.89, 9.00 },
|
||||||
{ 6.99, 4.99, 9.00, 9.98 }
|
{ 6.99, 4.99, 9.00, 9.98 }
|
||||||
}, new double[] { 32, 23, 33, 31 });
|
}, new double[] { 32, 23, 33, 31 });
|
||||||
VectorialPointValuePair optimum2 =
|
PointVectorValuePair optimum2 =
|
||||||
optimizer.optimize(100, problem2, problem2.target, new double[] { 1, 1, 1, 1 },
|
optimizer.optimize(100, problem2, problem2.target, new double[] { 1, 1, 1, 1 },
|
||||||
new double[] { 0, 1, 2, 3 });
|
new double[] { 0, 1, 2, 3 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -281,7 +281,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
}, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
|
}, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
|
||||||
|
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1, 1, 1 },
|
||||||
new double[] { 2, 2, 2, 2, 2, 2 });
|
new double[] { 2, 2, 2, 2, 2, 2 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -300,7 +300,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
}, new double[] { 3.0, 1.0, 5.0 });
|
}, new double[] { 3.0, 1.0, 5.0 });
|
||||||
|
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 },
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1, 1 },
|
||||||
new double[] { 1, 1 });
|
new double[] { 1, 1 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
|
@ -327,7 +327,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
new LinearProblem(new double[][] { { 1, 0 }, { 0, 1 } }, new double[] { -1, 1 });
|
new LinearProblem(new double[][] { { 1, 0 }, { 0, 1 } }, new double[] { -1, 1 });
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
|
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
optimizer.optimize(100, problem, problem.target, new double[] { 1, 1 }, new double[] { 0, 0 });
|
||||||
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
Assert.assertEquals(0, optimizer.getRMS(), 1.0e-10);
|
||||||
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
Assert.assertEquals(-1, optimum.getPoint()[0], 1.0e-10);
|
||||||
|
@ -398,7 +398,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
circle.addPoint( 35.0, 15.0);
|
circle.addPoint( 35.0, 15.0);
|
||||||
circle.addPoint( 45.0, 97.0);
|
circle.addPoint( 45.0, 97.0);
|
||||||
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 }, new double[] { 1, 1, 1, 1, 1 },
|
optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 }, new double[] { 1, 1, 1, 1, 1 },
|
||||||
new double[] { 98.680, 47.345 });
|
new double[] { 98.680, 47.345 });
|
||||||
Assert.assertTrue(optimizer.getEvaluations() < 10);
|
Assert.assertTrue(optimizer.getEvaluations() < 10);
|
||||||
|
@ -481,7 +481,7 @@ public class LevenbergMarquardtOptimizerTest {
|
||||||
}
|
}
|
||||||
LevenbergMarquardtOptimizer optimizer
|
LevenbergMarquardtOptimizer optimizer
|
||||||
= new LevenbergMarquardtOptimizer(new SimpleVectorialValueChecker(1.0e-8, 1.0e-8));
|
= new LevenbergMarquardtOptimizer(new SimpleVectorialValueChecker(1.0e-8, 1.0e-8));
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(100, circle, target, weights, new double[] { -12, -12 });
|
optimizer.optimize(100, circle, target, weights, new double[] { -12, -12 });
|
||||||
Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]);
|
Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]);
|
||||||
Assert.assertTrue(optimizer.getEvaluations() < 25);
|
Assert.assertTrue(optimizer.getEvaluations() < 25);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Arrays;
|
||||||
import org.apache.commons.math.exception.TooManyEvaluationsException;
|
import org.apache.commons.math.exception.TooManyEvaluationsException;
|
||||||
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction;
|
import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction;
|
||||||
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
import org.apache.commons.math.analysis.MultivariateMatrixFunction;
|
||||||
import org.apache.commons.math.optimization.VectorialPointValuePair;
|
import org.apache.commons.math.optimization.PointVectorValuePair;
|
||||||
import org.apache.commons.math.util.FastMath;
|
import org.apache.commons.math.util.FastMath;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -509,7 +509,7 @@ public class MinpackTest {
|
||||||
2.22044604926e-16);
|
2.22044604926e-16);
|
||||||
// Assert.assertTrue(function.checkTheoreticalStartCost(optimizer.getRMS()));
|
// Assert.assertTrue(function.checkTheoreticalStartCost(optimizer.getRMS()));
|
||||||
try {
|
try {
|
||||||
VectorialPointValuePair optimum =
|
PointVectorValuePair optimum =
|
||||||
optimizer.optimize(400 * (function.getN() + 1), function,
|
optimizer.optimize(400 * (function.getN() + 1), function,
|
||||||
function.getTarget(), function.getWeight(),
|
function.getTarget(), function.getWeight(),
|
||||||
function.getStartPoint());
|
function.getStartPoint());
|
||||||
|
@ -579,7 +579,7 @@ public class MinpackTest {
|
||||||
Assert.assertEquals(theoreticalMinCost, FastMath.sqrt(m) * rms, threshold);
|
Assert.assertEquals(theoreticalMinCost, FastMath.sqrt(m) * rms, threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkTheoreticalMinParams(VectorialPointValuePair optimum) {
|
public void checkTheoreticalMinParams(PointVectorValuePair optimum) {
|
||||||
double[] params = optimum.getPointRef();
|
double[] params = optimum.getPointRef();
|
||||||
if (theoreticalMinParams != null) {
|
if (theoreticalMinParams != null) {
|
||||||
for (int i = 0; i < theoreticalMinParams.length; ++i) {
|
for (int i = 0; i < theoreticalMinParams.length; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue