Example usage for org.apache.commons.math3.optim.nonlinear.scalar.noderiv PowellOptimizer PowellOptimizer

List of usage examples for org.apache.commons.math3.optim.nonlinear.scalar.noderiv PowellOptimizer PowellOptimizer

Introduction

In this page you can find the example usage for org.apache.commons.math3.optim.nonlinear.scalar.noderiv PowellOptimizer PowellOptimizer.

Prototype

public PowellOptimizer(double rel, double abs) 

Source Link

Document

The parameters control the default convergence checking procedure.

Usage

From source file:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApachePowell.java

@Override
public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate,
        int NUM_RATES, int numEval) {

    double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset
    Arrays.fill(startingVertex, 0.0);

    PowellOptimizer optimizer = new PowellOptimizer(1e-3, 5);

    // needed since one optimization found positive 
    // charges (paying customer to consume...)
    double[][] boundaries = createBoundaries(NUM_RATES);

    final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval),
            //new ObjectiveFunction(new MultivariateFunctionMappingAdapter(tariffUtilityEstimate, boundaries[0], boundaries[1])),
            new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)),
            GoalType.MAXIMIZE, new InitialGuess(startingVertex));

    TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>();
    eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey()));
    return eval2TOUTariff;
}

From source file:edu.uchc.octane.GaussianFitAstigmatism.java

@Override
public double[] doFit() {
    double[] initParameters;

    if (bPreprocessBg_) {
        initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_, sigma2_, sigma2_ };
    } else {/*from   www . ja  v  a  2  s.  co m*/
        initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_, sigma2_, sigma2_, bg_ };
    }

    PowellOptimizer optimizer = new PowellOptimizer(1e-4, 1e-1);

    MultivariateFunction func = new MultivariateFunction() {
        @Override
        public double value(double[] point) {

            double bg = bPreprocessBg_ ? 0 : point[3];

            double v = 0;

            for (int xi = -windowSize_; xi < windowSize_; xi++) {
                for (int yi = -windowSize_; yi < windowSize_; yi++) {
                    double delta = getValueExcludingBackground(xi, yi, point) + bg - pixelValue(xi, yi);
                    v += delta * delta;
                }
            }
            return v;
        }
    };

    pvp_ = optimizer.optimize(new ObjectiveFunction(func), new InitialGuess(initParameters), new MaxEval(10000),
            GoalType.MINIMIZE);

    //      double sigmax = pvp.getPoint()[3];
    //      double sigmay = pvp.getPoint()[4];
    //      if (calibration_ != null) {
    //         double [] pn = new double[4];
    //         pn[0] = p1_;
    //         pn[1] = p2_;
    //         pn[2] = p3_ + 2 * calibration_[2] * (calibration_[0] - sigmax) + 2 * calibration_[5] * (calibration_[3] - sigmay);
    //         pn[3] = calibration_[1] * (calibration_[0] - sigmax) + calibration_[4] * (calibration_[3] - sigmay);
    //         
    //         Complex [] roots = new LaguerreSolver().solveAllComplex(pn, 0);
    //         
    //         int minIndex = -1;
    //         double minV = Double.MAX_VALUE;
    //         for (int i = 0; i < 3; i ++) {
    //            double v;
    //            if (FastMath.abs(roots[i].getImaginary()) < 1e-7) {
    //               double z = roots[i].getReal(); 
    //               double vx = calibration_[0] + calibration_[1] * z + calibration_[2] * z * z - sigmax;
    //               double vy = calibration_[3] + calibration_[4] * z + calibration_[5] * z * z - sigmay;
    //               v = vx * vx + vy * vy;
    //               if (v < minV) {
    //                  minV = v;
    //                  minIndex = i;
    //               }
    //            }
    //         }
    //         
    //         if (minV > errTol_) {
    //            return null;
    //         }
    //
    //         z_ = roots[minIndex].getReal();
    //      }

    if (calibration_ != null) {
        calculateZ();
    }

    return pvp_.getPoint();
}

From source file:edu.uchc.octane.GaussianFit2D.java

@Override
public double[] doFit() {

    double[] initParameters;

    if (floatingSigma_) {
        if (bPreprocessBg_) {
            initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_, sigma2_ };
        } else {//from   ww  w.ja  v a 2  s.c  o m
            initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_, bg_, sigma2_ };
        }
    } else {
        if (bPreprocessBg_) {
            initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_ };
        } else {
            initParameters = new double[] { 0, 0, pixelValue(0, 0) - bg_, bg_ };
        }
    }

    PowellOptimizer optimizer = new PowellOptimizer(1e-4, 1e-1);

    MultivariateFunction func = new MultivariateFunction() {
        @Override
        public double value(double[] point) {

            //initParameters = point;
            double bg = bPreprocessBg_ ? 0 : point[3];

            double v = 0;

            for (int xi = -windowSize_; xi < windowSize_; xi++) {
                for (int yi = -windowSize_; yi < windowSize_; yi++) {
                    double delta = getValueExcludingBackground(xi, yi, point) + bg - pixelValue(xi, yi);
                    v += delta * delta;
                }
            }
            return v;
        }
    };

    pvp_ = optimizer.optimize(new ObjectiveFunction(func), new InitialGuess(initParameters), new MaxEval(10000),
            GoalType.MINIMIZE);

    return pvp_.getPoint();
}

From source file:edu.cmu.tetrad.sem.SemOptimizerPowell.java

public void optimize(SemIm semIm) {
    double min = Double.POSITIVE_INFINITY;
    double[] point = null;

    for (int count = 0; count < numRestarts + 1; count++) {
        System.out.println("Trial " + (count + 1));
        SemIm _sem2 = new SemIm(semIm);

        List<Parameter> freeParameters = _sem2.getFreeParameters();

        double[] p = new double[freeParameters.size()];

        for (int i = 0; i < freeParameters.size(); i++) {
            if (freeParameters.get(i).getType() == ParamType.VAR) {
                p[i] = RandomUtil.getInstance().nextUniform(0, 1);
            } else {
                p[i] = RandomUtil.getInstance().nextUniform(-1, 1);
            }/*from   w  w  w  .  j a  va 2  s. com*/
        }

        _sem2.setFreeParamValues(p);

        MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);
        PointValuePair pair = search.optimize(new InitialGuess(_sem2.getFreeParamValues()),
                new ObjectiveFunction(fittingFunction(semIm)), GoalType.MINIMIZE, new MaxEval(100000));

        double chisq = _sem2.getChiSquare();
        System.out.println("chisq = " + chisq);

        if (chisq < min) {
            min = chisq;
            point = pair.getPoint();
        }
    }

    System.arraycopy(point, 0, semIm.getFreeParamValues(), 0, point.length);
}

From source file:edu.cmu.tetrad.regression.LogisticRegression2.java

public void regress(int[] target, int numValues, double[][] regressors) {
    try {/*from  w ww.j  a v a2s  .co  m*/
        int numParams = regressors.length + 1;

        double[] coefficients = new double[(numValues - 1) * numParams];

        // Apparently this needs to be fairly loose.
        int tolerance = 250;
        MultivariateOptimizer search = new PowellOptimizer(tolerance, tolerance);

        PointValuePair pair = search.optimize(new InitialGuess(coefficients),
                new ObjectiveFunction(new FittingFunction(target, regressors)), GoalType.MAXIMIZE,
                new MaxEval(1000000));

        this.likelihood = pair.getValue();
    } catch (TooManyEvaluationsException e) {
        e.printStackTrace();
        this.likelihood = Double.NaN;
    }
}

From source file:edu.cmu.tetrad.search.Ling.java

private void optimizeNonGaussianity(final int rowIndex, final DoubleMatrix2D dataSetMatrix, final double[][] W,
        List<Mapping> allMappings) {
    final List<Mapping> mappings = mappingsForRow(rowIndex, allMappings);

    MultivariateFunction function = new MultivariateFunction() {
        public double value(double[] values) {
            for (int i = 0; i < values.length; i++) {
                Mapping mapping = mappings.get(i);
                W[mapping.getI()][mapping.getJ()] = values[i];
            }//from w  w  w .  ja  va 2  s .c om

            double v = ngFullData(rowIndex, dataSetMatrix, W);

            if (Double.isNaN(v))
                return 10000;

            return -(v);
        }
    };

    {
        double[] values = new double[mappings.size()];

        for (int k = 0; k < mappings.size(); k++) {
            Mapping mapping = mappings.get(k);
            values[k] = W[mapping.getI()][mapping.getJ()];
        }

        MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);

        PointValuePair pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function),
                GoalType.MINIMIZE, new MaxEval(100000));

        values = pair.getPoint();

        for (int k = 0; k < mappings.size(); k++) {
            Mapping mapping = mappings.get(k);
            W[mapping.getI()][mapping.getJ()] = values[k];
        }
    }

}

From source file:edu.cmu.tetrad.sem.GeneralizedSemEstimator.java

private double[] optimize(MultivariateFunction function, double[] values, int optimizer) {
    PointValuePair pair = null;/* w  w  w  .  j a va2s  .c o m*/

    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));
    }

    return pair.getPoint();
}

From source file:edu.cmu.tetrad.search.Mimbuild2.java

private void optimizeNonMeasureVariancesQuick(Node[][] indicators, TetradMatrix measurescov,
        TetradMatrix latentscov, double[][] loadings, int[][] indicatorIndices) {
    int count = 0;

    for (int i = 0; i < indicators.length; i++) {
        for (int j = i; j < indicators.length; j++) {
            count++;/*w ww . j a v  a  2s  . c  om*/
        }
    }

    for (int i = 0; i < indicators.length; i++) {
        for (int j = 0; j < indicators[i].length; j++) {
            count++;
        }
    }

    double[] values = new double[count];
    count = 0;

    for (int i = 0; i < indicators.length; i++) {
        for (int j = i; j < indicators.length; j++) {
            values[count++] = latentscov.get(i, j);
        }
    }

    for (int i = 0; i < indicators.length; i++) {
        for (int j = 0; j < indicators[i].length; j++) {
            values[count++] = loadings[i][j];
        }
    }

    Function1 function1 = new Function1(indicatorIndices, measurescov, loadings, latentscov, count);
    MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);

    PointValuePair pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function1),
            GoalType.MINIMIZE, new MaxEval(100000));

    minimum = pair.getValue();
}

From source file:edu.cmu.tetrad.search.Mimbuild2.java

private void optimizeNonMeasureVariancesConditionally(Node[][] indicators, TetradMatrix measurescov,
        TetradMatrix latentscov, double[][] loadings, int[][] indicatorIndices, double[] delta) {
    int count = 0;

    for (int i = 0; i < indicators.length; i++) {
        for (int j = i; j < indicators.length; j++) {
            count++;//from   w  w  w.j a v  a  2  s  .  c  om
        }
    }

    for (int i = 0; i < indicators.length; i++) {
        for (int j = 0; j < indicators[i].length; j++) {
            count++;
        }
    }

    double[] values3 = new double[count];
    count = 0;

    for (int i = 0; i < indicators.length; i++) {
        for (int j = i; j < indicators.length; j++) {
            values3[count] = latentscov.get(i, j);
            count++;
        }
    }

    for (int i = 0; i < indicators.length; i++) {
        for (int j = 0; j < indicators[i].length; j++) {
            values3[count] = loadings[i][j];
            count++;
        }
    }

    Function2 function2 = new Function2(indicatorIndices, measurescov, loadings, latentscov, delta, count);
    MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);

    PointValuePair pair = search.optimize(new InitialGuess(values3), new ObjectiveFunction(function2),
            GoalType.MINIMIZE, new MaxEval(100000));

    minimum = pair.getValue();
}

From source file:edu.cmu.tetrad.search.Mimbuild2.java

private void optimizeMeasureVariancesConditionally(TetradMatrix measurescov, TetradMatrix latentscov,
        double[][] loadings, int[][] indicatorIndices, double[] delta) {
    double[] values2 = new double[delta.length];
    int count = 0;

    for (int i = 0; i < delta.length; i++) {
        values2[count++] = delta[i];/*from   w  ww .ja v a 2s.  c  o m*/
    }

    Function2 function2 = new Function2(indicatorIndices, measurescov, loadings, latentscov, delta, count);
    MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);

    PointValuePair pair = search.optimize(new InitialGuess(values2), new ObjectiveFunction(function2),
            GoalType.MINIMIZE, new MaxEval(100000));

    minimum = pair.getValue();
}