List of usage examples for org.apache.commons.math3.random Well19937c Well19937c
public Well19937c()
From source file:cc.redberry.core.performance.StableSort.java
/** * @param args the command line arguments */// w w w . jav a 2s . c o m public static void main(String[] args) { try { //burn JVM BitsStreamGenerator bitsStreamGenerator = new Well19937c(); for (int i = 0; i < 1000; ++i) nextArray(1000, bitsStreamGenerator); System.out.println("!"); BufferedWriter timMeanOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timMean.dat")); BufferedWriter insertionMeanOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionMean.dat")); BufferedWriter timMaxOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timMax.dat")); BufferedWriter insertionMaxOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionMax.dat")); BufferedWriter timSigOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timSig.dat")); BufferedWriter insertionSigOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionSig.dat")); DescriptiveStatistics timSort; DescriptiveStatistics insertionSort; int tryies = 200; int arrayLength = 0; for (; arrayLength < 1000; ++arrayLength) { int[] coSort = nextArray(arrayLength, bitsStreamGenerator); timSort = new DescriptiveStatistics(); insertionSort = new DescriptiveStatistics(); for (int i = 0; i < tryies; ++i) { int[] t1 = nextArray(arrayLength, bitsStreamGenerator); int[] t2 = t1.clone(); long start = System.currentTimeMillis(); ArraysUtils.timSort(t1, coSort); long stop = System.currentTimeMillis(); timSort.addValue(stop - start); start = System.currentTimeMillis(); ArraysUtils.insertionSort(t2, coSort); stop = System.currentTimeMillis(); insertionSort.addValue(stop - start); } timMeanOut.write(arrayLength + "\t" + timSort.getMean() + "\n"); insertionMeanOut.write(arrayLength + "\t" + insertionSort.getMean() + "\n"); timMaxOut.write(arrayLength + "\t" + timSort.getMax() + "\n"); insertionMaxOut.write(arrayLength + "\t" + insertionSort.getMax() + "\n"); timSigOut.write(arrayLength + "\t" + timSort.getStandardDeviation() + "\n"); insertionSigOut.write(arrayLength + "\t" + insertionSort.getStandardDeviation() + "\n"); } timMeanOut.close(); insertionMeanOut.close(); timMaxOut.close(); insertionMaxOut.close(); timSigOut.close(); insertionSigOut.close(); } catch (IOException ex) { Logger.getLogger(StableSort.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.milaboratory.core.motif.MotifUtilsTest.java
@Test public void test1() throws Exception { RandomGenerator rg = new Well19937c(); for (int i = 0; i < its(1000, 10000); ++i) { int length = 10 + rg.nextInt(30); NucleotideSequence seq1 = randomSequence(NucleotideSequence.ALPHABET, length, length); NucleotideSequence seq2 = randomSequence(NucleotideSequence.ALPHABET, length, length); Motif<NucleotideSequence> motif = MotifUtils.twoSequenceMotif(seq1, 0, seq2, 0, length); Assert.assertTrue(motif.matches(seq1, 0)); Assert.assertTrue(motif.matches(seq2, 0)); }/*from w w w .j a v a 2 s . c o m*/ }
From source file:com.milaboratory.core.mutations.generator.UniformMutationsGeneratorTest.java
@Test public void testRandom1() throws Exception { RandomGenerator generator = new Well19937c(); for (int i = 0; i < 10000; ++i) { NucleotideSequence seq = TestUtil.randomSequence(NucleotideSequence.ALPHABET, generator, 30, 100); Mutations<NucleotideSequence> muts = UniformMutationsGenerator.createUniformMutationAsObject(seq, generator);//from w w w. j av a2 s . c om NucleotideSequence seqM = muts.mutate(seq); Assert.assertFalse(seq.equals(seqM)); } }
From source file:cc.redberry.core.utils.ByteBackedBitArrayTest.java
@Test public void test3() { BitsStreamGenerator random = new Well19937c(); for (int sukatvarblyad = 0; sukatvarblyad < 100; ++sukatvarblyad) { int length; boolean[] array = new boolean[length = random.nextInt(100000)]; ByteBackedBitArray bitArray = new ByteBackedBitArray(length); int i, bitCount = 0; IntArrayList bitsPositions = new IntArrayList(); for (i = 0; i < length; ++i) if (array[i] = random.nextBoolean()) { bitCount++;//ww w.j a v a 2 s .c o m bitArray.set(i); bitsPositions.add(i); } assertEquals(bitCount, bitArray.bitCount()); assertEquals(bitCount, bitsPositions.size()); int pointer = 0; for (i = 0; i < length; ++i) { assertTrue(array[i] == bitArray.get(i)); if (pointer != bitCount) assertTrue(bitsPositions.get(pointer) == bitArray.nextTrailingBit(i)); else assertTrue(-1 == bitArray.nextTrailingBit(i)); if (array[i]) pointer++; } bitArray.setAll(); assertEquals(length, bitArray.bitCount()); } }
From source file:com.milaboratory.primitivio.PrimitivIOTest.java
@Test public void testVarInt1() throws Exception { RandomGenerator rg = new Well19937c(); final int count = TestUtil.its(100, 1000); int[] values = new int[count]; for (int i = 0; i < count; ++i) { int bits = rg.nextInt(31); values[i] = rg.nextInt(0x7FFFFFFF >>> (bits)); }// ww w . j a v a2 s .c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrimitivO po = new PrimitivO(bos); for (int i = 0; i < count; ++i) po.writeVarInt(values[i]); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); PrimitivI pi = new PrimitivI(bis); for (int i = 0; i < count; ++i) Assert.assertEquals(values[i], pi.readVarInt()); }
From source file:cc.redberry.core.tensor.random.RandomTensorTest.java
@Test public void test1() { RandomTensor rp = new RandomTensor(4, 10, new int[] { 4, 0, 0, 0 }, new int[] { 10, 0, 0, 0 }, false, new Well19937c()); Tensor t = rp.nextProduct(4, ParserIndices.parseSimple("_nm")); Assert.assertTrue(t.getIndices().getFree().equalsRegardlessOrder(ParserIndices.parseSimple("_nm"))); }
From source file:io.coala.random.impl.RandomNumberStreamFactoryWell19937c.java
@Override public RandomNumberStream create(final RandomNumberStreamID id, final Number seed) { final RandomGenerator rng = new Well19937c(); rng.setSeed(seed.intValue());//from w w w . j a va 2s . co m return RandomNumberStream.Util.asStream(id, rng); }
From source file:cc.redberry.core.tensor.random.RandomTensorTest.java
@Test public void testSum1() { RandomTensor rp = new RandomTensor(4, 10, new int[] { 4, 0, 0, 0 }, new int[] { 10, 0, 0, 0 }, false, new Well19937c()); Tensor t = rp.nextSum(5, 4, ParserIndices.parseSimple("_nm")); Assert.assertTrue(t.getIndices().equalsRegardlessOrder(ParserIndices.parseSimple("_nm"))); }
From source file:gedi.util.math.stat.distributions.GeneralizedExtremeValueDistribution.java
public GeneralizedExtremeValueDistribution(double location, double scale, double shape) { super(new Well19937c()); this.location = location; this.scale = scale; this.shape = shape; }
From source file:gedi.util.math.stat.distributions.NormalMixtureDistribution.java
public NormalMixtureDistribution(NormalDistribution[] components, double[] mixing) { super(new Well19937c()); this.components = components; this.mixing = mixing; if (ArrayUtils.min(mixing) < 0) throw new NotPositiveException(ArrayUtils.min(mixing)); if (components.length != mixing.length) throw new DimensionMismatchException(mixing.length, components.length); double sum = ArrayUtils.sum(mixing); if (Double.isInfinite(sum)) throw new NotFiniteNumberException(sum); ArrayUtils.mult(mixing, 1 / sum);//from w ww.j a v a2 s . c o m this.mixingSum = mixing.clone(); ArrayUtils.cumSumInPlace(mixingSum, 1); }