Search in sources :

Example 6 with NelderMeadSimplex

use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex in project GDSC-SMLM by aherbert.

the class PCPALMMolecules method optimiseSimplex.

private double[] optimiseSimplex(float[] x, float[] y, double[] initialSolution) {
    // Simplex optimisation
    SkewNormalMultivariateFunction sn2 = new SkewNormalMultivariateFunction(initialSolution);
    sn2.addData(x, y);
    NelderMeadSimplex simplex = new NelderMeadSimplex(4);
    SimplexOptimizer opt = new SimplexOptimizer(1e-6, 1e-10);
    PointValuePair solution = opt.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(sn2), GoalType.MINIMIZE);
    double[] skewParameters2 = solution.getPointRef();
    return skewParameters2;
}
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 7 with NelderMeadSimplex

use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex in project aic-expresso by aic-sri-international.

the class OptimizationWithNelderMead method optimize.

/**
 * Main method. It computes the optimum of the function and returns a PointValuePair which contains the argopt and the optimum.
 * Both can be computed directly with findOptimum and findArgopt.
 */
private PointValuePair optimize(SimplexOptimizer optimizer) {
    final FunctionToOptimize f = new FunctionToOptimize(this.expressionToOptimize);
    double[] nelderMeadSimplexParameters = new double[numberOfVariablesInExpression()];
    for (int i = 0; i < numberOfVariablesInExpression(); i++) {
        nelderMeadSimplexParameters[i] = 0.2;
    }
    final PointValuePair optimum = optimizer.optimize(this.maxEval, new ObjectiveFunction(f), this.goalType, this.initialGuess, new NelderMeadSimplex(nelderMeadSimplexParameters));
    return optimum;
}
Also used : NelderMeadSimplex(org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) PointValuePair(org.apache.commons.math3.optim.PointValuePair)

Example 8 with NelderMeadSimplex

use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex in project tetrad by cmu-phil.

the class GeneralizedSemEstimator method optimize.

private double[] optimize(MultivariateFunction function, double[] values, int optimizer) {
    PointValuePair pair;
    if (optimizer == 1) {
        // 0.01, 0.000001
        // 2.0D * FastMath.ulp(1.0D), 1e-8
        MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);
        pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MINIMIZE, new MaxEval(100000));
    } else if (optimizer == 2) {
        MultivariateOptimizer search = new SimplexOptimizer(1e-7, 1e-7);
        pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MINIMIZE, new MaxEval(100000), new NelderMeadSimplex(values.length));
    } else if (optimizer == 3) {
        int dim = values.length;
        int additionalInterpolationPoints = 0;
        final int numIterpolationPoints = 2 * dim + 1 + additionalInterpolationPoints;
        BOBYQAOptimizer search = new BOBYQAOptimizer(numIterpolationPoints);
        pair = search.optimize(new MaxEval(100000), new ObjectiveFunction(function), GoalType.MINIMIZE, new InitialGuess(values), SimpleBounds.unbounded(dim));
    } else if (optimizer == 4) {
        MultivariateOptimizer search = new CMAESOptimizer(3000000, .05, false, 0, 0, new MersenneTwister(), false, new SimplePointChecker<PointValuePair>(0.5, 0.5));
        pair = search.optimize(new MaxEval(30000), new ObjectiveFunction(function), GoalType.MINIMIZE, new InitialGuess(values), new CMAESOptimizer.Sigma(new double[values.length]), new CMAESOptimizer.PopulationSize(1000));
    } else if (optimizer == 5) {
        // 0.01, 0.000001
        // 2.0D * FastMath.ulp(1.0D), 1e-8
        MultivariateOptimizer search = new PowellOptimizer(.05, .05);
        pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MINIMIZE, new MaxEval(100000));
    } else if (optimizer == 6) {
        MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);
        pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MAXIMIZE, new MaxEval(10000));
    } else {
        throw new IllegalStateException();
    }
    return pair.getPoint();
}
Also used : MultivariateOptimizer(org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer) ObjectiveFunction(org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction) MersenneTwister(org.apache.commons.math3.random.MersenneTwister)

Example 9 with NelderMeadSimplex

use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex in project GDSC-SMLM by aherbert.

the class Fire method findMin.

private static UnivariatePointValuePair findMin(UnivariatePointValuePair current, SimplexOptimizer optimiser, MultivariateFunction func, double qvalue) {
    try {
        final NelderMeadSimplex simplex = new NelderMeadSimplex(1);
        final double[] initialSolution = { qvalue };
        final PointValuePair solution = optimiser.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(func), GoalType.MINIMIZE);
        final UnivariatePointValuePair next = (solution == null) ? null : new UnivariatePointValuePair(solution.getPointRef()[0], solution.getValue());
        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) UnivariatePointValuePair(org.apache.commons.math3.optim.univariate.UnivariatePointValuePair) 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

ObjectiveFunction (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction)8 InitialGuess (org.apache.commons.math3.optim.InitialGuess)7 MaxEval (org.apache.commons.math3.optim.MaxEval)7 PointValuePair (org.apache.commons.math3.optim.PointValuePair)7 NelderMeadSimplex (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex)7 UnivariateObjectiveFunction (org.apache.commons.math3.optim.univariate.UnivariateObjectiveFunction)4 UnivariatePointValuePair (org.apache.commons.math3.optim.univariate.UnivariatePointValuePair)4 SimplexOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer)3 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)2 MersenneTwister (org.apache.commons.math3.random.MersenneTwister)2 DataException (uk.ac.sussex.gdsc.core.data.DataException)2 ConversionException (uk.ac.sussex.gdsc.core.data.utils.ConversionException)2 SimpleBounds (org.apache.commons.math3.optim.SimpleBounds)1 MultivariateOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer)1 MultiDirectionalSimplex (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.MultiDirectionalSimplex)1