Example usage for org.apache.commons.math.random RandomDataImpl RandomDataImpl

List of usage examples for org.apache.commons.math.random RandomDataImpl RandomDataImpl

Introduction

In this page you can find the example usage for org.apache.commons.math.random RandomDataImpl RandomDataImpl.

Prototype

public RandomDataImpl(RandomGenerator rand) 

Source Link

Document

Construct a RandomDataImpl using the supplied RandomGenerator as the source of (non-secure) random data.

Usage

From source file:com.milaboratory.util.MathTest.java

@Test
public void testBinomialLog() throws Exception {
    RandomData rdg = new RandomDataImpl(new Well19937c());
    long n, k;//from www  .  j a  v  a2s  .c  om
    double func, exact, avrg;
    for (int i = 0; i < 100000; ++i) {
        n = rdg.nextLong(1, 100);
        k = rdg.nextLong(0, n);
        func = Math.binomialCoefficientLog(n, k);
        exact = exactBinomialCoefficientLog(n, k);
        avrg = (func + exact) / 2;
        assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001);
    }
}

From source file:datafu.pig.hash.lsh.RepeatingLSH.java

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);
    /*/*from w  w  w.  ja va 2s .  c o  m*/
     * 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));
    }
}

From source file:com.milaboratory.util.MathTest.java

@Test
public void testBinomialLogBig() throws Exception {
    RandomData rdg = new RandomDataImpl(new Well19937c());
    long n, k;//  ww w. j a  va 2  s.  co m
    double func, exact, avrg;
    for (int i = 0; i < 5000; ++i) {
        n = rdg.nextLong(1, 10000);
        k = rdg.nextLong(0, n);
        func = Math.binomialCoefficientLog(n, k);
        exact = exactBinomialCoefficientLog(n, k);
        avrg = (func + exact) / 2;
        assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001);
    }
}

From source file:datafu.pig.hash.lsh.p_stable.AbstractStableDistributionFunction.java

public void reset(int dim, double w) throws MathException {
    RandomDataImpl dataSampler = new RandomDataImpl(rg);
    Sampler sampler = getSampler();//from  w ww  .  j a  v  a 2s .c o  m
    this.a = new double[dim];
    this.dim = dim;
    this.w = w;
    for (int i = 0; i < dim; ++i) {
        a[i] = sampler.sample(dataSampler);
    }
    b = dataSampler.nextUniform(0, w);
}

From source file:jmona.random.RandomUtilsTester.java

/**
 * Test method for {@link jmona.random.RandomUtils#setRandomData(RandomData)}.
 *///from   w ww . ja v a 2s  .co  m
@Test
public void testSetRandomData() {
    final RandomData newRandomData = new RandomDataImpl(new MersenneTwister());
    RandomUtils.setRandomData(newRandomData);
    assertSame(newRandomData, RandomUtils.randomData());
}

From source file:lfsom.visualization.clustering.LFSKMeans.java

/**
 * cluster centres are initialised by equally sized random chunks of the
 * input data when there's 150 instances, we assign 50 chosen randomly to
 * each cluster and calculate its centre from these (the last cluster might
 * be larger if numInstances mod k < 0)
 *//* ww  w .j  a v a 2  s.c o  m*/
private void initClustersEqualNumbers() {
    HashSet<Integer> usedIndices = new HashSet<Integer>();
    int limit = numberOfInstances / k;
    // FIXME: Test clustering with new permutation generator!
    // int[] randPermIndices = RandomTools.permutation(new
    // Random(RANDOM_SEED), this.numberOfInstances);
    JDKRandomGenerator rg = new JDKRandomGenerator();
    rg.setSeed(RANDOM_SEED);
    int[] randPermIndices = new RandomDataImpl(rg).nextPermutation(this.numberOfInstances,
            this.numberOfInstances);
    for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) {
        LFSCluster c = new LFSCluster(new double[data[0].length]);
        // System.out.println("cluster: " + clusterIndex);
        for (int randPermIndice : randPermIndices) {
            int currentIndex = randPermIndice;
            if ((c.getNumberOfInstances() < limit || clusterIndex == k - 1)
                    && !usedIndices.contains(currentIndex)) {
                c.addIndex(currentIndex);
                usedIndices.add(currentIndex);
                // System.out.print(" " + currentIndex);
            }
        }
        // System.out.println();
        c.calculateCentroid(data);
        // clusters[clusterIndex] = c;
        clusters[clusterIndex] = new LFSCluster(c.getCentroid());

    }
}