Package org.apache.commons.math3.random

Examples of org.apache.commons.math3.random.RandomDataImpl


    public void testWithInitialCapacityAndExpansionFactor() {

        ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
        Assert.assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() );

        RandomData randomData = new RandomDataImpl();
        int iterations = randomData.nextInt(100, 3000);

        for( int i = 0; i < iterations; i++) {
            eDA3.addElement( i );
        }
View Full Code Here


     * 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;
    }
View Full Code Here

     * @return rectangular array with rows = subsamples
     */
    private double[][] generatePartition(double[] sample) {
        final int length = sample.length;
        final double[][] out = new double[5][];
        final RandomData randomData = new RandomDataImpl();
        int cur = 0;
        int offset = 0;
        int sampleCount = 0;
        for (int i = 0; i < 5; i++) {
            if (cur == length || offset == length) {
                break;
            }
            final int next = (i == 4 || cur == length - 1) ? length - 1 : randomData.nextInt(cur, length - 1);
            final int subLength = next - cur + 1;
            out[i] = new double[subLength];
            System.arraycopy(sample, offset, out[i], 0, subLength);
            cur = next + 1;
            sampleCount++;
View Full Code Here

        final int len = 10;        // length of values array
        final double mu = 0;       // mean of test data
        final double sigma = 5;    // std dev of test data
        double[] values = new double[len];
        double[] weights = new double[len];
        RandomData randomData = new RandomDataImpl();

        // Fill weights array with random int values between 1 and 5
        int[] intWeights = new int[len];
        for (int i = 0; i < len; i++) {
            intWeights[i] = randomData.nextInt(1, 5);
            weights[i] = intWeights[i];
        }

        // Fill values array with random data from N(mu, sigma)
        // and fill valuesList with values from values array with
        // values[i] repeated weights[i] times, each i
        List<Double> valuesList = new ArrayList<Double>();
        for (int i = 0; i < len; i++) {
            double value = randomData.nextGaussian(mu, sigma);
            values[i] = value;
            for (int j = 0; j < intWeights[i]; j++) {
                valuesList.add(new Double(value));
            }
        }
View Full Code Here

        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;
 
View Full Code Here

    int haploidNum = 2;
    int groupNum = 1;
    int simSize = 1000000;
    CornSurface myCornSurface = new CornSurface(kernelNum,rowNum,haploidNum,groupNum);
    RandomGenerator rg = new Well44497b();
    RandomDataImpl rng = new RandomDataImpl(rg);
//    CornSimulation myCornSimulation = new CornSimulation(myCornSurface,rng,simSize);
//    System.out.println("The pvalue for four neighbor group is: " + myCornSimulation.simulate(NeighborType.FourNeighbor)+".");
//
//    System.out.println("The pvalue for eight neighbor group is: "+ myCornSimulation.simulate(NeighborType.EightNeighbor)+".");
  //  CornsSimulation corns = new CornsSimulation(2,rng,10000);
View Full Code Here

*
*/
public class TestSpeed {
  public static void main(String[] args) {
    RandomGenerator rg = new Well44497b();
    RandomDataImpl rng = new RandomDataImpl(rg);
    Timer timer = new Timer();
    timer.begin();
    final int MAX_THREADS = Runtime.getRuntime().availableProcessors();
    ExecutorService pool = Executors.newFixedThreadPool(MAX_THREADS);
    for (int i = 0; i < 10000; i++) {
View Full Code Here

public class TestRNGSpeed {
  public static void main(String[] args){
    //CommonMath
    RandomGenerator rg = new Well44497b(29);
    RandomDataImpl rng = new RandomDataImpl(rg);
    Timer timer = new Timer();
    timer.start();
    for(long i=0; i<130000000; ++i){
//      rng.nextPermutation(16, 8);
//      rng.nextGaussian(0, 1);
      rng.nextInt(0, 65779);
    }
    timer.stop();
    timer.printSeconds("generating random numbers");
  }
View Full Code Here


public class TestFinal {
  public static void main(String[] args){
    RandomGenerator rg = new Well44497b(5);
    RandomDataImpl rng = new RandomDataImpl(rg);
    FinalClass fc = new FinalClass.Builder(rng).builder();
    System.out.println(fc.getRNG().nextInt(0, 10));
    System.out.println(fc.getRNG().nextInt(0, 10));
    System.out.println(fc.getRNG().nextInt(0, 10));
    System.out.println(fc.getRNG().nextInt(0,10));
    System.out.println(rng.nextInt(0, 10));
    System.out.println(rng.nextInt(0, 10));
//    rg = new Well44497b(11);
//    rng = new RandomDataImpl(rg);
    System.out.println(fc.getRNG().nextInt(0, 10));
    System.out.println(fc.getRNG().nextInt(0, 10));
    System.out.println(fc.getRNG().nextInt(0, 10));
View Full Code Here

import org.apache.commons.math3.random.Well44497b;

public class TestRNG {
  public static void main(String[] args){
    RandomGenerator rg = new Well44497b(29);
    RandomDataImpl rng = new RandomDataImpl(rg);
    int numberOfElements = 12870;
    int upper = numberOfElements - 1;
    int[] freq = new int[numberOfElements];
    Arrays.fill(freq, 0);
    int averageFreq = 1000;
    for(int i=0; i<numberOfElements; ++i){
      for(int j=0; j<averageFreq; ++j){
        freq[rng.nextInt(0, upper)]++;
      }
    }
    Arrays.sort(freq);
    ArrayList<Frequency> hist = new ArrayList<Frequency>(100);
    Frequency currentFrequency = new Frequency(-1);
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.random.RandomDataImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.