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

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

Introduction

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

Prototype

public InitialGuess(double[] startPoint) 

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   w  ww  .j av  a2 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  w  w w  .  j a  v  a  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: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 www . j  a  v a 2 s  .com
    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.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: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 ww w  .ja  v  a 2  s.  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;
}