org.apache.commons.math3.distribution.BetaDistribution Java Examples
The following examples show how to use
org.apache.commons.math3.distribution.BetaDistribution.
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: RegressionSynthesizer.java From pyramid with Apache License 2.0 | 6 votes |
public RegDataSet univarBeta(){ BetaDistribution betaDistribution = new BetaDistribution(2,5); RegDataSet dataSet = RegDataSetBuilder.getBuilder() .numDataPoints(numDataPoints) .numFeatures(1) .dense(true) .missingValue(false) .build(); for (int i=0;i<numDataPoints;i++){ double featureValue = Sampling.doubleUniform(0,1); double label; label = betaDistribution.density(featureValue); label += noise.sample(); dataSet.setFeatureValue(i,0,featureValue); dataSet.setLabel(i,label); } return dataSet; }
Example #2
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testNextInversionDeviate() throws Exception { // Set the seed for the default random generator randomData.reSeed(100); double[] quantiles = new double[10]; for (int i = 0; i < 10; i++) { quantiles[i] = randomData.nextUniform(0, 1); } // Reseed again so the inversion generator gets the same sequence randomData.reSeed(100); BetaDistribution betaDistribution = new BetaDistribution(2, 4); /* * 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 = randomData.nextInversionDeviate(betaDistribution); Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9); } }
Example #3
Source File: SliceSamplerUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests slice sampling of a peaked beta distribution as an example of sampling of a bounded random variable. * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%, * respectively. */ @Test public void testSliceSamplingOfPeakedBetaDistribution() { rng.setSeed(RANDOM_SEED); final double alpha = 10.; final double beta = 4.; final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); final Function<Double, Double> betaLogPDF = betaDistribution::logDensity; final double mean = betaDistribution.getNumericalMean(); final double variance = betaDistribution.getNumericalVariance(); final double xInitial = 0.5; final double xMin = 0.; final double xMax = 1.; final double width = 0.1; final int numSamples = 10000; final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width); final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples)); final double sampleMean = new Mean().evaluate(samples); final double sampleVariance = new Variance().evaluate(samples); Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005); Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02); }
Example #4
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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: SliceSamplerUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Tests slice sampling of a monotonic beta distribution as an example of sampling of a bounded random variable. * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%, * respectively. */ @Test public void testSliceSamplingOfMonotonicBetaDistribution() { rng.setSeed(RANDOM_SEED); final double alpha = 10.; final double beta = 1.; final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); final Function<Double, Double> betaLogPDF = betaDistribution::logDensity; final double mean = betaDistribution.getNumericalMean(); final double variance = betaDistribution.getNumericalVariance(); final double xInitial = 0.5; final double xMin = 0.; final double xMax = 1.; final double width = 0.1; final int numSamples = 10000; final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width); final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples)); final double sampleMean = new Mean().evaluate(samples); final double sampleVariance = new Variance().evaluate(samples); Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005); Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02); }
Example #6
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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 #7
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testNextInversionDeviate() { // Set the seed for the default random generator randomData.reSeed(100); double[] quantiles = new double[10]; for (int i = 0; i < 10; i++) { quantiles[i] = randomData.nextUniform(0, 1); } // Reseed again so the inversion generator gets the same sequence randomData.reSeed(100); BetaDistribution betaDistribution = new BetaDistribution(2, 4); /* * 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 = randomData.nextInversionDeviate(betaDistribution); Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9); } }
Example #8
Source File: SomaticLikelihoodsEngineUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDirichletNormalization() { // a Dirichlet with two parameters is a Beta final double a = 11; final double b = 36; final double[] params1 = new double[] {a, b}; final double normalization = Math.exp(SomaticLikelihoodsEngine.logDirichletNormalization(params1)); final BetaDistribution bd = new BetaDistribution(a,b); for (final double x : new double[] {0.1, 0.3, 0.6}) { Assert.assertEquals(bd.density(x), normalization * Math.pow(x, a - 1) * Math.pow(1-x, b-1), 1e-6); } // a Dirichlet with parameters equal to 1 is flat, so the normalization is 1/the hypervolume of the simplex // which is d! where d is the dimension final double[] params2 = new double[] {1, 1, 1, 1}; final double normalization2 = Math.exp(SomaticLikelihoodsEngine.logDirichletNormalization(params2)); Assert.assertEquals(normalization2, 6, 1e-6); }
Example #9
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testNextInversionDeviate() { // Set the seed for the default random generator randomData.reSeed(100); double[] quantiles = new double[10]; for (int i = 0; i < 10; i++) { quantiles[i] = randomData.nextUniform(0, 1); } // Reseed again so the inversion generator gets the same sequence randomData.reSeed(100); BetaDistribution betaDistribution = new BetaDistribution(2, 4); /* * 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 = randomData.nextInversionDeviate(betaDistribution); Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9); } }
Example #10
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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 #11
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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 #12
Source File: SomaticLikelihoodsEngineUnitTest.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testDirichletNormalization() { // a Dirichlet with two parameters is a Beta final double a = 11; final double b = 36; final double[] params1 = new double[] {a, b}; final double normalization = Math.pow(10, SomaticLikelihoodsEngine.log10DirichletNormalization(params1)); final BetaDistribution bd = new BetaDistribution(a,b); for (final double x : new double[] {0.1, 0.3, 0.6}) { Assert.assertEquals(bd.density(x), normalization * Math.pow(x, a - 1) * Math.pow(1-x, b-1), 1e-6); } // a Dirichlet with parameters equal to 1 is flat, so the normalization is 1/the hypervolume of the simplex // which is d! where d is the dimension final double[] params2 = new double[] {1, 1, 1, 1}; final double normalization2 = Math.pow(10, SomaticLikelihoodsEngine.log10DirichletNormalization(params2)); Assert.assertEquals(normalization2, 6, 1e-6); }
Example #13
Source File: SliceSamplerUnitTest.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test slice sampling of a peaked beta distribution as an example of sampling of a bounded random variable. * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%, * respectively. */ @Test public void testSliceSamplingOfPeakedBetaDistribution() { rng.setSeed(RANDOM_SEED); final double alpha = 10.; final double beta = 4.; final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); final Function<Double, Double> betaLogPDF = betaDistribution::logDensity; final double xInitial = 0.5; final double xMin = 0.; final double xMax = 1.; final double width = 0.1; final int numSamples = 10000; final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width); final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples)); final double mean = betaDistribution.getNumericalMean(); final double variance = betaDistribution.getNumericalVariance(); final double sampleMean = new Mean().evaluate(samples); final double sampleVariance = new Variance().evaluate(samples); Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005); Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02); }
Example #14
Source File: SliceSamplerUnitTest.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test slice sampling of a monotonic beta distribution as an example of sampling of a bounded random variable. * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%, * respectively. */ @Test public void testSliceSamplingOfMonotonicBetaDistribution() { rng.setSeed(RANDOM_SEED); final double alpha = 10.; final double beta = 1.; final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); final Function<Double, Double> betaLogPDF = betaDistribution::logDensity; final double xInitial = 0.5; final double xMin = 0.; final double xMax = 1.; final double width = 0.1; final int numSamples = 10000; final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width); final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples)); final double mean = betaDistribution.getNumericalMean(); final double variance = betaDistribution.getNumericalVariance(); final double sampleMean = new Mean().evaluate(samples); final double sampleVariance = new Variance().evaluate(samples); Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005); Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02); }
Example #15
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@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 #16
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #17
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #18
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #19
Source File: CopyRatioSamplers.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Double sample(final RandomGenerator rng, final CopyRatioState state, final CopyRatioSegmentedData data) { logger.debug("Sampling outlier probability..."); final int numOutliers = (int) IntStream.range(0, data.getNumPoints()).filter(state::outlierIndicator).count(); return new BetaDistribution(rng, outlierProbabilityPriorAlpha + numOutliers, outlierProbabilityPriorBeta + data.getNumPoints() - numOutliers).sample(); }
Example #20
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() throws Exception { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #21
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #22
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #23
Source File: MinibatchSliceSamplerUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Tests slice sampling of a beta posterior = uniform prior x binomial likelihood from 1000 data points. * Checks that input mean and standard deviation are recovered from the posterior of the mean parameter * by 500 burn-in samples + 1000 samples to a relative error of 1% and 5%, respectively. */ @Test public void testSliceSamplingOfBetaPosterior() { rng.setSeed(RANDOM_SEED); final int numTrials = 100; final double p = 0.9; final BinomialDistribution binomialDistribution = new BinomialDistribution(rng, numTrials, p); final BiFunction<Integer, Double, Double> binomialLogLikelihood = (d, x) -> new BinomialDistribution(null, numTrials, x).logProbability(d); final List<Integer> data = Ints.asList(binomialDistribution.sample(NUM_DATA_POINTS)); final double numSuccessesTotal = data.stream().mapToDouble(x -> x).sum(); final double alpha = 1. + numSuccessesTotal; final double beta = 1. + (numTrials * NUM_DATA_POINTS - numSuccessesTotal); final double variance = new BetaDistribution(null, alpha, beta).getNumericalVariance(); final double xInitial = 0.5; final double xMin = 0.; final double xMax = 1.; final double width = 0.1; final int numBurnInSamples = 500; final int numSamples = 1500; final MinibatchSliceSampler<Integer> betaSampler = new MinibatchSliceSampler<>( rng, data, UNIFORM_LOG_PRIOR, binomialLogLikelihood, xMin, xMax, width, MINIBATCH_SIZE, APPROX_THRESHOLD); final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples).subList(numBurnInSamples, numSamples)); final double sampleMean = new Mean().evaluate(samples); final double sampleStandardDeviation = new StandardDeviation().evaluate(samples); Assert.assertEquals(relativeError(sampleMean, p), 0., 0.01); Assert.assertEquals(relativeError(sampleStandardDeviation, Math.sqrt(variance)), 0., 0.05); }
Example #24
Source File: RandomDataTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #25
Source File: RandomDataGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNextBeta() { double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5)); long[] counts = new long[4]; randomData.reSeed(1000); for (int i = 0; i < 1000; i++) { double value = randomData.nextBeta(2, 5); TestUtils.updateCounts(value, counts, quartiles); } TestUtils.assertChiSquareAccept(expected, counts, 0.001); }
Example #26
Source File: MathFunctions.java From presto with Apache License 2.0 | 5 votes |
@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 #27
Source File: CopyRatioSamplers.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Double sample(final RandomGenerator rng, final CopyRatioState state, final CopyRatioData dataCollection) { final int numOutliers = (int) IntStream.range(0, dataCollection.getNumTargets()).filter(state::targetOutlierIndicator).count(); return new BetaDistribution(rng, outlierProbabilityPriorAlpha + numOutliers, outlierProbabilityPriorBeta + dataCollection.getNumTargets() - numOutliers).sample(); }
Example #28
Source File: BetaDistributionEvaluator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Object doWork(Object first, Object second) throws IOException{ if(null == first){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory))); } if(null == second){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory))); } Number shape1 = (Number)first; Number shape2 = (Number)second; return new BetaDistribution(shape1.doubleValue(), shape2.doubleValue()); }
Example #29
Source File: MathFunctions.java From presto with Apache License 2.0 | 5 votes |
@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); }
Example #30
Source File: Beta.java From pacaya with Apache License 2.0 | 4 votes |
public Beta(double alpha, double beta) { // TODO: use Prng. this.beta = new BetaDistribution(alpha, beta); }