Example usage for org.apache.commons.math3.optim MaxEval MaxEval

List of usage examples for org.apache.commons.math3.optim MaxEval MaxEval

Introduction

In this page you can find the example usage for org.apache.commons.math3.optim MaxEval MaxEval.

Prototype

public MaxEval(int max) 

Source Link

Usage

From source file:de.tuberlin.uebb.jdae.solvers.OptimalitySolver.java

@Override
public double[] solve(int maxEval, MultivariateDifferentiableVectorFunction f, double[] startValue) {
    final double[] zeros = startValue.clone();
    final double[] ones = startValue.clone();
    Arrays.fill(zeros, 0.0);//from ww  w  .j ava 2 s  .c  o m
    Arrays.fill(ones, 1.0);

    return optim.optimize(new MaxEval(maxEval), new InitialGuess(startValue), new Target(zeros),
            new Weight(ones), new ModelFunction(f), new ModelFunctionJacobian(new JacobianFunction(f)))
            .getPoint();
}

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: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: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 ww w  . ja va  2  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:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApacheAmoeba.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.5 * SIMPLEX_EDGE);
    //Arrays.fill(startingVertex, -1 * SIMPLEX_EDGE);

    // TODO if there are convergence issues, change these guessed thresholds
    //SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30); 
    //SimplexOptimizer optimizer = new SimplexOptimizer(1e-4, 1e-4); 
    //SimplexOptimizer optimizer = new SimplexOptimizer(1e-2, 10); 
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-3, 5);
    //SimplexOptimizer optimizer = new SimplexOptimizer(1e-2, 5); 

    final PointValuePair optimum = optimizer.optimize(new MaxEval(numEval),
            new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)),
            GoalType.MAXIMIZE, new InitialGuess(startingVertex),
            //new NelderMeadSimplex(NUM_RATES, -1 * SIMPLEX_EDGE)); 
            new NelderMeadSimplex(NUM_RATES, SIMPLEX_EDGE));// should be positive since this reflects decrease in (negative) charges

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

From source file:de.tuberlin.uebb.jdae.solvers.OptimalitySolver.java

public double[] solve(int maxEval, MultivariateVectorFunction residual, MultivariateMatrixFunction jacobian,
        double[] startValue) {
    final double[] zeros = startValue.clone();
    final double[] ones = startValue.clone();
    Arrays.fill(zeros, 0.0);//from w  w  w  .  ja  v a  2 s .co m
    Arrays.fill(ones, 1.0);

    return optim.optimize(new MaxEval(maxEval), new InitialGuess(startValue), new Target(zeros),
            new Weight(ones), new ModelFunction(residual), new ModelFunctionJacobian(jacobian)).getPoint();
}

From source file:com.google.cloud.genomics.dataflow.functions.verifybamid.Solver.java

/**
 * Maximizes a univariate function using a grid search followed by Brent's algorithm.
 *
 * @param fn the likelihood function to minimize
 * @param gridStart the lower bound for the grid search
 * @param gridEnd the upper bound for the grid search
 * @param gridStep step size for the grid search
 * @param relErr relative error tolerance for Brent's algorithm
 * @param absErr absolute error tolerance for Brent's algorithm
 * @param maxIter maximum # of iterations to perform in Brent's algorithm
 * @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm
 *
 * @return the value of the parameter that maximizes the function
 *//*ww  w  . ja  v a 2 s  . c  o  m*/
public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd, double gridStep,
        double relErr, double absErr, int maxIter, int maxEval) {
    Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep);
    BrentOptimizer bo = new BrentOptimizer(relErr, absErr);
    UnivariatePointValuePair max = bo.optimize(new MaxIter(maxIter), new MaxEval(maxEval),
            new SearchInterval(interval.getInf(), interval.getSup()), new UnivariateObjectiveFunction(fn),
            GoalType.MAXIMIZE);
    return max.getPoint();
}