当前位置: 首页>>代码示例>>Java>>正文


Java JDKRandomGenerator.setSeed方法代码示例

本文整理汇总了Java中org.apache.commons.math3.random.JDKRandomGenerator.setSeed方法的典型用法代码示例。如果您正苦于以下问题:Java JDKRandomGenerator.setSeed方法的具体用法?Java JDKRandomGenerator.setSeed怎么用?Java JDKRandomGenerator.setSeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.random.JDKRandomGenerator的用法示例。


在下文中一共展示了JDKRandomGenerator.setSeed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadConfig

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
public void loadConfig(String filename, String username) throws FileNotFoundException {
    ItemConfigs[] loadedConfigSettings = ItemConfigs.build(filename);
    for (ItemConfigs itemConfigs : loadedConfigSettings) {
        if (itemConfigs.getUsers().contains(username)) {
            for (ItemConfig itemConfig : itemConfigs.getConfig()) {
                itemsCount.put(itemConfig.getName(), Integer.parseInt(itemConfig.getCount()));
                for (Relationship relationship : itemConfig.getRelationships()) {
                    JDKRandomGenerator jdkRandomGenerator = new JDKRandomGenerator();
                    jdkRandomGenerator.setSeed(filename.hashCode());
                    LinkedHashMap<Integer, Integer> relationConfig = new LinkedHashMap<>();
                    for (Percent percents : relationship.getPercent()) {
                        relationConfig.put(percents.getVertex(), percents.getPercentage());
                        System.out.println(percents.getVertex() + " / " + percents.getPercentage());
                    }
                    if (relationship.isUnique()) {
                        uniqueRelations.add(relationship.getName());
                    }
                    relDesc.put(relationship.getName(), new PercentageDistro(jdkRandomGenerator, relationConfig));
                }
            }
        }
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:24,代码来源:GraphBuilder.java

示例2: testSinMin

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(44428400075l);
    UnivariateMultiStartOptimizer<UnivariateFunction> optimizer =
        new UnivariateMultiStartOptimizer<UnivariateFunction>(underlying, 10, g);
    optimizer.optimize(300, f, GoalType.MINIMIZE, -100.0, 100.0);
    UnivariatePointValuePair[] optima = optimizer.getOptima();
    for (int i = 1; i < optima.length; ++i) {
        double d = (optima[i].getPoint() - optima[i-1].getPoint()) / (2 * FastMath.PI);
        Assert.assertTrue(FastMath.abs(d - FastMath.rint(d)) < 1.0e-8);
        Assert.assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10);
        Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10);
    }
    Assert.assertTrue(optimizer.getEvaluations() > 200);
    Assert.assertTrue(optimizer.getEvaluations() < 300);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:UnivariateMultiStartOptimizerTest.java

示例3: testQuinticMin

import org.apache.commons.math3.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,
    UnivariateFunction f = new QuinticFunction();
    UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    UnivariateMultiStartOptimizer<UnivariateFunction> optimizer =
        new UnivariateMultiStartOptimizer<UnivariateFunction>(underlying, 5, g);

    UnivariatePointValuePair 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);

    UnivariatePointValuePair[] 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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:UnivariateMultiStartOptimizerTest.java

示例4: testBadFunction

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testBadFunction() {
    UnivariateFunction f = new UnivariateFunction() {
            public double value(double x) {
                if (x < 0) {
                    throw new LocalException();
                }
                return 0;
            }
        };
    UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    UnivariateMultiStartOptimizer<UnivariateFunction> optimizer =
        new UnivariateMultiStartOptimizer<UnivariateFunction>(underlying, 5, g);
 
    try {
        optimizer.optimize(300, f, GoalType.MINIMIZE, -0.3, -0.2);
        Assert.fail();
    } catch (LocalException e) {
        // Expected.
    }

    // Ensure that the exception was thrown because no optimum was found.
    Assert.assertTrue(optimizer.getOptima()[0] == null);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:UnivariateMultiStartOptimizerTest.java

示例5: testRosenbrock

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testRosenbrock() {
    Rosenbrock rosenbrock = new Rosenbrock();
    SimplexOptimizer underlying
        = new SimplexOptimizer(new SimpleValueChecker(-1, 1.0e-3));
    NelderMeadSimplex simplex = new NelderMeadSimplex(new double[][] {
            { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
        });
    underlying.setSimplex(simplex);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator =
        new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
    MultivariateMultiStartOptimizer optimizer =
        new MultivariateMultiStartOptimizer(underlying, 10, generator);
    PointValuePair optimum =
        optimizer.optimize(1100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });

    Assert.assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
    Assert.assertTrue(optimizer.getEvaluations() > 900);
    Assert.assertTrue(optimizer.getEvaluations() < 1200);
    Assert.assertTrue(optimum.getValue() < 8.0e-4);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:MultivariateMultiStartOptimizerTest.java

示例6: testSinMin

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(44428400075l);
    MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
    optimizer.optimize(new MaxEval(300),
                       new UnivariateObjectiveFunction(f),
                       GoalType.MINIMIZE,
                       new SearchInterval(-100.0, 100.0));
    UnivariatePointValuePair[] optima = optimizer.getOptima();
    for (int i = 1; i < optima.length; ++i) {
        double d = (optima[i].getPoint() - optima[i-1].getPoint()) / (2 * FastMath.PI);
        Assert.assertTrue(FastMath.abs(d - FastMath.rint(d)) < 1.0e-8);
        Assert.assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10);
        Assert.assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10);
    }
    Assert.assertTrue(optimizer.getEvaluations() > 200);
    Assert.assertTrue(optimizer.getEvaluations() < 300);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:MultiStartUnivariateOptimizerTest.java

示例7: testQuinticMin

import org.apache.commons.math3.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,
    UnivariateFunction f = new QuinticFunction();
    UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 5, g);

    UnivariatePointValuePair optimum
        = optimizer.optimize(new MaxEval(300),
                             new UnivariateObjectiveFunction(f),
                             GoalType.MINIMIZE,
                             new SearchInterval(-0.3, -0.2));
    Assert.assertEquals(-0.27195613, optimum.getPoint(), 1e-9);
    Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9);

    UnivariatePointValuePair[] 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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:MultiStartUnivariateOptimizerTest.java

示例8: testNoOptimum

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的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();
                               }
                           }));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:MultiStartMultivariateVectorOptimizerTest.java

示例9: generator

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Override
public JDKRandomGenerator generator() {
	JDKRandomGenerator random = new JDKRandomGenerator();

	random.setSeed(seed);

	return random;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:JDKRandomGeneratorFactory.java

示例10: testMissingMaxEval

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test(expected=MathIllegalStateException.class)
public void testMissingMaxEval() {
    UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(44428400075l);
    MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
    optimizer.optimize(new UnivariateObjectiveFunction(new Sin()),
                       GoalType.MINIMIZE,
                       new SearchInterval(-1, 1));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:MultiStartUnivariateOptimizerTest.java

示例11: testMissingSearchInterval

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test(expected=MathIllegalStateException.class)
public void testMissingSearchInterval() {
    UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(44428400075l);
    MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
    optimizer.optimize(new MaxEval(300),
                       new UnivariateObjectiveFunction(new Sin()),
                       GoalType.MINIMIZE);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:MultiStartUnivariateOptimizerTest.java

示例12: testBadFunction

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testBadFunction() {
    UnivariateFunction f = new UnivariateFunction() {
            public double value(double x) {
                if (x < 0) {
                    throw new LocalException();
                }
                return 0;
            }
        };
    UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(4312000053L);
    MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 5, g);
 
    try {
        optimizer.optimize(new MaxEval(300),
                           new UnivariateObjectiveFunction(f),
                           GoalType.MINIMIZE,
                           new SearchInterval(-0.3, -0.2));
        Assert.fail();
    } catch (LocalException e) {
        // Expected.
    }

    // Ensure that the exception was thrown because no optimum was found.
    Assert.assertTrue(optimizer.getOptima()[0] == null);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:29,代码来源:MultiStartUnivariateOptimizerTest.java

示例13: testGetOptimaBeforeOptimize

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test(expected=NullPointerException.class)
public void testGetOptimaBeforeOptimize() {

    JacobianMultivariateVectorOptimizer underlyingOptimizer
        = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6));
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator
        = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer
        = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    optimizer.getOptima();
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:MultiStartMultivariateVectorOptimizerTest.java

示例14: testTrivial

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testTrivial() {
    LinearProblem problem
        = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    JacobianMultivariateVectorOptimizer underlyingOptimizer
        = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6));
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator
        = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer
        = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    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(1.5, optimum.getPoint()[0], 1e-10);
    Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10);
    PointVectorValuePair[] optima = optimizer.getOptima();
    Assert.assertEquals(10, optima.length);
    for (int i = 0; i < optima.length; i++) {
        Assert.assertEquals(1.5, optima[i].getPoint()[0], 1e-10);
        Assert.assertEquals(3.0, optima[i].getValue()[0], 1e-10);
    }
    Assert.assertTrue(optimizer.getEvaluations() > 20);
    Assert.assertTrue(optimizer.getEvaluations() < 50);
    Assert.assertEquals(100, optimizer.getMaxEvaluations());
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:33,代码来源:MultiStartMultivariateVectorOptimizerTest.java

示例15: testIssue914

import org.apache.commons.math3.random.JDKRandomGenerator; //导入方法依赖的package包/类
@Test
public void testIssue914() {
    LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
    JacobianMultivariateVectorOptimizer underlyingOptimizer =
            new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)) {
        @Override
        public PointVectorValuePair optimize(OptimizationData... optData) {
            // filter out simple bounds, as they are not supported
            // by the underlying optimizer, and we don't really care for this test
            OptimizationData[] filtered = optData.clone();
            for (int i = 0; i < filtered.length; ++i) {
                if (filtered[i] instanceof SimpleBounds) {
                    filtered[i] = null;
                }
            }
            return super.optimize(filtered);
        }
    };
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(16069223052l);
    RandomVectorGenerator generator =
            new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer =
            new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);

    optimizer.optimize(new MaxEval(100),
                       problem.getModelFunction(),
                       problem.getModelFunctionJacobian(),
                       problem.getTarget(),
                       new Weight(new double[] { 1 }),
                       new InitialGuess(new double[] { 0 }),
                       new SimpleBounds(new double[] { -1.0e-10 }, new double[] {  1.0e-10 }));
    PointVectorValuePair[] optima = optimizer.getOptima();
    // only the first start should have succeeded
    Assert.assertEquals(1, optima.length);

}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:38,代码来源:MultiStartMultivariateVectorOptimizerTest.java


注:本文中的org.apache.commons.math3.random.JDKRandomGenerator.setSeed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。