use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer in project GDSC-SMLM by aherbert.
the class FIRE method findMin.
private UnivariatePointValuePair findMin(UnivariatePointValuePair current, SimplexOptimizer o, MultivariateFunction f, double qValue) {
try {
NelderMeadSimplex simplex = new NelderMeadSimplex(1);
double[] initialSolution = { qValue };
PointValuePair solution = o.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(f), GoalType.MINIMIZE);
UnivariatePointValuePair next = (solution == null) ? null : new UnivariatePointValuePair(solution.getPointRef()[0], solution.getValue());
if (next == null)
return current;
//System.out.printf("Simplex [%f] %f = %f\n", qValue, next.getPoint(), next.getValue());
if (current != null)
return (next.getValue() < current.getValue()) ? next : current;
return next;
} catch (Exception e) {
return current;
}
}
use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer in project GDSC-SMLM by aherbert.
the class FIRE method findMin.
private PointValuePair findMin(PointValuePair current, SimplexOptimizer o, MultivariateFunction f, double[] initialSolution) {
try {
NelderMeadSimplex simplex = new NelderMeadSimplex(initialSolution.length);
PointValuePair next = o.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(f), GoalType.MINIMIZE);
if (next == null)
return current;
// Arrays.toString(next.getPointRef()), next.getValue());
if (current != null)
return (next.getValue() < current.getValue()) ? next : current;
return next;
} catch (Exception e) {
return current;
}
}
use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer in project narchy by automenta.
the class Optimize method solve.
public void solve(int dim, ObjectiveFunction func, double[] mid, double[] min, double[] max, double[] inc, int maxIterations) {
if (dim == 1) {
// use a solver capable of 1 dim
new SimplexOptimizer(1e-10, 1e-30).optimize(new MaxEval(maxIterations), func, GoalType.MAXIMIZE, new InitialGuess(mid), // new NelderMeadSimplex(inc)
new MultiDirectionalSimplex(inc));
} else {
int popSize = // 4 + 3 ln(n)
(int) Math.ceil(4 + 3 * Math.log(tweaks.size()));
double[] sigma = MathArrays.scale(1f, inc);
MyCMAESOptimizer m = new MyCMAESOptimizer(maxIterations, Double.NaN, true, 0, 1, new MersenneTwister(System.nanoTime()), true, null, popSize, sigma);
m.optimize(func, GoalType.MAXIMIZE, new MaxEval(maxIterations), new SimpleBounds(min, max), new InitialGuess(mid));
m.print(System.out);
// final int numIterpolationPoints = 3 * dim; //2 * dim + 1 + 1;
// new BOBYQAOptimizer(numIterpolationPoints,
// dim * 2.0,
// 1.0E-4D /* ? */).optimize(
// MaxEval.unlimited(), //new MaxEval(maxIterations),
// new MaxIter(maxIterations),
// func,
// GoalType.MAXIMIZE,
// new SimpleBounds(min, max),
// new InitialGuess(mid));
}
}
use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer in project GDSC-SMLM by aherbert.
the class PcPalmMolecules method optimiseSimplex.
private double[] optimiseSimplex(float[] x, float[] y, double[] initialSolution) {
// Simplex optimisation
final SkewNormalMultivariateFunction sn2 = new SkewNormalMultivariateFunction(initialSolution);
sn2.addData(x, y);
final NelderMeadSimplex simplex = new NelderMeadSimplex(4);
final SimplexOptimizer opt = new SimplexOptimizer(1e-6, 1e-10);
final PointValuePair solution = opt.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(sn2), GoalType.MINIMIZE);
return solution.getPointRef();
}
use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer in project GDSC-SMLM by aherbert.
the class Fire method findMin.
private static PointValuePair findMin(PointValuePair current, SimplexOptimizer optimiser, MultivariateFunction func, double[] initialSolution) {
try {
final NelderMeadSimplex simplex = new NelderMeadSimplex(initialSolution.length);
final PointValuePair next = optimiser.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(func), GoalType.MINIMIZE);
if (next == null) {
return current;
}
if (current != null) {
return (next.getValue() < current.getValue()) ? next : current;
}
return next;
} catch (final Exception ex) {
return current;
}
}
Aggregations