org.apache.commons.math.random.RandomDataImpl Java Examples
The following examples show how to use
org.apache.commons.math.random.RandomDataImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #2
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #3
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #4
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; Assert.assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; Assert.assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #5
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #6
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #7
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #8
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #9
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #10
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #11
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #12
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); RandomData randomData = new RandomDataImpl(); int iterations = randomData.nextInt(100, 1000); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #13
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); RandomData randomData = new RandomDataImpl(); int iterations = randomData.nextInt(100, 1000); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #14
Source File: MathUtilTest.java From gameserver with Apache License 2.0 | 6 votes |
/** * Run nextInt range for 10000. Time:9, Heap:0.0M 0: 44.8% 1: 31.42% 2: 16.7% 3: 5.54% 4: 1.31% 5: 0.2% 6: 0.03% 7: 0.0% 8: 0.0% 9: 0.0% * @throws Exception */ @Test public void testNextInt() throws Exception { int max = 10000; final int[] ratio1 = new int[10]; final RandomData commonRandom = new RandomDataImpl(); TestUtil.doPerform(new Runnable() { public void run() { int r = MathUtil.nextGaussionInt(0, 10); ratio1[r]++; } }, "nextInt range", max); printRatio(ratio1, max); }
Example #15
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testGcdConsistency() { int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131}; ArrayList<Integer> primes = new ArrayList<Integer>(); for (int i = 0; i < primeList.length; i++) { primes.add(Integer.valueOf(primeList[i])); } RandomDataImpl randomData = new RandomDataImpl(); for (int i = 0; i < 20; i++) { Object[] sample = randomData.nextSample(primes, 4); int p1 = ((Integer) sample[0]).intValue(); int p2 = ((Integer) sample[1]).intValue(); int p3 = ((Integer) sample[2]).intValue(); int p4 = ((Integer) sample[3]).intValue(); int i1 = p1 * p2 * p3; int i2 = p1 * p2 * p4; int gcd = p1 * p2; Assert.assertEquals(gcd, MathUtils.gcd(i1, i2)); long l1 = i1; long l2 = i2; Assert.assertEquals(gcd, MathUtils.gcd(l1, l2)); } }
Example #16
Source File: RepeatingLSH.java From datafu with Apache License 2.0 | 5 votes |
public RepeatingLSH(List<LSH> lshList) throws MathException { super(lshList.get(0).getDim(), lshList.get(0).getRandomGenerator()); this.lshList = lshList; RandomGenerator rg = lshList.get(0).getRandomGenerator(); RandomData rd = new RandomDataImpl(rg); /* * Compute a random vector of lshList.size() with each component taken from U(0,10) */ randomVec = new ArrayRealVector(lshList.size()); for(int i = 0; i < randomVec.getDimension();++i) { randomVec.setEntry(i, rd.nextUniform(0, 10.0)); } }
Example #17
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given NaNStrategy and TiesStrategy. * * @param nanStrategy NaNStrategy to use * @param tiesStrategy TiesStrategy to use */ public NaturalRanking(NaNStrategy nanStrategy, TiesStrategy tiesStrategy) { super(); this.nanStrategy = nanStrategy; this.tiesStrategy = tiesStrategy; randomData = new RandomDataImpl(); }
Example #18
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final RandomData randomData = new RandomDataImpl(); final int sampleSize = randomData.nextInt(10,100); double[] out = new double[sampleSize]; for (int i = 0; i < out.length; i++) { out[i] = randomData.nextUniform(-100, 100); } return out; }
Example #19
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with TiesStrategy.RANDOM and the given * RandomGenerator as the source of random data. * * @param randomGenerator source of random data */ public NaturalRanking(RandomGenerator randomGenerator) { super(); this.tiesStrategy = TiesStrategy.RANDOM; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(randomGenerator); }
Example #20
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given TiesStrategy. * * @param tiesStrategy the TiesStrategy to use */ public NaturalRanking(TiesStrategy tiesStrategy) { super(); this.tiesStrategy = tiesStrategy; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(); }
Example #21
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with TiesStrategy.RANDOM and the given * RandomGenerator as the source of random data. * * @param randomGenerator source of random data */ public NaturalRanking(RandomGenerator randomGenerator) { super(); this.tiesStrategy = TiesStrategy.RANDOM; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(randomGenerator); }
Example #22
Source File: MathUtilTest.java From gameserver with Apache License 2.0 | 5 votes |
@Test public void testNextIntQ2() throws Exception { int loop = 10000; final int min = 10; final int max = 100; final double q = 5; final HashMap<Integer, Integer> countMap = new HashMap<Integer, Integer>(); final RandomData commonRandom = new RandomDataImpl(); TestUtil.doPerform(new Runnable() { public void run() { int r = MathUtil.nextGaussionInt(min, max, q); Integer count = countMap.get(r); if ( count == null ) { countMap.put(r, 1); } else { countMap.put(r, count+1); } } }, "nextInt range 3.0", loop); ArrayList<Integer> list = new ArrayList<Integer>(countMap.keySet()); Collections.sort(list); for ( Integer in : list ) { Integer value = countMap.get(in); System.out.println(in+ "->"+value+" : " + (value*100.0/loop) + "%"); assertTrue(in.intValue() >= min); } }
Example #23
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given TiesStrategy. * * @param tiesStrategy the TiesStrategy to use */ public NaturalRanking(TiesStrategy tiesStrategy) { super(); this.tiesStrategy = tiesStrategy; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(); }
Example #24
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with TiesStrategy.RANDOM and the given * RandomGenerator as the source of random data. * * @param randomGenerator source of random data */ public NaturalRanking(RandomGenerator randomGenerator) { super(); this.tiesStrategy = TiesStrategy.RANDOM; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(randomGenerator); }
Example #25
Source File: MathUtilsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Make sure that permuted arrays do not hash to the same value. */ @Test public void testPermutedArrayHash() { double[] original = new double[10]; double[] permuted = new double[10]; RandomDataImpl random = new RandomDataImpl(); // Generate 10 distinct random values for (int i = 0; i < 10; i++) { original[i] = random.nextUniform(i + 0.5, i + 0.75); } // Generate a random permutation, making sure it is not the identity boolean isIdentity = true; do { int[] permutation = random.nextPermutation(10, 10); for (int i = 0; i < 10; i++) { if (i != permutation[i]) { isIdentity = false; } permuted[i] = original[permutation[i]]; } } while (isIdentity); // Verify that permuted array has different hash Assert.assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted)); }
Example #26
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given TiesStrategy. * * @param tiesStrategy the TiesStrategy to use */ public NaturalRanking(TiesStrategy tiesStrategy) { super(); this.tiesStrategy = tiesStrategy; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(); }
Example #27
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final RandomData randomData = new RandomDataImpl(); final int sampleSize = randomData.nextInt(10,100); double[] out = new double[sampleSize]; for (int i = 0; i < out.length; i++) { out[i] = randomData.nextUniform(-100, 100); } return out; }
Example #28
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM * and the given source of random data. * * @param nanStrategy NaNStrategy to use * @param randomGenerator source of random data */ public NaturalRanking(NaNStrategy nanStrategy, RandomGenerator randomGenerator) { super(); this.nanStrategy = nanStrategy; this.tiesStrategy = TiesStrategy.RANDOM; randomData = new RandomDataImpl(randomGenerator); }
Example #29
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with TiesStrategy.RANDOM and the given * RandomGenerator as the source of random data. * * @param randomGenerator source of random data */ public NaturalRanking(RandomGenerator randomGenerator) { super(); this.tiesStrategy = TiesStrategy.RANDOM; nanStrategy = DEFAULT_NAN_STRATEGY; randomData = new RandomDataImpl(randomGenerator); }
Example #30
Source File: NaturalRanking.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM * and the given source of random data. * * @param nanStrategy NaNStrategy to use * @param randomGenerator source of random data */ public NaturalRanking(NaNStrategy nanStrategy, RandomGenerator randomGenerator) { super(); this.nanStrategy = nanStrategy; this.tiesStrategy = TiesStrategy.RANDOM; randomData = new RandomDataImpl(randomGenerator); }