Examples of RandomDataImpl


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

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

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

    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

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

     * 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

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

     * @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

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

        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

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

    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

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

    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

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

    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

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

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

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

     * 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
TOP
Copyright © 2018 www.massapi.com. 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.