Java Code Examples for org.apache.commons.math3.distribution.BetaDistribution#DEFAULT_INVERSE_ABSOLUTE_ACCURACY

The following examples show how to use org.apache.commons.math3.distribution.BetaDistribution#DEFAULT_INVERSE_ABSOLUTE_ACCURACY . 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);
    }
}
 
Example 6
Source File: MathFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Inverse of Beta cdf given a, b parameters and probability")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double inverseBetaCdf(
        @SqlType(StandardTypes.DOUBLE) double a,
        @SqlType(StandardTypes.DOUBLE) double b,
        @SqlType(StandardTypes.DOUBLE) double p)
{
    checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be 0 >= p >= 1");
    checkCondition(a > 0 && b > 0, INVALID_FUNCTION_ARGUMENT, "a, b must be > 0");
    BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    return distribution.inverseCumulativeProbability(p);
}
 
Example 7
Source File: MathFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@Description("Beta cdf given the a, b parameters and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double betaCdf(
        @SqlType(StandardTypes.DOUBLE) double a,
        @SqlType(StandardTypes.DOUBLE) double b,
        @SqlType(StandardTypes.DOUBLE) double value)
{
    checkCondition(value >= 0 && value <= 1, INVALID_FUNCTION_ARGUMENT, "value must be 0 >= v >= 1");
    checkCondition(a > 0 && b > 0, INVALID_FUNCTION_ARGUMENT, "a, b must be > 0");
    BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    return distribution.cumulativeProbability(value);
}