Example usage for org.apache.commons.math3.optim.nonlinear.scalar GoalType MINIMIZE

List of usage examples for org.apache.commons.math3.optim.nonlinear.scalar GoalType MINIMIZE

Introduction

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

Prototype

GoalType MINIMIZE

To view the source code for org.apache.commons.math3.optim.nonlinear.scalar GoalType MINIMIZE.

Click Source Link

Document

Minimization.

Usage

From source file:edu.ucsf.valelab.saim.calculations.SaimErrorFunctionFitter.java

public double[] fit(Collection<WeightedObservedPoint> observedPoints) {
    SaimErrorFunction ser = new SaimErrorFunction(data_, observedPoints);
    MultivariateOptimizer optimizer = new BOBYQAOptimizer(6, 10, 1.0E-8);
    double[] lb = { 0.0, 0.0, 0.0 };
    double[] ub = { 64000, 64000, 1000 };
    SimpleBounds sb = new SimpleBounds(lb, ub);
    PointValuePair results = optimizer.optimize(new MaxEval(20000), GoalType.MINIMIZE, new InitialGuess(guess_),
            new ObjectiveFunction(ser), sb);
    System.out.println("Value: " + results.getValue());
    return results.getPoint();

}

From source file:eu.crisis_economics.abm.markets.clearing.heterogeneous.BoundedQuadraticEstimationClearingAlgorithm.java

@Override
public double applyToNetwork(final MixedClearingNetwork network) {
    Preconditions.checkNotNull(network);
    final int dimension = network.getNumberOfEdges();

    final ResidualCostFunction aggregateCostFunction = super.getResidualScalarCostFunction(network);
    final RealVector start = new ArrayRealVector(network.getNumberOfEdges());
    start.set(1.0); // Initial rate guess.

    final BOBYQAOptimizer optimizer = new BOBYQAOptimizer(2 * dimension + 1, 1.2, 1.e-8);
    final PointValuePair result = optimizer.optimize(new MaxEval(maximumEvaluations),
            new ObjectiveFunction(aggregateCostFunction), GoalType.MINIMIZE,
            new SimpleBounds(new double[dimension], ArrayUtil.ones(dimension)),
            new InitialGuess(start.toArray()));

    final double residualCost = result.getValue();
    System.out.println("Network cleared: residual cost: " + residualCost + ".");

    return residualCost;
}

From source file:com.itemanalysis.psychometrics.factoranalysis.MINRESmethod.java

public double estimateParameters() {
    MINRESObjectiveFunction objectiveFunction = new MINRESObjectiveFunction();

    optimizer = new NonLinearConjugateGradientOptimizer(
            NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-10, 1e-10),
            1e-4, 1e-4, 1);//from w w  w.j  ava2  s.c o m

    solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(),
            objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE,
            new InitialGuess(getStartValues()));

    computeFactorLoadings(solution.getPoint());
    return solution.getValue();
}

From source file:com.itemanalysis.psychometrics.factoranalysis.WeightedLeastSquaresMethod.java

public double estimateParameters() {

    Sinv = new LUDecomposition(R).getSolver().getInverse();

    WLSObjectiveFunction objectiveFunction = new WLSObjectiveFunction();

    optimizer = new NonLinearConjugateGradientOptimizer(
            NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8));

    solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(),
            objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE,
            new InitialGuess(getStartValues()));

    computeFactorLoadings(solution.getPoint());
    return solution.getValue();

}

From source file:com.itemanalysis.psychometrics.factoranalysis.GeneralizedLeastSquaresMethod.java

public double estimateParameters() {

    Sinv = new LUDecomposition(R).getSolver().getInverse();

    GLSObjectiveFunction objectiveFunction = new GLSObjectiveFunction();

    optimizer = new NonLinearConjugateGradientOptimizer(
            NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8));

    solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(),
            objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE,
            new InitialGuess(getStartValues()));

    computeFactorLoadings(solution.getPoint());
    return solution.getValue();

}

From source file:eu.crisis_economics.abm.markets.clearing.heterogeneous.NelderMeadClearingAlgorithm.java

@Override
public double applyToNetwork(final MixedClearingNetwork network) {
    Preconditions.checkNotNull(network);
    final SimplexOptimizer optimizer = new SimplexOptimizer(relErrorTarget, absErrorTarget);

    final ResidualCostFunction aggregateCostFunction = super.getResidualScalarCostFunction(network);
    final RealVector start = new ArrayRealVector(network.getNumberOfEdges());
    for (int i = 0; i < network.getNumberOfEdges(); ++i)
        start.setEntry(i, network.getEdges().get(i).getMaximumRateAdmissibleByBothParties());
    start.set(1.);//from   w  w w  . j  a  va  2s .co m

    final PointValuePair result = optimizer.optimize(new MaxEval(maximumEvaluations),
            new ObjectiveFunction(aggregateCostFunction), GoalType.MINIMIZE, new InitialGuess(start.toArray()),
            new NelderMeadSimplex(network.getNumberOfEdges()));

    final double residualCost = result.getValue();
    System.out.println("Network cleared: residual cost: " + residualCost + ".");

    return residualCost;
}

From source file:com.itemanalysis.psychometrics.factoranalysis.MaximumLikelihoodMethod.java

public double estimateParameters() {

    MLObjectiveFunction objectiveFunction = new MLObjectiveFunction();

    //        System.out.println("START VALUES: " + Arrays.toString(getStartValues()));

    optimizer = new NonLinearConjugateGradientOptimizer(
            NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8));

    solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(),
            objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE,
            new InitialGuess(getStartValues()));

    computeFactorLoadings(solution.getPoint());
    return solution.getValue();
}

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 {/* w w w  .ja v a 2  s.  c  o  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. j  a  va2  s. co 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  ww  w .  j  a  v a  2 s.co m
        }

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