本文整理汇总了Java中org.apache.commons.math3.optim.MaxIter类的典型用法代码示例。如果您正苦于以下问题:Java MaxIter类的具体用法?Java MaxIter怎么用?Java MaxIter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MaxIter类属于org.apache.commons.math3.optim包,在下文中一共展示了MaxIter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import org.apache.commons.math3.optim.MaxIter; //导入依赖的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();
}
示例2: optimize
import org.apache.commons.math3.optim.MaxIter; //导入依赖的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;
}
示例3: optimize
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
private PointValuePair optimize(final MultivariateOptimizer optimizer, final double[] initialValues,
final OptimizationData... data) {
final OptimizationData[] d = new OptimizationData[5 + data.length];
d[0] = new MaxIter(convergence.maxIt + 1);
d[1] = new MaxEval(convergence.maxIt * 2);
d[2] = new ObjectiveFunction(this);
d[3] = GoalType.MAXIMIZE;
d[4] = new InitialGuess(fixBounds(initialValues));
for (int i = 0; i < data.length; ++i) {
d[5 + i] = data[i];
}
return optimizer.optimize(d);
}
示例4: testMath930
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
@Test
public void testMath930() {
Collection<LinearConstraint> constraints = createMath930Constraints();
double[] objFunctionCoeff = new double[33];
objFunctionCoeff[3] = 1;
LinearObjectiveFunction f = new LinearObjectiveFunction(objFunctionCoeff, 0);
SimplexSolver solver = new SimplexSolver(1e-4, 10, 1e-6);
PointValuePair solution = solver.optimize(new MaxIter(1000), f, new LinearConstraintSet(constraints),
GoalType.MINIMIZE, new NonNegativeConstraint(true));
Assert.assertEquals(0.3752298, solution.getValue(), 1e-4);
}
示例5: testSolutionCallback
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
@Test
public void testSolutionCallback() {
// re-use the problem from testcase for MATH-288
// it normally requires 5 iterations
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 7, 3, 0, 0 }, 0 );
List<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
constraints.add(new LinearConstraint(new double[] { 3, 0, -5, 0 }, Relationship.LEQ, 0.0));
constraints.add(new LinearConstraint(new double[] { 2, 0, 0, -5 }, Relationship.LEQ, 0.0));
constraints.add(new LinearConstraint(new double[] { 0, 3, 0, -5 }, Relationship.LEQ, 0.0));
constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0 }, Relationship.LEQ, 1.0));
constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0 }, Relationship.LEQ, 1.0));
final SimplexSolver solver = new SimplexSolver();
final SolutionCallback callback = new SolutionCallback();
Assert.assertNull(callback.getSolution());
Assert.assertFalse(callback.isSolutionOptimal());
try {
solver.optimize(new MaxIter(3), f, new LinearConstraintSet(constraints),
GoalType.MAXIMIZE, new NonNegativeConstraint(true), callback);
Assert.fail("expected TooManyIterationsException");
} catch (TooManyIterationsException ex) {
// expected
}
final PointValuePair solution = callback.getSolution();
Assert.assertNotNull(solution);
Assert.assertTrue(validSolution(solution, constraints, 1e-4));
Assert.assertFalse(callback.isSolutionOptimal());
// the solution is clearly not optimal: optimal = 10.0
Assert.assertEquals(7.0, solution.getValue(), 1e-4);
}
示例6: computeFitnessValue
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
private void computeFitnessValue()
{
fitnessValueSolution = new SimplexSolver()
.optimize(new MaxIter(500),
f,
new LinearConstraintSet(getConstraints()),
GoalType.MINIMIZE,
new NonNegativeConstraint(true));
}
开发者ID:Polytech-AdrienCastex,项目名称:2D-Cutting-Stock-Problem-with-Setup-Cost,代码行数:10,代码来源:Solution.java
示例7: simplexDouble
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
/**
*
* @param A ресурсы на выпуск всех товаров (юнитов) [номер ресурса][номер юнита]
* @param b предел ресурсов (ограничение)
* @param c выгода
* @param x out кол-во выпуска (план выпуска, ответ)
* @return суммарная выгода плана x
*/
public static double simplexDouble(double[][] A, double[] b, double[] c, double[] x) {
// return justOneMaximize(A,b,c, x); // maybe fast, but not precission
// - - -
LinearObjectiveFunction f = new LinearObjectiveFunction(c, 0); // !!!
ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
for(int i=0; i<A.length; i++) { // Ограничения
constraints.add( new LinearConstraint(A[i], Relationship.LEQ, b[i]) ); // _c[i]*x[i]<=V_Res[i]
double[] zeroV = new double[A[i].length];
Arrays.fill(zeroV, 0);
constraints.add( new LinearConstraint(zeroV, Relationship.GEQ, 0) ); // _c[i]*x[i]<=V_Res[i]
}
// TODO при переработке энергии в металл можно учесть с помощью двух переменных и ограничения!!!
// FIXME precission - do not use between 0.00001 and 1.0, only 1,2,3...
SimplexSolver solver = new SimplexSolver();
PointValuePair optSolution = solver.optimize(new MaxIter(1000), f,
new LinearConstraintSet(constraints),
GoalType.MAXIMIZE,
new NonNegativeConstraint(true));
//double[] solution = optSolution.getPoint();
double[] x_=optSolution.getPointRef(); // TODO it is bad fix for n*1.0. To do iteration.
for (int i=0;i<x_.length;i++) if (x_[i]>0) x_[i]=Math.round(x_[i]-0.5);
System.arraycopy(x_, 0, x, 0, x.length);
return optSolution.getValue();
// - - -
}
示例8: optimize
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
@Override
public Result optimize(int nParameterSpace, int nOptimizations, boolean stopWhenSuccessful,
Map<String, Double> minStartValues, Map<String, Double> maxStartValues, int maxIterations,
DoubleConsumer progessListener, ExecutionContext exec) throws CanceledExecutionException {
if (exec != null) {
exec.checkCanceled();
}
progessListener.accept(0.0);
List<ParamRange> ranges = MathUtils.getParamRanges(parameters, minStartValues, maxStartValues, nParameterSpace);
ranges.set(parameters.indexOf(sdParam), new ParamRange(1.0, 1, 1.0));
List<StartValues> startValuesList = MathUtils.createStartValuesList(ranges, nOptimizations,
values -> optimizerFunction.value(Doubles.toArray(values)),
progress -> progessListener.accept(0.5 * progress), exec);
Result result = new Result();
AtomicInteger currentIteration = new AtomicInteger();
SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-10, 1e-10) {
@Override
public boolean converged(int iteration, PointValuePair previous, PointValuePair current) {
if (super.converged(iteration, previous, current)) {
return true;
}
return currentIteration.incrementAndGet() >= maxIterations;
}
});
int count = 0;
for (StartValues startValues : startValuesList) {
if (exec != null) {
exec.checkCanceled();
}
progessListener.accept(0.5 * count++ / startValuesList.size() + 0.5);
try {
PointValuePair optimizerResults = optimizer.optimize(new MaxEval(Integer.MAX_VALUE),
new MaxIter(maxIterations), new InitialGuess(Doubles.toArray(startValues.getValues())),
new ObjectiveFunction(optimizerFunction), GoalType.MAXIMIZE,
new NelderMeadSimplex(parameters.size()));
double logLikelihood = optimizerResults.getValue() != null ? optimizerResults.getValue() : Double.NaN;
if (result.logLikelihood == null || logLikelihood > result.logLikelihood) {
result = getResults(optimizerResults);
if (result.logLikelihood == 0.0 || stopWhenSuccessful) {
break;
}
}
} catch (TooManyEvaluationsException | TooManyIterationsException | ConvergenceException e) {
}
}
return result;
}
示例9: maximize
import org.apache.commons.math3.optim.MaxIter; //导入依赖的package包/类
/**
* Maximizes a univariate function using a grid search followed by Brent's algorithm.
*
* @param fn the likelihood function to minimize
* @param gridStart the lower bound for the grid search
* @param gridEnd the upper bound for the grid search
* @param gridStep step size for the grid search
* @param relErr relative error tolerance for Brent's algorithm
* @param absErr absolute error tolerance for Brent's algorithm
* @param maxIter maximum # of iterations to perform in Brent's algorithm
* @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm
*
* @return the value of the parameter that maximizes the function
*/
public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd,
double gridStep, double relErr, double absErr, int maxIter, int maxEval) {
Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep);
BrentOptimizer bo = new BrentOptimizer(relErr, absErr);
UnivariatePointValuePair max = bo.optimize(
new MaxIter(maxIter),
new MaxEval(maxEval),
new SearchInterval(interval.getInf(), interval.getSup()),
new UnivariateObjectiveFunction(fn),
GoalType.MAXIMIZE);
return max.getPoint();
}