Search in sources :

Example 1 with MultiDirectionalSimplex

use of org.apache.commons.math3.optim.nonlinear.scalar.noderiv.MultiDirectionalSimplex 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)

Aggregations

InitialGuess (org.apache.commons.math3.optim.InitialGuess)1 MaxEval (org.apache.commons.math3.optim.MaxEval)1 SimpleBounds (org.apache.commons.math3.optim.SimpleBounds)1 MultiDirectionalSimplex (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.MultiDirectionalSimplex)1 SimplexOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer)1 MersenneTwister (org.apache.commons.math3.random.MersenneTwister)1