本文整理汇总了Java中org.apache.commons.math3.optim.InitialGuess类的典型用法代码示例。如果您正苦于以下问题:Java InitialGuess类的具体用法?Java InitialGuess怎么用?Java InitialGuess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InitialGuess类属于org.apache.commons.math3.optim包,在下文中一共展示了InitialGuess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyToNetwork
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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: findOptimum
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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;
}
示例3: optimize
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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;
}
示例4: optimize
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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
}
示例5: testNoOptimum
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
/**
* Test demonstrating that the user exception is finally thrown if none
* of the runs succeed.
*/
@Test(expected=TestException.class)
public void testNoOptimum() {
JacobianMultivariateVectorOptimizer underlyingOptimizer
= new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6));
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(12373523445l);
RandomVectorGenerator generator
= new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
MultiStartMultivariateVectorOptimizer optimizer
= new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);
optimizer.optimize(new MaxEval(100),
new Target(new double[] { 0 }),
new Weight(new double[] { 1 }),
new InitialGuess(new double[] { 0 }),
new ModelFunction(new MultivariateVectorFunction() {
public double[] value(double[] point) {
throw new TestException();
}
}));
}
示例6: testGetChiSquare
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test
public void testGetChiSquare() throws IOException {
final StatisticalReferenceDataset dataset
= StatisticalReferenceDatasetFactory.createKirby2();
final AbstractLeastSquaresOptimizer optimizer = createOptimizer();
final double[] a = dataset.getParameters();
final double[] y = dataset.getData()[1];
final double[] w = new double[y.length];
Arrays.fill(w, 1.0);
StatisticalReferenceDataset.LeastSquaresProblem problem
= dataset.getLeastSquaresProblem();
optimizer.optimize(new MaxEval(1),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
new Target(y),
new Weight(w),
new InitialGuess(a));
final double expected = dataset.getResidualSumOfSquares();
final double actual = optimizer.getChiSquare();
Assert.assertEquals(dataset.getName(), expected, actual,
1E-11 * expected);
}
示例7: testMaxEvaluations
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test(expected=TooManyEvaluationsException.class)
public void testMaxEvaluations() throws Exception {
CircleVectorial circle = new CircleVectorial();
circle.addPoint( 30.0, 68.0);
circle.addPoint( 50.0, -6.0);
circle.addPoint(110.0, -20.0);
circle.addPoint( 35.0, 15.0);
circle.addPoint( 45.0, 97.0);
GaussNewtonOptimizer optimizer
= new GaussNewtonOptimizer(new SimpleVectorValueChecker(1e-30, 1e-30));
optimizer.optimize(new MaxEval(100),
circle.getModelFunction(),
circle.getModelFunctionJacobian(),
new Target(new double[] { 0, 0, 0, 0, 0 }),
new Weight(new double[] { 1, 1, 1, 1, 1 }),
new InitialGuess(new double[] { 98.680, 47.345 }));
}
示例8: testNonInvertible
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Override
@Test(expected=SingularMatrixException.class)
public void testNonInvertible() {
/*
* Overrides the method from parent class, since the default singularity
* threshold (1e-14) does not trigger the expected exception.
*/
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 2, -3 },
{ 2, 1, 3 },
{ -3, 0, -9 }
}, new double[] { 1, 1, 1 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum
= optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1 }),
new InitialGuess(new double[] { 0, 0, 0 }));
Assert.assertTrue(FastMath.sqrt(optimizer.getTargetSize()) * optimizer.getRMS() > 0.6);
optimizer.computeCovariances(optimum.getPoint(), 1.5e-14);
}
示例9: testTrivial
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test
public void testTrivial() {
LinearProblem problem
= new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum =
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1 }),
new InitialGuess(new double[] { 0 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
Assert.assertEquals(1.5, optimum.getPoint()[0], 1e-10);
Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10);
}
示例10: testQRColumnsPermutation
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test
public void testQRColumnsPermutation() {
LinearProblem problem
= new LinearProblem(new double[][] { { 1, -1 }, { 0, 2 }, { 1, -2 } },
new double[] { 4, 6, 1 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum =
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1 }),
new InitialGuess(new double[] { 0, 0 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
Assert.assertEquals(7, optimum.getPoint()[0], 1e-10);
Assert.assertEquals(3, optimum.getPoint()[1], 1e-10);
Assert.assertEquals(4, optimum.getValue()[0], 1e-10);
Assert.assertEquals(6, optimum.getValue()[1], 1e-10);
Assert.assertEquals(1, optimum.getValue()[2], 1e-10);
}
示例11: testNoDependency
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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, 1.1, 2.2, 3.3, 4.4, 5.5 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum =
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1, 1, 1, 1 }),
new InitialGuess(new double[] { 0, 0, 0, 0, 0, 0 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
for (int i = 0; i < problem.target.length; ++i) {
Assert.assertEquals(0.55 * i, optimum.getPoint()[i], 1e-10);
}
}
示例12: testOneSet
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的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});
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum =
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1 }),
new InitialGuess(new double[] { 0, 0, 0 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
Assert.assertEquals(1, optimum.getPoint()[0], 1e-10);
Assert.assertEquals(2, optimum.getPoint()[1], 1e-10);
Assert.assertEquals(3, optimum.getPoint()[2], 1e-10);
}
示例13: testNonInvertible
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test(expected=ConvergenceException.class)
public void testNonInvertible() throws Exception {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 2, -3 },
{ 2, 1, 3 },
{ -3, 0, -9 }
}, new double[] { 1, 1, 1 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1 }),
new InitialGuess(new double[] { 0, 0, 0 }));
}
示例14: testMoreEstimatedParametersSimple
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test
public void testMoreEstimatedParametersSimple() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 3, 2, 0, 0 },
{ 0, 1, -1, 1 },
{ 2, 0, 1, 0 }
}, new double[] { 7, 3, 5 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1 }),
new InitialGuess(new double[] { 7, 6, 5, 4 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
}
示例15: testMoreEstimatedParametersUnsorted
import org.apache.commons.math3.optim.InitialGuess; //导入依赖的package包/类
@Test
public void testMoreEstimatedParametersUnsorted() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 1, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 1, -1 },
{ 0, 0, -1, 1, 0, 1 },
{ 0, 0, 0, -1, 1, 0 }
}, new double[] { 3, 12, -1, 7, 1 });
AbstractLeastSquaresOptimizer optimizer = createOptimizer();
PointVectorValuePair optimum =
optimizer.optimize(new MaxEval(100),
problem.getModelFunction(),
problem.getModelFunctionJacobian(),
problem.getTarget(),
new Weight(new double[] { 1, 1, 1, 1, 1 }),
new InitialGuess(new double[] { 2, 2, 2, 2, 2, 2 }));
Assert.assertEquals(0, optimizer.getRMS(), 1e-10);
Assert.assertEquals(3, optimum.getPointRef()[2], 1e-10);
Assert.assertEquals(4, optimum.getPointRef()[3], 1e-10);
Assert.assertEquals(5, optimum.getPointRef()[4], 1e-10);
Assert.assertEquals(6, optimum.getPointRef()[5], 1e-10);
}