Package org.apache.commons.math.random

Examples of org.apache.commons.math.random.RandomData


        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


    public void testWithInitialCapacity() {

        ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
        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 );
        }
View Full Code Here

    public void testWithInitialCapacityAndExpansionFactor() {

        ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
        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

        }
      }
    }
    state.getMap().remove(LAST_SETTING);
    state.getMap().remove(LAST_TABLE_SETTING);
    RandomData random = new RandomDataImpl();
    if (random.nextInt(0, 1) == 0) {
      changeTableSetting(random, state, props);
    } else {
      changeSetting(random, state, props);
    }
  }
View Full Code Here

        }
      }
    }
    state.getMap().remove(LAST_SETTING);
    state.getMap().remove(LAST_TABLE_SETTING);
    RandomData random = new RandomDataImpl();
    if (random.nextInt(0, 1) == 0) {
      changeTableSetting(random, state, props);
    } else {
      changeSetting(random, state, props);
    }
  }
View Full Code Here

    return (T) pickArray(args);
  }

  public static Number pickRange(NumberRange range) {
    Number result = null;
    RandomData randomData = new RandomDataImpl();

    if (range.getMinimumNumber() instanceof Integer && range.getMaximumNumber() instanceof Integer) {
      result = randomData.nextInt(range.getMinimumInteger(), range.getMaximumInteger());
    }

    if (range.getMinimumNumber() instanceof Long && range.getMaximumNumber() instanceof Long) {
      result = randomData.nextLong(range.getMinimumLong(), range.getMaximumLong());
    }

    if (range.getMinimumNumber() instanceof Float && range.getMaximumNumber() instanceof Float) {
      result = randomData.nextUniform(range.getMinimumFloat(), range.getMaximumFloat());
    }

    if (range.getMinimumNumber() instanceof Double && range.getMaximumNumber() instanceof Double) {
      result = randomData.nextUniform(range.getMinimumDouble(), range.getMaximumDouble());
    }

    return result;
  }
View Full Code Here

    public void testWithInitialCapacity() {
       
        ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
        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 );
        }
       
View Full Code Here

    public void testWithInitialCapacityAndExpansionFactor() {
       
        ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
        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

        double[] test1 = {5,4,3,2,1};
        double[] test2 = {5,2,1,3,4,0};
        double[] test3 = {1};
        int[] testi = null;
        double[] test4 = null;
        RandomData rd = new RandomDataImpl();
        tstGetSortedValues(test1);
        tstGetSortedValues(test2);
        tstGetSortedValues(test3);
        for (int i = 0; i < 10; i++) {
            testi = rd.nextPermutation(10,6);
            test4 = new double[6];
            for (int j = 0; j < testi.length; j++) {
                test4[j] = (double) testi[j];
            }
            tstGetSortedValues(test4);
        }
        for (int i = 0; i < 10; i++) {
            testi = rd.nextPermutation(10,5);
            test4 = new double[5];
            for (int j = 0; j < testi.length; j++) {
                test4[j] = (double) testi[j];
            }
            tstGetSortedValues(test4);
View Full Code Here

        assertEquals("Q1",1,u.getPercentile(25),10E-12);
        assertEquals("Q3",1,u.getPercentile(75),10E-12);
        assertEquals("Q2",1,u.getPercentile(50),10E-12);
       
        u.clear();
        RandomData rd = new RandomDataImpl();
        int[] testi = rd.nextPermutation(100,100); // will contain 0-99
        for (int j = 0; j < testi.length; j++) {
            u.addValue((double) testi[j])//OK, laugh at me for the cast
        }
        for (int i = 1; i < 100; i++) {
            assertEquals("percentile " + i,
View Full Code Here

TOP

Related Classes of org.apache.commons.math.random.RandomData

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.