本文整理汇总了Java中org.apache.commons.math3.optim.nonlinear.scalar.GoalType类的典型用法代码示例。如果您正苦于以下问题:Java GoalType类的具体用法?Java GoalType怎么用?Java GoalType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GoalType类属于org.apache.commons.math3.optim.nonlinear.scalar包,在下文中一共展示了GoalType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyToNetwork
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的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.nonlinear.scalar.GoalType; //导入依赖的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: optimizeUni
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
public double optimizeUni() throws Exception {
double maxLh=0;
BrentOptimizer optimizer = new BrentOptimizer(1e-6, 1e-12);
UnivariatePointValuePair optimum =
optimizer.optimize(new UnivariateObjectiveFunction(this),
new MaxEval(100),
GoalType.MAXIMIZE,
new SearchInterval(pfBoundsLower[0],pfBoundsUpper[0]));
//double point = optimum.getPoint();
//System.out.print("--> "+paramName+": "+paramValue+" point= "+point);
//System.out.print(" ");
//System.out.println("value = "+ optimum.getValue());
maxLh = optimum.getValue();
optPoint[0] = optimum.getPoint();
return maxLh;
}
示例4: findOptimum
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的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.nonlinear.scalar.GoalType; //导入依赖的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: parseOptimizationData
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
/**
* Scans the list of (required and optional) optimization data that
* characterize the problem.
*
* @param optData Optimization data.
* The following data will be looked for:
* <ul>
* <li>{@link GoalType}</li>
* <li>{@link SearchInterval}</li>
* <li>{@link UnivariateObjectiveFunction}</li>
* </ul>
*/
@Override
protected void parseOptimizationData(OptimizationData... optData) {
// Allow base class to register its own data.
super.parseOptimizationData(optData);
// The existing values (as set by the previous call) are reused if
// not provided in the argument list.
for (OptimizationData data : optData) {
if (data instanceof SearchInterval) {
final SearchInterval interval = (SearchInterval) data;
min = interval.getMin();
max = interval.getMax();
start = interval.getStartValue();
continue;
}
if (data instanceof UnivariateObjectiveFunction) {
function = ((UnivariateObjectiveFunction) data).getObjectiveFunction();
continue;
}
if (data instanceof GoalType) {
goal = (GoalType) data;
continue;
}
}
}
示例7: sortPairs
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
/**
* Sort the optima from best to worst, followed by {@code null} elements.
*
* @param goal Goal type.
*/
private void sortPairs(final GoalType goal) {
Arrays.sort(optima, new Comparator<UnivariatePointValuePair>() {
/** {@inheritDoc} */
public int compare(final UnivariatePointValuePair o1,
final UnivariatePointValuePair 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 (goal == GoalType.MINIMIZE) ?
Double.compare(v1, v2) : Double.compare(v2, v1);
}
});
}
示例8: doOptimize
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的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);
}
示例9: SimplexTableau
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
/**
* Build a tableau for a linear problem.
* @param f linear objective function
* @param constraints linear constraints
* @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}
* @param restrictToNonNegative whether to restrict the variables to non-negative values
* @param epsilon amount of error to accept when checking for optimality
* @param maxUlps amount of error to accept in floating point comparisons
*/
SimplexTableau(final LinearObjectiveFunction f,
final Collection<LinearConstraint> constraints,
final GoalType goalType,
final boolean restrictToNonNegative,
final double epsilon,
final int maxUlps) {
this.f = f;
this.constraints = normalizeConstraints(constraints);
this.restrictToNonNegative = restrictToNonNegative;
this.epsilon = epsilon;
this.maxUlps = maxUlps;
this.numDecisionVariables = f.getCoefficients().getDimension() + (restrictToNonNegative ? 0 : 1);
this.numSlackVariables = getConstraintTypeCounts(Relationship.LEQ) +
getConstraintTypeCounts(Relationship.GEQ);
this.numArtificialVariables = getConstraintTypeCounts(Relationship.EQ) +
getConstraintTypeCounts(Relationship.GEQ);
this.tableau = createTableau(goalType == GoalType.MAXIMIZE);
// initialize the basic variables for phase 1:
// we know that only slack or artificial variables can be basic
initializeBasicVariables(getSlackVariableOffset());
initializeColumnLabels();
}
示例10: optimize
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的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;
}
示例11: optimize
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
/**
* Optimizes the circuit to the given ys vector
*
* @param ys
* complex scattering parameters to which the model is optimized
*/
public void optimize(Complex[] ys) {
// shorten parameters to optimize
shortParameters = MCUtil.shortenParam(circuitType, parameters);
errorFunction = new MCErrorSum(ys, this);
optimum = null;
try {
optimum = optimizer.optimize(new MaxEval(10000), new ObjectiveFunction(errorFunction), GoalType.MINIMIZE,
new InitialGuess(shortParameters), new NelderMeadSimplex(optStep));
parameters = MCUtil.topo2Param(circuitType, optimum.getPoint());
} catch (TooManyEvaluationsException ex) {
// This exception can be ignored. If max eval is reached, the recent
// parameters are stored
// and no null pointer can appear
parameters = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
}
// save new parameters
}
示例12: sortPairs
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
/**
* Sort the optima from best to worst, followed by {@code null} elements.
*
* @param goal Goal type.
*/
private void sortPairs(final GoalType goal) {
Arrays.sort(optima, new Comparator<UnivariatePointValuePair>() {
public int compare(final UnivariatePointValuePair o1,
final UnivariatePointValuePair 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 (goal == GoalType.MINIMIZE) ?
Double.compare(v1, v2) : Double.compare(v2, v1);
}
});
}
示例13: testCubicMax
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
@Test
public void testCubicMax() {
final BracketFinder bFind = new BracketFinder();
final UnivariateFunction func = new UnivariateFunction() {
public double value(double x) {
if (x < -2) {
return value(-2);
}
else {
return -(x - 1) * (x + 2) * (x + 3);
}
}
};
bFind.search(func, GoalType.MAXIMIZE, -2 , -1);
final double tol = 1e-15;
Assert.assertEquals(-2, bFind.getLo(), tol);
Assert.assertEquals(-1, bFind.getMid(), tol);
Assert.assertEquals(0.61803399999999997, bFind.getHi(), tol);
}
示例14: testMinimumIsOnIntervalBoundary
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
@Test
public void testMinimumIsOnIntervalBoundary() {
final UnivariateFunction func = new UnivariateFunction() {
public double value(double x) {
return x * x;
}
};
final BracketFinder bFind = new BracketFinder();
bFind.search(func, GoalType.MINIMIZE, 0, 1);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
bFind.search(func, GoalType.MINIMIZE, -1, 0);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
}
示例15: testIntervalBoundsOrdering
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; //导入依赖的package包/类
@Test
public void testIntervalBoundsOrdering() {
final UnivariateFunction func = new UnivariateFunction() {
public double value(double x) {
return x * x;
}
};
final BracketFinder bFind = new BracketFinder();
bFind.search(func, GoalType.MINIMIZE, -1, 1);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
bFind.search(func, GoalType.MINIMIZE, 1, -1);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
bFind.search(func, GoalType.MINIMIZE, 1, 2);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
bFind.search(func, GoalType.MINIMIZE, 2, 1);
Assert.assertTrue(bFind.getLo() <= 0);
Assert.assertTrue(0 <= bFind.getHi());
}