本文整理汇总了Java中org.apache.commons.math3.optimization.GoalType类的典型用法代码示例。如果您正苦于以下问题:Java GoalType类的具体用法?Java GoalType怎么用?Java GoalType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GoalType类属于org.apache.commons.math3.optimization包,在下文中一共展示了GoalType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sortPairs
import org.apache.commons.math3.optimization.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);
}
});
}
开发者ID:biocompibens,项目名称:SME,代码行数:23,代码来源:UnivariateMultiStartOptimizer.java
示例2: optimize
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/** {@inheritDoc} */
public UnivariatePointValuePair optimize(int maxEval, UnivariateFunction f,
GoalType goalType,
double min, double max,
double startValue) {
// Checks.
if (f == null) {
throw new NullArgumentException();
}
if (goalType == null) {
throw new NullArgumentException();
}
// Reset.
searchMin = min;
searchMax = max;
searchStart = startValue;
goal = goalType;
function = f;
evaluations.setMaximalCount(maxEval);
evaluations.resetCount();
// Perform computation.
return doOptimize();
}
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:BaseAbstractUnivariateOptimizer.java
示例3: optimizeInternal
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/**
* Optimize an objective function.
*
* @param maxEval Allowed number of evaluations of the objective function.
* @param f Objective function.
* @param goalType Optimization type.
* @param optData Optimization data. The following data will be looked for:
* <ul>
* <li>{@link InitialGuess}</li>
* <li>{@link SimpleBounds}</li>
* </ul>
* @return the point/value pair giving the optimal value of the objective
* function.
* @throws TooManyEvaluationsException if the maximal number of
* evaluations is exceeded.
* @since 3.1
*/
protected PointValuePair optimizeInternal(int maxEval,
FUNC f,
GoalType goalType,
OptimizationData... optData)
throws TooManyEvaluationsException {
// Set internal state.
evaluations.setMaximalCount(maxEval);
evaluations.resetCount();
function = f;
goal = goalType;
// Retrieve other settings.
parseOptimizationData(optData);
// Check input consistency.
checkParameters();
// Perform computation.
return doOptimize();
}
开发者ID:biocompibens,项目名称:SME,代码行数:35,代码来源:BaseAbstractMultivariateOptimizer.java
示例4: doOptimize
import org.apache.commons.math3.optimization.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);
}
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:BOBYQAOptimizer.java
示例5: search
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p Starting point.
* @param d Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d) {
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = p[i] + alpha * d[i];
}
final double obj = PowellOptimizer.this.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = PowellOptimizer.this.getGoalType();
bracket.search(f, goal, 0, 1);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(Integer.MAX_VALUE, f, goal,
bracket.getLo(), bracket.getHi(), bracket.getMid());
}
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:PowellOptimizer.java
示例6: optimize
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/** {@inheritDoc} */
public PointValuePair optimize(final LinearObjectiveFunction f,
final Collection<LinearConstraint> constraints,
final GoalType goalType, final boolean restrictToNonNegative)
throws MathIllegalStateException {
// store linear problem characteristics
this.function = f;
this.linearConstraints = constraints;
this.goal = goalType;
this.nonNegative = restrictToNonNegative;
iterations = 0;
// solve the problem
return doOptimize();
}
开发者ID:biocompibens,项目名称:SME,代码行数:19,代码来源:AbstractLinearOptimizer.java
示例7: SimplexTableau
import org.apache.commons.math3.optimization.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);
initializeColumnLabels();
}
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:SimplexTableau.java
示例8: testStartSimplexInsideRange
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testStartSimplexInsideRange() {
final BiQuadratic biQuadratic = new BiQuadratic(2.0, 2.5, 1.0, 3.0, 2.0, 3.0);
final MultivariateFunctionPenaltyAdapter wrapped =
new MultivariateFunctionPenaltyAdapter(biQuadratic,
biQuadratic.getLower(),
biQuadratic.getUpper(),
1000.0, new double[] { 100.0, 100.0 });
SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));
final PointValuePair optimum
= optimizer.optimize(300, wrapped, GoalType.MINIMIZE, new double[] { 1.5, 2.25 });
Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7);
Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:MultivariateFunctionPenaltyAdapterTest.java
示例9: doTest
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/**
* @param func Function to optimize.
* @param startPoint Starting point.
* @param boundaries Upper / lower point limit.
* @param goal Minimization or maximization.
* @param fTol Tolerance relative error on the objective function.
* @param pointTol Tolerance for checking that the optimum is correct.
* @param maxEvaluations Maximum number of evaluations.
* @param expected Expected point / value.
*/
private void doTest(MultivariateFunction func,
double[] startPoint,
double[][] boundaries,
GoalType goal,
double fTol,
double pointTol,
int maxEvaluations,
PointValuePair expected) {
doTest(func,
startPoint,
boundaries,
goal,
fTol,
pointTol,
maxEvaluations,
0,
expected,
"");
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:30,代码来源:BOBYQAOptimizerTest.java
示例10: testHalfBounded
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testHalfBounded() {
final BiQuadratic biQuadratic = new BiQuadratic(4.0, 4.0,
1.0, Double.POSITIVE_INFINITY,
Double.NEGATIVE_INFINITY, 3.0);
final MultivariateFunctionPenaltyAdapter wrapped =
new MultivariateFunctionPenaltyAdapter(biQuadratic,
biQuadratic.getLower(),
biQuadratic.getUpper(),
1000.0, new double[] { 100.0, 100.0 });
SimplexOptimizer optimizer = new SimplexOptimizer(new SimplePointChecker<PointValuePair>(1.0e-10, 1.0e-20));
optimizer.setSimplex(new NelderMeadSimplex(new double[] { 1.0, 0.5 }));
final PointValuePair optimum
= optimizer.optimize(400, wrapped, GoalType.MINIMIZE, new double[] { -1.5, 4.0 });
Assert.assertEquals(biQuadratic.getBoundedXOptimum(), optimum.getPoint()[0], 2e-7);
Assert.assertEquals(biQuadratic.getBoundedYOptimum(), optimum.getPoint()[1], 2e-7);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:MultivariateFunctionPenaltyAdapterTest.java
示例11: sortPairs
import org.apache.commons.math3.optimization.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);
}
});
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:UnivariateMultiStartOptimizer.java
示例12: testLeastSquares1
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testLeastSquares1() {
final RealMatrix factors =
new Array2DRowRealMatrix(new double[][] {
{ 1, 0 },
{ 0, 1 }
}, false);
LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
public double[] value(double[] variables) {
return factors.operate(variables);
}
}, new double[] { 2.0, -3.0 });
SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
optimizer.setSimplex(new NelderMeadSimplex(2));
PointValuePair optimum =
optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
Assert.assertTrue(optimizer.getEvaluations() > 60);
Assert.assertTrue(optimizer.getEvaluations() < 80);
Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:SimplexOptimizerNelderMeadTest.java
示例13: testRestrictVariablesToNonNegative
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testRestrictVariablesToNonNegative() {
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 409, 523, 70, 204, 339 }, 0);
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
constraints.add(new LinearConstraint(new double[] { 43, 56, 345, 56, 5 }, Relationship.LEQ, 4567456));
constraints.add(new LinearConstraint(new double[] { 12, 45, 7, 56, 23 }, Relationship.LEQ, 56454));
constraints.add(new LinearConstraint(new double[] { 8, 768, 0, 34, 7456 }, Relationship.LEQ, 1923421));
constraints.add(new LinearConstraint(new double[] { 12342, 2342, 34, 678, 2342 }, Relationship.GEQ, 4356));
constraints.add(new LinearConstraint(new double[] { 45, 678, 76, 52, 23 }, Relationship.EQ, 456356));
SimplexSolver solver = new SimplexSolver();
PointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
Assert.assertEquals(2902.92783505155, solution.getPoint()[0], .0000001);
Assert.assertEquals(480.419243986254, solution.getPoint()[1], .0000001);
Assert.assertEquals(0.0, solution.getPoint()[2], .0000001);
Assert.assertEquals(0.0, solution.getPoint()[3], .0000001);
Assert.assertEquals(0.0, solution.getPoint()[4], .0000001);
Assert.assertEquals(1438556.7491409, solution.getValue(), .0000001);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:SimplexSolverTest.java
示例14: search
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
/**
* Find the minimum of the function {@code f(p + alpha * d)}.
*
* @param p Starting point.
* @param d Search direction.
* @return the optimum.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the number of evaluations is exceeded.
*/
public UnivariatePointValuePair search(final double[] p, final double[] d) {
final int n = p.length;
final UnivariateFunction f = new UnivariateFunction() {
public double value(double alpha) {
final double[] x = new double[n];
for (int i = 0; i < n; i++) {
x[i] = p[i] + alpha * d[i];
}
final double obj = PowellOptimizer.this.computeObjectiveValue(x);
return obj;
}
};
final GoalType goal = PowellOptimizer.this.getGoalType();
bracket.search(f, goal, 0, 1);
// Passing "MAX_VALUE" as a dummy value because it is the enclosing
// class that counts the number of evaluations (and will eventually
// generate the exception).
return optimize(Integer.MAX_VALUE, f, goal,
bracket.getLo(), bracket.getHi(), bracket.getMid());
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:31,代码来源:PowellOptimizer.java
示例15: testTableauWithNoArtificialVars
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testTableauWithNoArtificialVars() {
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {15, 10}, 0);
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.LEQ, 2));
constraints.add(new LinearConstraint(new double[] {0, 1}, Relationship.LEQ, 3));
constraints.add(new LinearConstraint(new double[] {1, 1}, Relationship.LEQ, 4));
SimplexTableau tableau =
new SimplexTableau(f, constraints, GoalType.MAXIMIZE, false, 1.0e-6);
double[][] initialTableau = {
{1, -15, -10, 25, 0, 0, 0, 0},
{0, 1, 0, -1, 1, 0, 0, 2},
{0, 0, 1, -1, 0, 1, 0, 3},
{0, 1, 1, -2, 0, 0, 1, 4}
};
assertMatrixEquals(initialTableau, tableau.getData());
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:SimplexTableauTest.java
示例16: testColumnsPermutation
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testColumnsPermutation() {
LinearProblem problem =
new LinearProblem(new double[][] { { 1.0, -1.0 }, { 0.0, 2.0 }, { 1.0, -2.0 } },
new double[] { 4.0, 6.0, 1.0 });
NonLinearConjugateGradientOptimizer optimizer =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
new SimpleValueChecker(1e-6, 1e-6));
PointValuePair optimum =
optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0 });
Assert.assertEquals(7.0, optimum.getPoint()[0], 1.0e-10);
Assert.assertEquals(3.0, optimum.getPoint()[1], 1.0e-10);
Assert.assertEquals(0.0, optimum.getValue(), 1.0e-10);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例17: testNoDependency
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testNoDependency() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 2, 0, 0, 0, 0, 0 },
{ 0, 2, 0, 0, 0, 0 },
{ 0, 0, 2, 0, 0, 0 },
{ 0, 0, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 2, 0 },
{ 0, 0, 0, 0, 0, 2 }
}, new double[] { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5 });
NonLinearConjugateGradientOptimizer optimizer =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
new SimpleValueChecker(1e-6, 1e-6));
PointValuePair optimum =
optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0, 0, 0, 0 });
for (int i = 0; i < problem.target.length; ++i) {
Assert.assertEquals(0.55 * i, optimum.getPoint()[i], 1.0e-10);
}
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例18: testOneSet
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testOneSet() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 0, 0 },
{ -1, 1, 0 },
{ 0, -1, 1 }
}, new double[] { 1, 1, 1});
NonLinearConjugateGradientOptimizer optimizer =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
new SimpleValueChecker(1e-6, 1e-6));
PointValuePair optimum =
optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 0, 0, 0 });
Assert.assertEquals(1.0, optimum.getPoint()[0], 1.0e-10);
Assert.assertEquals(2.0, optimum.getPoint()[1], 1.0e-10);
Assert.assertEquals(3.0, optimum.getPoint()[2], 1.0e-10);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例19: testMoreEstimatedParametersUnsorted
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testMoreEstimatedParametersUnsorted() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 1.0, 1.0, 1.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 1.0, -1.0 },
{ 0.0, 0.0, -1.0, 1.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, -1.0, 1.0, 0.0 }
}, new double[] { 3.0, 12.0, -1.0, 7.0, 1.0 });
NonLinearConjugateGradientOptimizer optimizer =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
new SimpleValueChecker(1e-6, 1e-6));
PointValuePair optimum =
optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 2, 2, 2, 2, 2, 2 });
Assert.assertEquals(0, optimum.getValue(), 1.0e-10);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例20: testInconsistentEquations
import org.apache.commons.math3.optimization.GoalType; //导入依赖的package包/类
@Test
public void testInconsistentEquations() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1.0, 1.0 },
{ 1.0, -1.0 },
{ 1.0, 3.0 }
}, new double[] { 3.0, 1.0, 4.0 });
NonLinearConjugateGradientOptimizer optimizer =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
new SimpleValueChecker(1e-6, 1e-6));
PointValuePair optimum =
optimizer.optimize(100, problem, GoalType.MINIMIZE, new double[] { 1, 1 });
Assert.assertTrue(optimum.getValue() > 0.1);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:NonLinearConjugateGradientOptimizerTest.java
注:本文中的org.apache.commons.math3.optimization.GoalType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论