List of usage examples for org.apache.commons.math3.optim.nonlinear.scalar.noderiv BOBYQAOptimizer BOBYQAOptimizer
public BOBYQAOptimizer(int numberOfInterpolationPoints, double initialTrustRegionRadius, double stoppingTrustRegionRadius)
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:edu.utexas.cs.tactex.tariffoptimization.OptimizerWrapperApacheBOBYQA.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); //Arrays.fill(startingVertex, 0.5 * INITIAL_TRUST_REGION_RADIUS); //Arrays.fill(startingVertex, 1 * INITIAL_TRUST_REGION_RADIUS); final int numIterpolationPoints = 2 * NUM_RATES + 1; // BOBYQA recommends 2n+1 points BOBYQAOptimizer optimizer = new BOBYQAOptimizer(numIterpolationPoints, INITIAL_TRUST_REGION_RADIUS, STOPPING_TRUST_REGION_RADIUS); // 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 OptimizerWrapperApacheObjective(tariffUtilityEstimate)), GoalType.MAXIMIZE, new InitialGuess(startingVertex), //new SimpleBounds(boundaries[0], boundaries[1])); SimpleBounds.unbounded(NUM_RATES)); TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>(); eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey())); return eval2TOUTariff; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair doSingleStart(BaseObjectiveFunction objective, double[] startPoint, int maxEvaluations, double[] nextStart) { singleRunEvaluations = 0;/*from ww w.j a va 2 s. com*/ PointValuePair result = null; try { int numVariables = objective.getNrDimensions(); if (numVariables > 1) // Use BOBYQA { double trustRegion = objective.getInitialTrustRegionRadius(nextStart); double stoppingTrustRegion = objective.getStoppingTrustRegionRadius(); BOBYQAOptimizer optimizer = new BOBYQAOptimizer(objective.getNrInterpolations(), trustRegion, stoppingTrustRegion); result = runBobyqa(optimizer, objective, nextStart, maxEvaluations); singleRunEvaluations = optimizer.getEvaluations(); } else // Use Brent { BrentOptimizer optimizer = new BrentOptimizer(1.e-6, 1.e-14); UnivariatePointValuePair outcome = runBrent(optimizer, objective, startPoint); result = new PointValuePair(new double[] { outcome.getPoint() }, outcome.getValue()); singleRunEvaluations = optimizer.getEvaluations(); } double value = result.getValue(); if (value == Double.POSITIVE_INFINITY) { System.out.print("no valid solution found"); } else { System.out.print("optimum " + result.getValue()); } } catch (TooManyEvaluationsException e) { System.out.println("Exception: " + e.getMessage()); } // Thrown by BOBYQA for no apparent reason: a bug? catch (NoSuchElementException e) { System.out.println("no valid solution found"); } catch (OperationCancelledException e) { // Restore starting point. objective.setGeometryPoint(startPoint); // Re-throw the exception to give up the whole multi-start // optimization. throw new OperationCancelledException(e.getMessage()); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); // e.printStackTrace(); } finally { System.out.println(" at start point " + Arrays.toString(nextStart)); } return result; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runBobyqa(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { double trustRegion = objective.getInitialTrustRegionRadius(startPoint); double stoppingTrustRegion = objective.getStoppingTrustRegionRadius(); BOBYQAOptimizer optimizer = new BOBYQAOptimizer(objective.getNrInterpolations(), trustRegion, stoppingTrustRegion);/*from w ww . j a v a2 s.c om*/ return runBobyqa(optimizer, objective, startPoint, objective.getMaxEvaluations()); }