Java Code Examples for org.apache.commons.math.random.RandomDataImpl#nextPermutation()

The following examples show how to use org.apache.commons.math.random.RandomDataImpl#nextPermutation() . 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 3
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 5
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 7
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 9
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 11
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 13
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 14
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 15
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 16
Source File: MathUtilsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}