本文整理汇总了Java中org.apache.commons.math3.optim.PointValuePair类的典型用法代码示例。如果您正苦于以下问题:Java PointValuePair类的具体用法?Java PointValuePair怎么用?Java PointValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PointValuePair类属于org.apache.commons.math3.optim包,在下文中一共展示了PointValuePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: solve
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
public void solve(ActionEvent actionEvent) {
disableControls();
try{
solver=new SimplexSolver(1e-6);
LinearObjectiveFunction function=setObjective();
Collection<LinearConstraint> constraints=setConstrains();
PointValuePair result = solver.optimize(new MaxIter(1000000),function,new LinearConstraintSet(constraints), GoalType.MINIMIZE,new NonNegativeConstraint(true));
retrieveResults(result);
}catch(Exception e)
{
Alert alert=new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Optimization failed due to error");
alert.setContentText(e.getMessage());
alert.showAndWait();
e.printStackTrace();
}
enableControls();
}
示例3: 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));
}
示例4: findOptimum
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
@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;
}
示例5: solve
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
@Override
public void solve(double[] dir)
{
/* Check the dimension of the vectorspace where lives dir */
if (dir.length != d)
throw new LinearProgrammingSolverException(dddirMessage);
/* Update the constraints set of the simplex solver if modification */
if (lcListModified)
{
List <LinearConstraint> lcList = new ArrayList <LinearConstraint>();
int n = dirList.size();
for (int i = 0 ; i < n ; i++) lcList.add(new LinearConstraint(dirList.get(i), Relationship.LEQ, valList.get(i)));
lcSet = new LinearConstraintSet(lcList);
}
/* Evaluation */
PointValuePair res = solver.optimize(new LinearObjectiveFunction(dir, 0), lcSet, GoalType.MAXIMIZE);
/* Update the results and the flags */
point = res.getPoint ();
value = res.getSecond ();
evaluated = true;
lcListModified = false;
}
示例6: iteration
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
private PointValuePair iteration(final PointValuePair init) {
PointValuePair result = init;
if (bounds != null) {
result = select("CM", cmaes(init.getFirst(), 10), result);
}
result = select("NM", nelderMead(init.getFirst()), result);
if (ADDITIONAL_OPTIMIZERS) {
result = select("MD", multiDirection(init.getFirst()), result);
result = select("PO", powell(init.getFirst()), result);
try {
result = select("BO", bobyqa(init.getFirst()), result);
} catch (final Exception e) {
logger.error("{}", e);
}
}
return result;
}
示例7: NonLinearConjugateGradientOptimizer
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* @param updateFormula formula to use for updating the β parameter,
* must be one of {@link Formula#FLETCHER_REEVES} or
* {@link Formula#POLAK_RIBIERE}.
* @param checker Convergence checker.
* @param preconditioner Preconditioner.
* @param relativeTolerance Relative threshold for line search.
* @param absoluteTolerance Absolute threshold for line search.
* @param initialBracketingRange Extent of the initial interval used to
* find an interval that brackets the optimum in order to perform the
* line search.
*
* @see LineSearch#LineSearch(MultivariateOptimizer,double,double,double)
* @since 3.3
*/
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
ConvergenceChecker<PointValuePair> checker,
double relativeTolerance,
double absoluteTolerance,
double initialBracketingRange,
final Preconditioner preconditioner) {
super(checker);
this.updateFormula = updateFormula;
this.preconditioner = preconditioner;
line = new LineSearch(this,
relativeTolerance,
absoluteTolerance,
initialBracketingRange);
}
示例8: 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);
}
};
}
示例9: doOptimize
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected PointValuePair doOptimize() {
final double[] lowerBound = getLowerBound();
final double[] upperBound = getUpperBound();
// Validity checks.
setup(lowerBound, upperBound);
isMinimize = (getGoalType() == GoalType.MINIMIZE);
currentBest = new ArrayRealVector(getStartPoint());
final double value = bobyqa(lowerBound, upperBound);
return new PointValuePair(currentBest.getDataRef(),
isMinimize ? value : -value);
}
示例10: build
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* Build an initial simplex.
*
* @param startPoint First point of the simplex.
* @throws DimensionMismatchException if the start point does not match
* simplex dimension.
*/
public void build(final double[] startPoint) {
if (dimension != startPoint.length) {
throw new DimensionMismatchException(dimension, startPoint.length);
}
// Set first vertex.
simplex = new PointValuePair[dimension + 1];
simplex[0] = new PointValuePair(startPoint, Double.NaN);
// Set remaining vertices.
for (int i = 0; i < dimension; i++) {
final double[] confI = startConfiguration[i];
final double[] vertexI = new double[dimension];
for (int k = 0; k < dimension; k++) {
vertexI[k] = startPoint[k] + confI[k];
}
simplex[i + 1] = new PointValuePair(vertexI, Double.NaN);
}
}
示例11: evaluateNewSimplex
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* Compute and evaluate a new simplex.
*
* @param evaluationFunction Evaluation function.
* @param original Original simplex (to be preserved).
* @param coeff Linear coefficient.
* @param comparator Comparator to use to sort simplex vertices from best
* to poorest.
* @return the best point in the transformed simplex.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the maximal number of evaluations is exceeded.
*/
private PointValuePair evaluateNewSimplex(final MultivariateFunction evaluationFunction,
final PointValuePair[] original,
final double coeff,
final Comparator<PointValuePair> comparator) {
final double[] xSmallest = original[0].getPointRef();
// Perform a linear transformation on all the simplex points,
// except the first one.
setPoint(0, original[0]);
final int dim = getDimension();
for (int i = 1; i < getSize(); i++) {
final double[] xOriginal = original[i].getPointRef();
final double[] xTransformed = new double[dim];
for (int j = 0; j < dim; j++) {
xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
}
setPoint(i, new PointValuePair(xTransformed, Double.NaN, false));
}
// Evaluate the simplex.
evaluate(evaluationFunction, comparator);
return getPoint(0);
}
示例12: PowellOptimizer
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* This constructor allows to specify a user-defined convergence checker,
* in addition to the parameters that control the default convergence
* checking procedure and the line search tolerances.
*
* @param rel Relative threshold for this optimizer.
* @param abs Absolute threshold for this optimizer.
* @param lineRel Relative threshold for the internal line search optimizer.
* @param lineAbs Absolute threshold for the internal line search optimizer.
* @param checker Convergence checker.
* @throws NotStrictlyPositiveException if {@code abs <= 0}.
* @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
*/
public PowellOptimizer(double rel,
double abs,
double lineRel,
double lineAbs,
ConvergenceChecker<PointValuePair> checker) {
super(checker);
if (rel < MIN_RELATIVE_TOLERANCE) {
throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
}
if (abs <= 0) {
throw new NotStrictlyPositiveException(abs);
}
relativeThreshold = rel;
absoluteThreshold = abs;
// Create the line search optimizer.
line = new LineSearch(this,
lineRel,
lineAbs,
1d);
}
示例13: CMAESOptimizer
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* @param maxIterations Maximal number of iterations.
* @param stopFitness Whether to stop if objective function value is smaller than
* {@code stopFitness}.
* @param isActiveCMA Chooses the covariance matrix update method.
* @param diagonalOnly Number of initial iterations, where the covariance matrix
* remains diagonal.
* @param checkFeasableCount Determines how often new random objective variables are
* generated in case they are out of bounds.
* @param random Random generator.
* @param generateStatistics Whether statistic data is collected.
* @param checker Convergence checker.
*
* @since 3.1
*/
public CMAESOptimizer(int maxIterations,
double stopFitness,
boolean isActiveCMA,
int diagonalOnly,
int checkFeasableCount,
RandomGenerator random,
boolean generateStatistics,
ConvergenceChecker<PointValuePair> checker) {
super(checker);
this.maxIterations = maxIterations;
this.stopFitness = stopFitness;
this.isActiveCMA = isActiveCMA;
this.diagonalOnly = diagonalOnly;
this.checkFeasableCount = checkFeasableCount;
this.random = random;
this.generateStatistics = generateStatistics;
}
示例14: optimize
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
/**
* Optimizes parameters using the Nelder-Mead Method
* @param initialGuess initial guess / state required for Nelder-Mead-Method
* @param costFunction which defines that the Mean Squared Error has to be minimized
* @return the optimized values
*/
private static double[] optimize(double[] initialGuess, MultivariateFunctionMappingAdapter costFunction) {
double[] result;
SimplexOptimizer optimizer = new SimplexOptimizer(simplexRelativeThreshold, simplexAbsoluteThreshold);
PointValuePair unBoundedResult = optimizer.optimize(
GoalType.MINIMIZE,
new MaxIter(MAX_ALLOWED_NUMBER_OF_ITERATION),
new MaxEval(MAX_ALLOWED_NUMBER_OF_EVALUATION),
new InitialGuess(initialGuess),
new ObjectiveFunction(costFunction),
new NelderMeadSimplex(initialGuess.length));
result = costFunction.unboundedToBounded(unBoundedResult.getPoint());
return result;
}
示例15: testMath828Cycle
import org.apache.commons.math3.optim.PointValuePair; //导入依赖的package包/类
@Test
public void testMath828Cycle() {
LinearObjectiveFunction f = new LinearObjectiveFunction(
new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 0.0);
ArrayList <LinearConstraint>constraints = new ArrayList<LinearConstraint>();
constraints.add(new LinearConstraint(new double[] {0.0, 16.0, 14.0, 69.0, 1.0, 85.0, 52.0, 43.0, 64.0, 97.0, 14.0, 74.0, 89.0, 28.0, 94.0, 58.0, 13.0, 22.0, 21.0, 17.0, 30.0, 25.0, 1.0, 59.0, 91.0, 78.0, 12.0, 74.0, 56.0, 3.0, 88.0,}, Relationship.GEQ, 91.0));
constraints.add(new LinearConstraint(new double[] {0.0, 60.0, 40.0, 81.0, 71.0, 72.0, 46.0, 45.0, 38.0, 48.0, 40.0, 17.0, 33.0, 85.0, 64.0, 32.0, 84.0, 3.0, 54.0, 44.0, 71.0, 67.0, 90.0, 95.0, 54.0, 99.0, 99.0, 29.0, 52.0, 98.0, 9.0,}, Relationship.GEQ, 54.0));
constraints.add(new LinearConstraint(new double[] {0.0, 41.0, 12.0, 86.0, 90.0, 61.0, 31.0, 41.0, 23.0, 89.0, 17.0, 74.0, 44.0, 27.0, 16.0, 47.0, 80.0, 32.0, 11.0, 56.0, 68.0, 82.0, 11.0, 62.0, 62.0, 53.0, 39.0, 16.0, 48.0, 1.0, 63.0,}, Relationship.GEQ, 62.0));
constraints.add(new LinearConstraint(new double[] {83.0, -76.0, -94.0, -19.0, -15.0, -70.0, -72.0, -57.0, -63.0, -65.0, -22.0, -94.0, -22.0, -88.0, -86.0, -89.0, -72.0, -16.0, -80.0, -49.0, -70.0, -93.0, -95.0, -17.0, -83.0, -97.0, -31.0, -47.0, -31.0, -13.0, -23.0,}, Relationship.GEQ, 0.0));
constraints.add(new LinearConstraint(new double[] {41.0, -96.0, -41.0, -48.0, -70.0, -43.0, -43.0, -43.0, -97.0, -37.0, -85.0, -70.0, -45.0, -67.0, -87.0, -69.0, -94.0, -54.0, -54.0, -92.0, -79.0, -10.0, -35.0, -20.0, -41.0, -41.0, -65.0, -25.0, -12.0, -8.0, -46.0,}, Relationship.GEQ, 0.0));
constraints.add(new LinearConstraint(new double[] {27.0, -42.0, -65.0, -49.0, -53.0, -42.0, -17.0, -2.0, -61.0, -31.0, -76.0, -47.0, -8.0, -93.0, -86.0, -62.0, -65.0, -63.0, -22.0, -43.0, -27.0, -23.0, -32.0, -74.0, -27.0, -63.0, -47.0, -78.0, -29.0, -95.0, -73.0,}, Relationship.GEQ, 0.0));
constraints.add(new LinearConstraint(new double[] {15.0, -46.0, -41.0, -83.0, -98.0, -99.0, -21.0, -35.0, -7.0, -14.0, -80.0, -63.0, -18.0, -42.0, -5.0, -34.0, -56.0, -70.0, -16.0, -18.0, -74.0, -61.0, -47.0, -41.0, -15.0, -79.0, -18.0, -47.0, -88.0, -68.0, -55.0,}, Relationship.GEQ, 0.0));
double epsilon = 1e-6;
PointValuePair solution = new SimplexSolver().optimize(DEFAULT_MAX_ITER, f,
new LinearConstraintSet(constraints),
GoalType.MINIMIZE, new NonNegativeConstraint(true),
PivotSelectionRule.BLAND);
Assert.assertEquals(1.0d, solution.getValue(), epsilon);
Assert.assertTrue(validSolution(solution, constraints, epsilon));
}