本文整理汇总了Java中org.apache.commons.math3.optim.PointValuePair.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java PointValuePair.getValue方法的具体用法?Java PointValuePair.getValue怎么用?Java PointValuePair.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.optim.PointValuePair
的用法示例。
在下文中一共展示了PointValuePair.getValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyToNetwork
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@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;
}
示例2: retrieveResults
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
private void retrieveResults(PointValuePair result) {
int rows=suppliers.getValue();
int cols=recipients.getValue();
if (excessCheckbox.isSelected())
cols++;
double[] data=result.getPoint();
for (int i = 0; i < rows; i++) {
setVectorElement(excess,i,0);
}
for (int i = 0; i < data.length; i++) {
int x=i%cols;
int y=i/cols;
if(x<recipients.getValue())
setMatrixElement(this.result,y,x,data[i]);
else
setVectorElement(this.excess,y,data[i]);
}
double value=result.getValue();
cost.setText(String.valueOf(value));
}
示例3: getPairComparator
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/**
* @return a comparator for sorting the optima.
*/
private Comparator<PointValuePair> getPairComparator() {
return new Comparator<PointValuePair>() {
/** {@inheritDoc} */
public int compare(final PointValuePair o1,
final PointValuePair o2) {
if (o1 == null) {
return (o2 == null) ? 0 : 1;
} else if (o2 == null) {
return -1;
}
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return (optimizer.getGoalType() == GoalType.MINIMIZE) ?
Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
}
示例4: getPairComparator
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/**
* @return a comparator for sorting the optima.
*/
private Comparator<PointValuePair> getPairComparator() {
return new Comparator<PointValuePair>() {
public int compare(final PointValuePair o1,
final PointValuePair o2) {
if (o1 == null) {
return (o2 == null) ? 0 : 1;
} else if (o2 == null) {
return -1;
}
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return (optimizer.getGoalType() == GoalType.MINIMIZE) ?
Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
}
示例5: testMath283
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Test
public void testMath283() {
// fails because MultiDirectional.iterateSimplex is looping forever
// the while(true) should be replaced with a convergence check
SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14);
final Gaussian2D function = new Gaussian2D(0, 0, 1);
PointValuePair estimate = optimizer.optimize(new MaxEval(1000),
new ObjectiveFunction(function),
GoalType.MAXIMIZE,
new InitialGuess(function.getMaximumPosition()),
new MultiDirectionalSimplex(2));
final double EPSILON = 1e-5;
final double expectedMaximum = function.getMaximum();
final double actualMaximum = estimate.getValue();
Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON);
final double[] expectedPosition = function.getMaximumPosition();
final double[] actualPosition = estimate.getPoint();
Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON );
Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON );
}
示例6: applyToNetwork
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@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.);
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;
}
示例7: select
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
private PointValuePair select(final String method, final PointValuePair newResult, final PointValuePair oldResult) {
if (newResult.getValue() < oldResult.getValue()
|| convergence.trainMax != null && newResult.getValue() > convergence.trainMax) {
log(method + " (rejc.)", newResult);
return oldResult;
}
log(method, newResult);
return newResult;
}
示例8: converged
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Override
public boolean converged(final int iteration, final PointValuePair previous, final PointValuePair current) {
if (++it >= maxIt) {
return true;
}
if (trainMax != null && current.getValue() >= trainMax) {
return true;
}
return super.converged(iteration, previous, current);
}
示例9: doOptimize
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
checkParameters();
// Indirect call to "computeObjectiveValue" in order to update the
// evaluations counter.
final MultivariateFunction evalFunc
= new MultivariateFunction() {
/** {@inheritDoc} */
public double value(double[] point) {
return computeObjectiveValue(point);
}
};
final boolean isMinim = getGoalType() == GoalType.MINIMIZE;
final Comparator<PointValuePair> comparator
= new Comparator<PointValuePair>() {
/** {@inheritDoc} */
public int compare(final PointValuePair o1,
final PointValuePair o2) {
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
// Initialize search.
simplex.build(getStartPoint());
simplex.evaluate(evalFunc, comparator);
PointValuePair[] previous = null;
int iteration = 0;
final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
while (true) {
if (getIterations() > 0) {
boolean converged = true;
for (int i = 0; i < simplex.getSize(); i++) {
PointValuePair prev = previous[i];
converged = converged &&
checker.converged(iteration, prev, simplex.getPoint(i));
}
if (converged) {
// We have found an optimum.
return simplex.getPoint(0);
}
}
// We still need to search.
previous = simplex.getPoints();
simplex.iterate(evalFunc, comparator);
incrementIterationCount();
}
}
示例10: doOptimize
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
checkParameters();
// Indirect call to "computeObjectiveValue" in order to update the
// evaluations counter.
final MultivariateFunction evalFunc
= new MultivariateFunction() {
public double value(double[] point) {
return computeObjectiveValue(point);
}
};
final boolean isMinim = getGoalType() == GoalType.MINIMIZE;
final Comparator<PointValuePair> comparator
= new Comparator<PointValuePair>() {
public int compare(final PointValuePair o1,
final PointValuePair o2) {
final double v1 = o1.getValue();
final double v2 = o2.getValue();
return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1);
}
};
// Initialize search.
simplex.build(getStartPoint());
simplex.evaluate(evalFunc, comparator);
PointValuePair[] previous = null;
int iteration = 0;
final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
while (true) {
if (getIterations() > 0) {
boolean converged = true;
for (int i = 0; i < simplex.getSize(); i++) {
PointValuePair prev = previous[i];
converged = converged &&
checker.converged(iteration, prev, simplex.getPoint(i));
}
if (converged) {
// We have found an optimum.
return simplex.getPoint(0);
}
}
// We still need to search.
previous = simplex.getPoints();
simplex.iterate(evalFunc, comparator);
incrementIterationCount();
}
}
示例11: solve
import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
public Optimisation.Result solve(final Result kickStarter) {
// final InitialGuess guess = new InitialGuess(kickStarter.toRawCopy1D());
//
// myModelData.add(guess);
Optimisation.State state = Optimisation.State.FAILED;
double value = Double.NaN;
Access1D<?> solution = kickStarter;
try {
final SimplexSolver solver = new SimplexSolver();
DEFAULT.configure(solver, myOptions);
final Optional<Configurator> optional = myOptions.getConfigurator(Configurator.class);
if (optional.isPresent()) {
optional.get().configure(solver, myOptions);
}
final PointValuePair solutionAndValue = solver.optimize(myModelData.toArray(new OptimizationData[myModelData.size()]));
state = Optimisation.State.OPTIMAL;
value = solutionAndValue.getValue();
solution = Access1D.wrap(solutionAndValue.getPoint());
} catch (final NoFeasibleSolutionException infeasible) {
state = Optimisation.State.INFEASIBLE;
} catch (final UnboundedSolutionException unbounded) {
state = Optimisation.State.UNBOUNDED;
}
final Optimisation.Result result = new Optimisation.Result(state, value, solution);
return result;
}