List of usage examples for org.apache.commons.math3.random Well19937a Well19937a
public Well19937a()
From source file:com.milaboratory.core.io.util.IOUtilTest.java
@Test public void test1() throws Exception { RandomGenerator rg = new Well19937a(); int count = 1000; int[] values = new int[count]; for (int n = 0; n < 10; ++n) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < count; ++i) { final int d = rg.nextInt(31); values[i] = (rg.nextInt(Integer.MAX_VALUE) >>> d); IOUtil.writeRawVarint32(bos, values[i]); }/*from w w w. j a va 2 s . c o m*/ byte[] data = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(data); int g; for (int i = 0; i < count; ++i) { Assert.assertEquals(values[i], IOUtil.readRawVarint32(bis, -1)); } Assert.assertEquals(-1, IOUtil.readRawVarint32(bis, -1)); } }
From source file:com.milaboratory.core.io.util.IOUtilTest.java
@Test public void test3() throws Exception { RandomGenerator rg = new Well19937a(); int count = 1000; int[] values = new int[count]; for (int n = 0; n < 10; ++n) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < count; ++i) { final int d = rg.nextInt(31) + 1; values[i] = (rg.nextInt(Integer.MAX_VALUE) >>> d); if (rg.nextBoolean()) values[i] *= -1;/* ww w .j a v a 2 s . co m*/ final int encoded = IOUtil.encodeZigZag32(values[i]); Assert.assertTrue(-1 != encoded); IOUtil.writeRawVarint32(bos, encoded); } byte[] data = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(data); int g; for (int i = 0; i < count; ++i) { Assert.assertEquals(values[i], IOUtil.decodeZigZag32(IOUtil.readRawVarint32(bis, -1))); } Assert.assertEquals(-1, IOUtil.readRawVarint32(bis, -1)); } }
From source file:com.milaboratory.core.io.util.IOUtilTest.java
@Test public void test2() throws Exception { RandomGenerator rg = new Well19937a(); int count = 1000; long[] values = new long[count]; for (int n = 0; n < 10; ++n) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < count; ++i) { final int d = rg.nextInt(63) + 1; values[i] = (rg.nextLong() >>> d); IOUtil.writeRawVarint64(bos, values[i]); }// w w w .ja v a 2s .c om byte[] data = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(data); int g; for (int i = 0; i < count; ++i) { Assert.assertEquals(values[i], IOUtil.readRawVarint64(bis, -1)); } Assert.assertEquals(-1L, IOUtil.readRawVarint64(bis, -1)); } }
From source file:com.milaboratory.core.io.util.IOUtilTest.java
@Test public void test4() throws Exception { RandomGenerator rg = new Well19937a(); int count = 1000; long[] values = new long[count]; for (int n = 0; n < 10; ++n) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < count; ++i) { final int d = rg.nextInt(63) + 1; values[i] = (rg.nextLong() >>> d); if (rg.nextBoolean()) values[i] *= -1;//from ww w. ja v a 2 s . c om final long encoded = IOUtil.encodeZigZag64(values[i]); Assert.assertTrue(-1L != encoded); IOUtil.writeRawVarint64(bos, encoded); } byte[] data = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(data); int g; for (int i = 0; i < count; ++i) { Assert.assertEquals(values[i], IOUtil.decodeZigZag64(IOUtil.readRawVarint64(bis, -1))); } Assert.assertEquals(-1L, IOUtil.readRawVarint64(bis, -1)); } }
From source file:com.milaboratory.core.clustering.ClusteringTest.java
@Test public void testRandom1() throws Exception { int out = TestUtil.its(3, 30); Well19937a rand = new Well19937a(); for (int x = 0; x < out; ++x) { int N = TestUtil.its(40, 300); Cluster<TestObject>[] clusters = new Cluster[N]; Well19937a rand1 = new Well19937a(rand.nextLong()); TestStrategy strategy = new TestStrategy(5, new TreeSearchParameters(1, 1, 1, 1)); for (int i = 0; i < N; ++i) clusters[i] = getRandomTestCluster( TestUtil.randomSequence(NucleotideSequence.ALPHABET, rand1, 45, 55), strategy.depth, 5, 10000 + rand1.nextInt(10000), 5 + rand1.nextInt(900), rand1.nextLong()); assertClusters(false, strategy, clusters); }// ww w. j a va 2 s . c o m }
From source file:com.milaboratory.core.clustering.ClusteringTest.java
@Test public void testRandom2WithColor() { int out = TestUtil.its(3, 30); Well19937a rand = new Well19937a(); int colors = 3; for (int x = 0; x < out; ++x) { int N = TestUtil.its(16, 100); Cluster<TestObject>[] clusters = new Cluster[N * colors]; Well19937a rand1 = new Well19937a(rand.nextLong()); TestStrategy strategy = new TestStrategy(5, new TreeSearchParameters(1, 1, 1, 1)); int c = 0; for (int i = 0; i < N; ++i) { long seed = rand1.nextLong(); NucleotideSequence sequence = TestUtil.randomSequence(NucleotideSequence.ALPHABET, rand1, 45, 55); for (int color = 0; color < colors; ++color) { clusters[c++] = getRandomTestCluster(sequence, color, strategy.depth, 5, 10000 + rand1.nextInt(10000), 5 + rand1.nextInt(900), seed); }/*from w w w .ja va 2s. c o m*/ } assertDiffSizeClusters(strategy.getDummy(), clusters); assertClusters(false, strategy, clusters); } }
From source file:com.milaboratory.core.tree.SequenceTreeMapTest.java
@Test public void testRemoveTest() throws Exception { RandomGenerator gen = new Well19937a(); RandomDataGenerator data = new RandomDataGenerator(gen); for (int k = 0; k < 100; ++k) { Set<NucleotideSequence> seqSet = new HashSet<>(); for (int i = 0; i < 1000; ++i) seqSet.add(randomSequence(NucleotideSequence.ALPHABET, data, 4, 30)); SequenceTreeMap<NucleotideSequence, NucleotideSequence> seqTree = new SequenceTreeMap<>( NucleotideSequence.ALPHABET); for (NucleotideSequence seq : seqSet) seqTree.put(seq, seq);// www . j av a 2 s. c om int n = 0; for (NucleotideSequence seq : seqTree.values()) { assertTrue(seqSet.contains(seq)); ++n; } assertEquals(seqSet.size(), n); for (NucleotideSequence seq : seqSet) assertEquals(seq, seqTree.remove(seq)); for (int i = 0; i < 4; ++i) assertNull(seqTree.root.links[i]); n = 0; for (NucleotideSequence seq : seqTree.values()) ++n; assertEquals(0, n); } }
From source file:org.dawnsci.plotting.tools.diffraction.BeamCenterRefinement.java
/** * Run optimisation of sector region position in a separate job. * //from w w w .j ava 2s . c om * @param startPosition Initial position of sector region */ public void optimize(final double[] startPosition) { final int cmaesLambda = this.cmaesLambda; final double[] cmaesInputSigma = this.cmaesInputSigma; final int cmaesMaxIterations = this.cmaesMaxIterations; final int cmaesCheckFeasableCount = this.cmaesCheckFeasableCount; final ConvergenceChecker<PointValuePair> cmaesChecker = this.cmaesChecker; final BeamCenterRefinement function = this; Job job = new Job("Beam Position Refinement") { @Override protected IStatus run(IProgressMonitor monitor) { function.setInitPeaks(initPeaks); function.setMonitor(monitor); final double[] lB = new double[] { startPosition[0] - 20, startPosition[1] - 20 }; final double[] uB = new double[] { startPosition[0] + 20, startPosition[1] + 20 }; CMAESOptimizer beamPosOptimizer = new CMAESOptimizer(cmaesMaxIterations, 0.0, true, 0, cmaesCheckFeasableCount, new Well19937a(), false, cmaesChecker); final PointValuePair result = beamPosOptimizer.optimize(new MaxEval(cmaesMaxIterations), new ObjectiveFunction(function), GoalType.MAXIMIZE, new CMAESOptimizer.PopulationSize(cmaesLambda), new CMAESOptimizer.Sigma(cmaesInputSigma), new SimpleBounds(lB, uB), new InitialGuess(startPosition)); final double[] newBeamPosition = result.getPoint(); logger.info("Optimiser terminated at beam position ({}, {}) with the value {}", new Object[] { newBeamPosition[0], newBeamPosition[1], result.getValue() }); Display.getDefault().syncExec(new Runnable() { @Override public void run() { ((IDiffractionMetadata) dataset.getMetadata()).getDetector2DProperties() .setBeamCentreCoords(newBeamPosition); } }); return Status.OK_STATUS; } }; job.schedule(); }
From source file:org.optaplanner.core.impl.solver.random.DefaultRandomFactory.java
@Override public Random createRandom() { switch (randomType) { case JDK:// w ww . j a v a 2 s.c om return randomSeed == null ? new Random() : new Random(randomSeed); case MERSENNE_TWISTER: return new RandomAdaptor(randomSeed == null ? new MersenneTwister() : new MersenneTwister(randomSeed)); case WELL512A: return new RandomAdaptor(randomSeed == null ? new Well512a() : new Well512a(randomSeed)); case WELL1024A: return new RandomAdaptor(randomSeed == null ? new Well1024a() : new Well1024a(randomSeed)); case WELL19937A: return new RandomAdaptor(randomSeed == null ? new Well19937a() : new Well19937a(randomSeed)); case WELL19937C: return new RandomAdaptor(randomSeed == null ? new Well19937c() : new Well19937c(randomSeed)); case WELL44497A: return new RandomAdaptor(randomSeed == null ? new Well44497a() : new Well44497a(randomSeed)); case WELL44497B: return new RandomAdaptor(randomSeed == null ? new Well44497b() : new Well44497b(randomSeed)); default: throw new IllegalStateException("The randomType (" + randomType + ") is not implemented."); } }
From source file:uk.ac.diamond.scisoft.ncd.calibration.rcp.views.MultivariateFunctionWithMonitor.java
public void optimize(final double[] startPosition) { final int cmaesLambda = this.cmaesLambda; final double[] cmaesInputSigma = this.cmaesInputSigma; final int cmaesMaxIterations = this.cmaesMaxIterations; final int cmaesCheckFeasableCount = this.cmaesCheckFeasableCount; final ConvergenceChecker<PointValuePair> cmaesChecker = this.cmaesChecker; final MultivariateFunctionWithMonitor function = this; Job job = new Job(jobName) { @Override//from ww w .j a va 2 s . c om protected IStatus run(IProgressMonitor monitor) { function.setInitPeaks(initPeaks); function.setMonitor(monitor); CMAESOptimizer beamPosOptimizer = new CMAESOptimizer(cmaesMaxIterations, 0.0, true, 0, cmaesCheckFeasableCount, new Well19937a(), false, cmaesChecker); final PointValuePair res = beamPosOptimizer.optimize(new MaxEval(cmaesMaxIterations), new ObjectiveFunction(function), GoalType.MAXIMIZE, new CMAESOptimizer.PopulationSize(cmaesLambda), new CMAESOptimizer.Sigma(cmaesInputSigma), SimpleBounds.unbounded(2), new InitialGuess(startPosition)); final double[] newBeamPos = res.getPoint(); logger.info("Optimiser terminated at beam position ({}, {}) with the value {}", new Object[] { newBeamPos[0], newBeamPos[1], res.getValue() }); // Run calculation with optimised beam center to update UI function.value(newBeamPos); return Status.OK_STATUS; } }; job.schedule(); }