Search in sources :

Example 1 with SimplexOptimizer

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;
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) TooManyEvaluationsException(org.apache.commons.math3.exception.TooManyEvaluationsException) PointValuePair(org.apache.commons.math3.optim.PointValuePair) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)

Example 2 with SimplexOptimizer

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;
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) TooManyEvaluationsException(org.apache.commons.math3.exception.TooManyEvaluationsException) PointValuePair(org.apache.commons.math3.optim.PointValuePair) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)

Example 3 with SimplexOptimizer

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));
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) MultiDirectionalSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.MultiDirectionalSimplex) SimpleBounds(org.apache.commons.math3.optim.SimpleBounds) SimplexOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer) MersenneTwister(org.apache.commons.math3.random.MersenneTwister)

Example 4 with SimplexOptimizer

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();
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) SimplexOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) PointValuePair(org.apache.commons.math3.optim.PointValuePair)

Example 5 with SimplexOptimizer

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;
    }
}
Also used : MaxEval(org.apache.commons.math3.optim.MaxEval) InitialGuess(org.apache.commons.math3.optim.InitialGuess) NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) UnivariateObjectiveFunction(org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) DataException(uk.ac.sussex.gdsc.core.data.DataException) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) PointValuePair(org.apache.commons.math3.optim.PointValuePair) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)

Aggregations

PointValuePair (org.apache.commons.math3.optim.PointValuePair)8 InitialGuess (org.apache.commons.math3.optim.InitialGuess)7 MaxEval (org.apache.commons.math3.optim.MaxEval)7 ObjectiveFunction (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction)7 NelderMeadSimplex (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex)6 UnivariatePointValuePair (org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)6 SimplexOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer)5 UnivariateObjectiveFunction (org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction)4 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)3 DataException (uk.ac.sussex.gdsc.core.data.DataException)3 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)3 LoessInterpolator (org.apache.commons.math3.analysis.interpolation.LoessInterpolator)2 SimpleCurveFitter (org.apache.commons.math3.fitting.SimpleCurveFitter)2 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)2 WeightedObservedPoints (org.apache.commons.math3.fitting.WeightedObservedPoints)2 BrentOptimizer (org.apache.commons.math3.optim.univariate.BrentOptimizer)2 UnivariateOptimizer (org.apache.commons.math3.optim.univariate.UnivariateOptimizer)2 MersenneTwister (org.apache.commons.math3.random.MersenneTwister)2 MedianWindow (gdsc.core.utils.MedianWindow)1 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)1