Package edu.cmu.tetrad.util
Class ProbUtils
java.lang.Object
edu.cmu.tetrad.util.ProbUtils
Implements a number of important functions from probability and statistics.> 0
We don't know who wrote this class; we didn't. All we added was the documentation. -Joe Ramsey, jdramsey@andrew.cmu.edu> 0
- Version:
- $Id: $Id
- Author:
- Unknown, but thanks
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
bernoulliRand
(double p) bernoulliRand.static double
betaCdf
(double x, double pin, double qin) Incomplete Beta function.static double
betaPdf
(double x, double a, double b) betaPdf.static double
betaQuantile
(double alpha, double p, double q) betaQuantile.static double
betaRand
(double a, double b) Beta distribution random generator.static double
binomialCdf
(int k, int n, double p) Binomial cumulative distribution function.static double
binomialPmf
(int k, int n, double p) binomialPmf.static int
binomialQuantile
(double x, int n, double p) binomialQuantile.static int
binomialRand
(int n, double pp) Binomial random generator from Numerical Recipesstatic double
biNormalCdf
(double ah, double ak, double r) Bivariate normal CDF.static double
cauchyCdf
(double x) Cauchy CDFstatic double
cauchyPdf
(double x) cauchyPdf.static double
cauchyQuantile
(double x) cauchyQuantile.static double
Cauchy random generator.static double
chisqCdf
(double x, double df) chisqCdf.static double
chisqPdf
(double x, double v) chisqPdf.static double
chisqQuantile
(double p, double v) chisqQuantile.static double
chisqRand
(double df) Chi square random generator.static double
fCdf
(double x, double df1, double df2) F CDF.static double
fPdf
(double x, double a, double b) fPdf.static double
fQuantile
(double p, double df1, double df2) fQuantile.static double
fRand
(double ndf, double ddf) F distribution random generator.static double
gammaCdf
(double a, double x) compute complementary gamma cdf by its continued fraction expansionstatic double
gammaPdf
(double x, double a) gammaPdf.static double
gammaQuantile
(double a, double p) gammaQuantile.static double
gammaRand
(double a) Gamma random generator.static double
lngamma
(double xx) This is a more literal (that is, exact) copy of the log gamma method from Numerical Recipes than the following one.static double
logbeta
(double p, double q) Calculates the log beta function of p and q.static double
multinormalProb
(double[] a, double[] b, double[][] cov) Compute the probability over a rectangular region with correlation matrix c.static double
normalCdf
(double y) Normal cumulative distribution function (the value which results by integrating the normal distribution function from negative infinity up to y).static double
normalPdf
(double x) normalPdf.static double
normalQuantile
(double p) normalQuantile.static double
Normal random generatorstatic double
poissonCdf
(int k, double y) poissonCdf.static double
poissonPmf
(int k, double lambda) poissonPmf.static int
poissonQuantile
(double x, double l) poissonQuantile.static int
poissonRand
(double xm) Poisson random generator from Numerical Recipesstatic double
tCdf
(double x, double df) CACM Algorithm 395, by G.static double
tPdf
(double x, double a) tPdf.static double
tQuantile
(double pp, double n) CACM Algorithm 396, by G.static double
tRand
(double df) T distribution random generator.static double
uniformRand.static void
uniformSeeds
(long a, long b) uniformSeeds.
-
Method Details
-
normalCdf
public static double normalCdf(double y) Normal cumulative distribution function (the value which results by integrating the normal distribution function from negative infinity up to y).- Parameters:
y
- the upper limit of integration.- Returns:
- the area accumulated in the integration.
-
lngamma
public static double lngamma(double xx) This is a more literal (that is, exact) copy of the log gamma method from Numerical Recipes than the following one. It was created by cutting and pasting from the PDF version of the book and then converting C syntax to Java. The static double array above goes with this. Converted to Java by Frank Wimberly- Parameters:
xx
- a double- Returns:
- the value ln[?(xx)] for xx > 0
-
logbeta
public static double logbeta(double p, double q) Calculates the log beta function of p and q.- Parameters:
p
- a doubleq
- a double- Returns:
- a double
-
betaCdf
public static double betaCdf(double x, double pin, double qin) Incomplete Beta function. Translated from FORTRAN july 1977 edition. w. fullerton, c3, los alamos scientific lab. based on bosten and battiste, remark on algorithm 179, comm. acm, v 17, p 153, (1974).- Parameters:
x
- upper limit of integration. x must be in (0,1) inclusive.pin
- first beta distribution parameter. p must be gt 0.0.qin
- second beta distribution parameter. q must be gt 0.0.- Returns:
- result.
-
binomialCdf
public static double binomialCdf(int k, int n, double p) Binomial cumulative distribution function.- Parameters:
k
- a intn
- a intp
- a double- Returns:
- a double
-
cauchyCdf
public static double cauchyCdf(double x) Cauchy CDF- Parameters:
x
- a double- Returns:
- a double
-
fCdf
public static double fCdf(double x, double df1, double df2) F CDF.- Parameters:
x
- a doubledf1
- a doubledf2
- a double- Returns:
- a double
-
gammaCdf
public static double gammaCdf(double a, double x) compute complementary gamma cdf by its continued fraction expansion- Parameters:
a
- a doublex
- a double- Returns:
- a double
-
chisqCdf
public static double chisqCdf(double x, double df) chisqCdf.
- Parameters:
x
- a doubledf
- a double- Returns:
- a double
-
poissonCdf
public static double poissonCdf(int k, double y) poissonCdf.
- Parameters:
k
- a inty
- a double- Returns:
- a double
-
tCdf
public static double tCdf(double x, double df) CACM Algorithm 395, by G. W. Hill- Parameters:
x
- a doubledf
- a double- Returns:
- a double
-
betaQuantile
public static double betaQuantile(double alpha, double p, double q) betaQuantile.
- Parameters:
alpha
- a doublep
- a doubleq
- a double- Returns:
- a double
-
binomialQuantile
public static int binomialQuantile(double x, int n, double p) binomialQuantile.
- Parameters:
x
- a doublen
- a intp
- a double- Returns:
- a int
-
cauchyQuantile
public static double cauchyQuantile(double x) cauchyQuantile.
- Parameters:
x
- a double- Returns:
- a double
-
chisqQuantile
public static double chisqQuantile(double p, double v) chisqQuantile.
- Parameters:
p
- a doublev
- a double- Returns:
- a double
-
fQuantile
public static double fQuantile(double p, double df1, double df2) fQuantile.
- Parameters:
p
- a doubledf1
- a doubledf2
- a double- Returns:
- a double
-
gammaQuantile
public static double gammaQuantile(double a, double p) gammaQuantile.
- Parameters:
a
- a doublep
- a double- Returns:
- a double
-
normalQuantile
public static double normalQuantile(double p) normalQuantile.
- Parameters:
p
- a double- Returns:
- a double
-
poissonQuantile
public static int poissonQuantile(double x, double l) poissonQuantile.
- Parameters:
x
- a doublel
- a double- Returns:
- a int
-
tQuantile
public static double tQuantile(double pp, double n) CACM Algorithm 396, by G. W. Hill- Parameters:
pp
- a doublen
- a double- Returns:
- a double
-
betaPdf
public static double betaPdf(double x, double a, double b) betaPdf.
- Parameters:
x
- a doublea
- a doubleb
- a double- Returns:
- a double
-
binomialPmf
public static double binomialPmf(int k, int n, double p) binomialPmf.
- Parameters:
k
- a intn
- a intp
- a double- Returns:
- a double
-
cauchyPdf
public static double cauchyPdf(double x) cauchyPdf.
- Parameters:
x
- a double- Returns:
- a double
-
chisqPdf
public static double chisqPdf(double x, double v) chisqPdf.
- Parameters:
x
- a doublev
- a double- Returns:
- a double
-
fPdf
public static double fPdf(double x, double a, double b) fPdf.
- Parameters:
x
- a doublea
- a doubleb
- a double- Returns:
- a double
-
gammaPdf
public static double gammaPdf(double x, double a) gammaPdf.
- Parameters:
x
- a doublea
- a double- Returns:
- a double
-
normalPdf
public static double normalPdf(double x) normalPdf.
- Parameters:
x
- a double- Returns:
- a double
-
poissonPmf
public static double poissonPmf(int k, double lambda) poissonPmf.
- Parameters:
k
- a intlambda
- a double- Returns:
- a double
-
tPdf
public static double tPdf(double x, double a) tPdf.
- Parameters:
x
- a doublea
- a double- Returns:
- a double
-
uniformSeeds
public static void uniformSeeds(long a, long b) uniformSeeds.
- Parameters:
a
- a longb
- a long
-
uniformRand
public static double uniformRand()uniformRand.
- Returns:
- a double
-
bernoulliRand
public static int bernoulliRand(double p) bernoulliRand.
- Parameters:
p
- a double- Returns:
- a int
-
poissonRand
public static int poissonRand(double xm) Poisson random generator from Numerical Recipes- Parameters:
xm
- a double- Returns:
- a int
-
binomialRand
public static int binomialRand(int n, double pp) Binomial random generator from Numerical Recipes- Parameters:
n
- a intpp
- a double- Returns:
- a int
-
normalRand
public static double normalRand()Normal random generator- Returns:
- a double
-
cauchyRand
public static double cauchyRand()Cauchy random generator.- Returns:
- a double
-
gammaRand
public static double gammaRand(double a) Gamma random generator.- Parameters:
a
- a double- Returns:
- a double
-
chisqRand
public static double chisqRand(double df) Chi square random generator.- Parameters:
df
- a double- Returns:
- a double
-
tRand
public static double tRand(double df) T distribution random generator.- Parameters:
df
- a double- Returns:
- a double
-
betaRand
public static double betaRand(double a, double b) Beta distribution random generator.- Parameters:
a
- a doubleb
- a double- Returns:
- a double
-
fRand
public static double fRand(double ndf, double ddf) F distribution random generator.- Parameters:
ndf
- a doubleddf
- a double- Returns:
- a double
-
biNormalCdf
public static double biNormalCdf(double ah, double ak, double r) Bivariate normal CDF. Adapted from statlib, file general/gaut.c, by Ajay Shah. Adaptation for Java found here --November 1st 2003, Ricardo Silva- Parameters:
ah
- upper bound 1ak
- upper bound 1r
- correlatiohn- Returns:
- a double
-
multinormalProb
public static double multinormalProb(double[] a, double[] b, double[][] cov) Compute the probability over a rectangular region with correlation matrix c. Algorithm extracted from Alan Genz: Numerical Computation of Multivariate Normal Probabilities; revised version published in J. Comp. Graph Stat. 1 (1992), pp. 141-149. http://www.math.wsu.edu/faculty/genz/homepage Warning: this method has the side effect of changing the order of the elements in the arrays given as input. --November 3st 2003, Ricardo Silva- Parameters:
a
- lower bounds (use Double.NEGATIVE_INFINITY if necessary)b
- upper bounds (use Double.POSITIVE_INFINITY if necessary)cov
- an array of objects- Returns:
- a double
-