List of usage examples for org.apache.commons.math.special Beta regularizedBeta
public static double regularizedBeta(double x, double a, double b) throws MathException
From source file:dr.math.distributions.NegativeBinomialDistribution.java
public double quantile(double y) { // TB - I'm having trouble implementing this // LM - A first stab using simple minimisation to invert the function (under absolute loss) // Implementation based on the qnbinom.c function used in R final double stdev = Math.sqrt(mean + (mean * mean * alpha)); final double r = -1 * (mean * mean) / (mean - stdev * stdev); final double p = mean / (stdev * stdev); final double prob = y; final double Q = 1.0 / p; final double P = (1.0 - p) * Q; final double gamma = (Q + P) / stdev; final double z = Math.sqrt(2.0) * ErrorFunction.inverseErf(2.0 * y - 1.0); final double crudeY = mean + stdev * (z + gamma * (z * z - 1) / 6); UnivariateFunction f = new UnivariateFunction() { double tent = Double.NaN; public double evaluate(final double argument) { try { tent = Beta.regularizedBeta(p, r, argument + 1); } catch (MathException e) { return Double.NaN; }/*from w ww .j av a 2 s . c om*/ double score = Math.abs(tent - prob); return score; } public int getNumArguments() { return 1; } public double getLowerBound() { // 20% window should cut it. Probably too large even... return Math.min(crudeY - .2 * crudeY, 0); } public double getUpperBound() { return crudeY + .2 * crudeY; } }; UnivariateMinimum minimum = new UnivariateMinimum(); double q = minimum.findMinimum(f); return Math.ceil(q); }
From source file:geogebra.util.MyMath.java
final public static double betaIncomplete(double a, double b, double x) { try {/*from ww w. j a va 2s. co m*/ return Beta.regularizedBeta(x, a, b) * beta(a, b); } catch (MathException e) { return Double.NaN; } }
From source file:geogebra.util.MyMath.java
final public static double betaIncompleteRegularized(double a, double b, double x) { try {/*from w ww .j av a 2s.c o m*/ return Beta.regularizedBeta(x, a, b); } catch (MathException e) { return Double.NaN; } }
From source file:dr.math.distributions.NegativeBinomialDistribution.java
public static double cdf(double x, double mean, double alpha) { double theta = 1.0 / alpha; double p = theta / (theta + mean); try {/*from w w w . j a va 2 s.co m*/ return Beta.regularizedBeta(p, theta, x + 1); } catch (MathException e) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Couldn't calculate beta cdf for alpha = " + alpha + ", beta = " + beta + ": " +e.getMessage()); } }
From source file:dr.math.distributions.BetaDistribution.java
public double cdf(double x) { if (x <= 0) { return 0; } else if (x >= 1) { return 1; } else {// www . j a va2s.co m try { return Beta.regularizedBeta(x, alpha, beta); } catch (MathException e) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Couldn't calculate beta cdf for alpha = " + alpha + ", beta = " + beta + ": " +e.getMessage()); } } }
From source file:dr.math.distributions.BetaDistribution.java
public double cumulativeProbability(double x) throws MathException { if (x <= 0) { return 0; } else if (x >= 1) { return 1; } else {//www . ja v a 2 s.c om return Beta.regularizedBeta(x, alpha, beta); } }