本文整理汇总了Java中org.apache.commons.math.random.JDKRandomGenerator.setSeed方法的典型用法代码示例。如果您正苦于以下问题:Java JDKRandomGenerator.setSeed方法的具体用法?Java JDKRandomGenerator.setSeed怎么用?Java JDKRandomGenerator.setSeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.random.JDKRandomGenerator
的用法示例。
在下文中一共展示了JDKRandomGenerator.setSeed方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRosenbrock
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testRosenbrock()
throws FunctionEvaluationException, ConvergenceException {
Rosenbrock rosenbrock = new Rosenbrock();
NelderMead underlying = new NelderMead();
underlying.setStartConfiguration(new double[][] {
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
});
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(16069223052l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
MultiStartMultivariateRealOptimizer optimizer =
new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
optimizer.setMaxIterations(100);
RealPointValuePair optimum =
optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
assertTrue(optimizer.getEvaluations() > 20);
assertTrue(optimizer.getEvaluations() < 250);
assertTrue(optimum.getValue() < 8.0e-4);
}
示例2: testSinMin
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testSinMin() throws MathException {
UnivariateRealFunction f = new SinFunction();
UnivariateRealOptimizer underlying = new BrentOptimizer();
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(44428400075l);
MultiStartUnivariateRealOptimizer minimizer =
new MultiStartUnivariateRealOptimizer(underlying, 10, g);
minimizer.optimize(f, GoalType.MINIMIZE, -100.0, 100.0);
double[] optima = minimizer.getOptima();
double[] optimaValues = minimizer.getOptimaValues();
for (int i = 1; i < optima.length; ++i) {
double d = (optima[i] - optima[i-1]) / (2 * Math.PI);
assertTrue (Math.abs(d - Math.rint(d)) < 1.0e-8);
assertEquals(-1.0, f.value(optima[i]), 1.0e-10);
assertEquals(f.value(optima[i]), optimaValues[i], 1.0e-10);
}
assertTrue(minimizer.getEvaluations() > 2900);
assertTrue(minimizer.getEvaluations() < 3100);
}
示例3: testNoOptimum
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test(expected = OptimizationException.class)
public void testNoOptimum() throws FunctionEvaluationException, OptimizationException {
DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
new GaussNewtonOptimizer(true);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(12373523445l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
10, generator);
optimizer.setMaxIterations(100);
optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
optimizer.optimize(new DifferentiableMultivariateVectorialFunction() {
public MultivariateMatrixFunction jacobian() {
return null;
}
public double[] value(double[] point) throws FunctionEvaluationException {
throw new FunctionEvaluationException(point[0]);
}
}, new double[] { 2 }, new double[] { 1 }, new double[] { 0 });
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
示例4: testBadFunction
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testBadFunction() {
UnivariateRealFunction f = new UnivariateRealFunction() {
public double value(double x) {
if (x < 0) {
throw new MathUserException();
}
return 0;
}
};
UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(4312000053L);
MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer =
new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g);
try {
optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2);
Assert.fail();
} catch (MathUserException e) {
// Expected.
}
// Ensure that the exception was thrown because no optimum was found.
Assert.assertTrue(optimizer.getOptima()[0] == null);
}
示例5: testQuinticMin
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testQuinticMin() {
// The quintic function has zeros at 0, +-0.5 and +-1.
// The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(4312000053L);
MultiStartUnivariateRealOptimizer<UnivariateRealFunction> optimizer =
new MultiStartUnivariateRealOptimizer<UnivariateRealFunction>(underlying, 5, g);
UnivariateRealPointValuePair optimum
= optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2);
Assert.assertEquals(-0.2719561293, optimum.getPoint(), 1e-9);
Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9);
UnivariateRealPointValuePair[] optima = optimizer.getOptima();
for (int i = 0; i < optima.length; ++i) {
Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1e-9);
}
Assert.assertTrue(optimizer.getEvaluations() >= 50);
Assert.assertTrue(optimizer.getEvaluations() <= 100);
}
示例6: testCircleFitting
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testCircleFitting() {
Circle circle = new Circle();
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);
NonLinearConjugateGradientOptimizer underlying =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(753289573253l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 },
new GaussianRandomGenerator(g));
MultiStartDifferentiableMultivariateRealOptimizer optimizer =
new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator);
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10));
BrentSolver solver = new BrentSolver();
RealPointValuePair optimum =
optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
assertEquals(200, optimizer.getMaxEvaluations());
RealPointValuePair[] optima = optimizer.getOptima();
for (RealPointValuePair o : optima) {
Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]);
assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
assertEquals(96.075902096, center.x, 1.0e-8);
assertEquals(48.135167894, center.y, 1.0e-8);
}
assertTrue(optimizer.getEvaluations() > 70);
assertTrue(optimizer.getEvaluations() < 90);
assertEquals(3.1267527, optimum.getValue(), 1.0e-8);
}
示例7: testTrivial
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testTrivial() {
LinearProblem problem =
new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
new GaussNewtonOptimizer(true);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(16069223052l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
10, generator);
optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
// no optima before first optimization attempt
try {
optimizer.getOptima();
Assert.fail("an exception should have been thrown");
} catch (MathIllegalStateException ise) {
// expected
}
VectorialPointValuePair optimum =
optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
Assert.assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
Assert.assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
VectorialPointValuePair[] optima = optimizer.getOptima();
Assert.assertEquals(10, optima.length);
for (int i = 0; i < optima.length; ++i) {
Assert.assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10);
Assert.assertEquals(3.0, optima[i].getValue()[0], 1.0e-10);
}
Assert.assertTrue(optimizer.getEvaluations() > 20);
Assert.assertTrue(optimizer.getEvaluations() < 50);
Assert.assertEquals(100, optimizer.getMaxEvaluations());
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:37,代码来源:MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
示例8: createRandom
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
/**
* To be able to use a specific seed and make everything reproducible.
* @return RandomData
*/
private RandomData createRandom() {
final JDKRandomGenerator randomGen = new JDKRandomGenerator();
randomGen.setSeed(1234567890);
return new RandomDataImpl(randomGen);
}
示例9: testTrivial
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testTrivial() throws FunctionEvaluationException, OptimizationException {
LinearProblem problem =
new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
new GaussNewtonOptimizer(true);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(16069223052l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
10, generator);
optimizer.setMaxIterations(100);
optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
// no optima before first optimization attempt
try {
optimizer.getOptima();
fail("an exception should have been thrown");
} catch (IllegalStateException ise) {
// expected
}
VectorialPointValuePair optimum =
optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 });
assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
VectorialPointValuePair[] optima = optimizer.getOptima();
assertEquals(10, optima.length);
for (int i = 0; i < optima.length; ++i) {
assertEquals(1.5, optima[i].getPoint()[0], 1.0e-10);
assertEquals(3.0, optima[i].getValue()[0], 1.0e-10);
}
assertTrue(optimizer.getEvaluations() > 20);
assertTrue(optimizer.getEvaluations() < 50);
assertTrue(optimizer.getIterations() > 20);
assertTrue(optimizer.getIterations() < 50);
assertTrue(optimizer.getJacobianEvaluations() > 20);
assertTrue(optimizer.getJacobianEvaluations() < 50);
assertEquals(100, optimizer.getMaxIterations());
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:42,代码来源:MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
示例10: testCircleFitting
import org.apache.commons.math.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testCircleFitting() throws FunctionEvaluationException, OptimizationException {
Circle circle = new Circle();
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);
NonLinearConjugateGradientOptimizer underlying =
new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
JDKRandomGenerator g = new JDKRandomGenerator();
g.setSeed(753289573253l);
RandomVectorGenerator generator =
new UncorrelatedRandomVectorGenerator(new double[] { 50.0, 50.0 }, new double[] { 10.0, 10.0 },
new GaussianRandomGenerator(g));
MultiStartDifferentiableMultivariateRealOptimizer optimizer =
new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator);
optimizer.setMaxIterations(100);
assertEquals(100, optimizer.getMaxIterations());
optimizer.setMaxEvaluations(100);
assertEquals(100, optimizer.getMaxEvaluations());
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10));
BrentSolver solver = new BrentSolver();
solver.setAbsoluteAccuracy(1.0e-13);
solver.setRelativeAccuracy(1.0e-15);
RealPointValuePair optimum =
optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
RealPointValuePair[] optima = optimizer.getOptima();
for (RealPointValuePair o : optima) {
Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]);
assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
assertEquals(96.075902096, center.x, 1.0e-8);
assertEquals(48.135167894, center.y, 1.0e-8);
}
assertTrue(optimizer.getGradientEvaluations() > 650);
assertTrue(optimizer.getGradientEvaluations() < 700);
assertTrue(optimizer.getEvaluations() > 70);
assertTrue(optimizer.getEvaluations() < 90);
assertTrue(optimizer.getIterations() > 70);
assertTrue(optimizer.getIterations() < 90);
assertEquals(3.1267527, optimum.getValue(), 1.0e-8);
}