10package umontreal.ssj.probdistmulti;
12import umontreal.ssj.probdist.NormalDist;
13import umontreal.ssj.util.Num;
26 private static final double TWOPI = 2.0 * Math.PI;
27 private static final double SQRTPI = Math.sqrt(Math.PI);
28 private static final int KMAX = 6;
30 private static double BB[] =
new double[KMAX + 1];
31 private static final double CB[] = { 0.9999936, -0.9992989, 0.9872976, -0.9109973, 0.6829098, -0.3360210,
34 private static double BorthT(
double h,
double a) {
36 final double w = a * h /
Num.
RAC2;
37 final double w2 = w * w;
38 double z = w * Math.exp(-w2);
40 BB[0] = SQRTPI * (Gauss(
Num.
RAC2 * w) - 0.5);
41 for (k = 1; k <= KMAX; ++k) {
42 BB[k] = ((2 * k - 1) * BB[k - 1] - z) / 2.0;
46 final double h2 = h * h / 2.0;
49 for (k = 0; k <= KMAX; ++k) {
50 sum += CB[k] * BB[k] / z;
53 return sum * Math.exp(-h2) / TWOPI;
66 throw new IllegalArgumentException(
"ndig > 15");
86 super(mu1, sigma1, mu2, sigma2, rho);
88 throw new IllegalArgumentException(
"ndig > 15");
97 this(mu1, sigma1, mu2, sigma2, rho, 15);
115 public static double cdf(
double x,
double y,
double rho,
int ndig) {
122 throw new IllegalArgumentException(
"ndig > 15");
123 double b = specialCDF(x, y, rho, 13.0);
128 final boolean SINGLE_FLAG = ndig <= 7 ? true :
false;
129 final double TWO_PI = 2.0 * Math.PI;
130 final double r = rho;
131 final double ah = -x;
132 final double ak = -y;
134 double a2, ap, cn, conex, ex, g2, gh, gk, gw = 0, h2, h4, rr, s1, s2, sgn, sn, sp, sqr, t, temp, w2, wh = 0,
147 rr = (1 - r) * (1 + r);
149 throw new IllegalArgumentException(
"|rho| > 1");
158 else if (ah * ak == 0) {
161 }
else if (ak == 0) {
162 return Math.asin(r) / TWO_PI + 0.25;
170 wk = (ak / ah - r) / sqr;
178 wk = (ah / ak - r) / sqr;
186 if (Math.abs(wk) >= 1)
187 if (Math.abs(wk) == 1) {
188 t = wk * gw * (1 - gw) / 2;
204 b = b - (gw + g2) / 2 + gw * g2;
223 conex = Math.abs(con / wk);
225 cn = ap * s2 / (sn + sp);
227 if (Math.abs(cn) <= conex)
235 t = (Math.atan(wk) - wk * s1) / TWO_PI;
256 public static double cdf(
double mu1,
double sigma1,
double x,
double mu2,
double sigma2,
double y,
double rho,
259 throw new IllegalArgumentException(
"sigma1 <= 0");
261 throw new IllegalArgumentException(
"sigma2 <= 0");
262 double X = (x - mu1) / sigma1;
263 double Y = (y - mu2) / sigma2;
264 return cdf(X, Y, rho, ndig);
275 public static double barF(
double mu1,
double sigma1,
double x,
double mu2,
double sigma2,
double y,
double rho,
278 throw new IllegalArgumentException(
"sigma1 <= 0");
280 throw new IllegalArgumentException(
"sigma2 <= 0");
281 double X = (x - mu1) / sigma1;
282 double Y = (y - mu2) / sigma2;
283 return barF(X, Y, rho, ndig);
291 public static double barF(
double x,
double y,
double rho,
int ndig) {
292 return cdf(-x, -y, rho, ndig);
295 public double cdf(
double x,
double y) {
296 return cdf((x - mu1) / sigma1, (y - mu2) / sigma2, rho, ndigit);
299 public static double cdf(
double x,
double y,
double rho) {
300 return cdf(x, y, rho, 15);
303 public static double cdf(
double mu1,
double sigma1,
double x,
double mu2,
double sigma2,
double y,
double rho) {
304 return cdf(mu1, sigma1, x, mu2, sigma2, y, rho, 15);
307 public double barF(
double x,
double y) {
308 return barF((x - mu1) / sigma1, (y - mu2) / sigma2, rho, ndigit);
311 public static double barF(
double mu1,
double sigma1,
double x,
double mu2,
double sigma2,
double y,
double rho) {
312 return barF(mu1, sigma1, x, mu2, sigma2, y, rho, 15);
315 public static double barF(
double x,
double y,
double rho) {
316 return barF(x, y, rho, 15);
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a (page 80)).
static double cdf01(double x)
Same as cdf(0, 1, x).
BiNormalDist(double rho)
Constructs a BiNormalDist object with default parameters , and correlation.
static double barF(double mu1, double sigma1, double x, double mu2, double sigma2, double y, double rho)
Computes the upper binormal distribution function ( cdf3binormal ) with parameters = mu1,...
static double barF(double mu1, double sigma1, double x, double mu2, double sigma2, double y, double rho, int ndig)
Computes the upper binormal distribution function ( cdf3binormal ) with parameters = mu1,...
BiNormalDonnellyDist(double rho, int ndig)
Constructor with default parameters ,.
static double cdf(double mu1, double sigma1, double x, double mu2, double sigma2, double y, double rho)
Computes the binormal distribution function ( cdf1binormal ) with parameters = mu1,...
double cdf(double x, double y)
Computes the distribution function :
BiNormalDonnellyDist(double mu1, double sigma1, double mu2, double sigma2, double rho, int ndig)
Constructor with parameters = mu1, = mu2, = sigma1, = sigma2,.
BiNormalDonnellyDist(double mu1, double sigma1, double mu2, double sigma2, double rho)
Same as BiNormalDonnellyDist(mu1, sigma1, mu2, sigma2, rho, 15).
static double cdf(double x, double y, double rho, int ndig)
The following methods use the parameter ndig for the number of digits of absolute accuracy.
double barF(double x, double y)
Computes the upper cumulative distribution function.
static double cdf(double mu1, double sigma1, double x, double mu2, double sigma2, double y, double rho, int ndig)
Computes the binormal distribution function ( cdf1binormal ) with parameters = mu1,...
static double cdf(double x, double y, double rho)
Computes the standard binormal distribution ( cdf2binormal ) using the fast Drezner-Wesolowsky method...
static double barF(double x, double y, double rho, int ndig)
Computes the upper standard binormal distribution function ( cdf3binormal ) with parameters = rho an...
static double barF(double x, double y, double rho)
Computes the standard upper binormal distribution with and .
BiNormalDonnellyDist(double rho)
Same as BiNormalDonnellyDist(rho,15).
int decPrec
Defines the target number of decimals of accuracy when approximating a distribution function,...
This class provides various constants and methods to compute numerical quantities such as factorials,...
static final double RAC2
The value of .
static final double TEN_NEG_POW[]
Contains the precomputed negative powers of 10.