Java Code Examples for org.apache.commons.math3.distribution.BetaDistribution#sample()

The following examples show how to use org.apache.commons.math3.distribution.BetaDistribution#sample() . 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: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
Example 2
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
Example 3
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
Example 4
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
Example 5
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}