49 private static final int NKOLMO = 100000;
55 public Function(
int n,
double u) {
60 public double evaluate(
double x) {
76 public double cdf(
double x) {
80 public double barF(
double x) {
92 public static double density(
int n,
double x) {
94 double Res = densConnue(n, x);
99 Res = (
cdf(n, x + EPS) -
cdf(n, x - EPS)) / (2.0 * EPS);
105 private static double Pelz(
int n,
double x) {
113 final double EPS = 1.0e-10;
114 final double RACN = Math.sqrt((
double) n);
115 final double z = RACN * x;
116 final double z2 = z * z;
117 final double z4 = z2 * z2;
118 final double z6 = z4 * z2;
119 final double C2PI = 2.506628274631001;
120 final double DPI2 = 1.2533141373155001;
121 final double PI2 = Math.PI * Math.PI;
122 final double PI4 = PI2 * PI2;
123 final double w = PI2 / (2.0 * z * z);
124 double ti, term, tom;
131 while (j <= JMAX && term > EPS * sum) {
133 term = Math.exp(-ti * ti * w);
142 while (j <= JMAX && Math.abs(term) > EPS * Math.abs(tom)) {
144 term = (PI2 * ti * ti - z2) * Math.exp(-ti * ti * w);
148 sum += tom * DPI2 / (RACN * 3.0 * z4);
153 while (j <= JMAX && Math.abs(term) > EPS * Math.abs(tom)) {
155 term = 6 * z6 + 2 * z4 + PI2 * (2 * z4 - 5 * z2) * ti * ti + PI4 * (1 - 2 * z2) * ti * ti * ti * ti;
156 term *= Math.exp(-ti * ti * w);
160 sum += tom * DPI2 / (n * 36.0 * z * z6);
165 while (j <= JMAX && term > EPS * tom) {
167 term = PI2 * ti * ti * Math.exp(-ti * ti * w);
171 sum -= tom * DPI2 / (n * 18.0 * z * z2);
176 while (j <= JMAX && Math.abs(term) > EPS * Math.abs(tom)) {
179 term = -30 * z6 - 90 * z6 * z2 + PI2 * (135 * z4 - 96 * z6) * ti + PI4 * (212 * z4 - 60 * z2) * ti * ti
180 + PI2 * PI4 * ti * ti * ti * (5 - 30 * z2);
181 term *= Math.exp(-ti * w);
185 sum += tom * DPI2 / (RACN * n * 3240.0 * z4 * z6);
190 while (j <= JMAX && Math.abs(term) > EPS * Math.abs(tom)) {
192 term = (3 * PI2 * ti * z2 - PI4 * ti * ti) * Math.exp(-ti * w);
196 sum += tom * DPI2 / (RACN * n * 108.0 * z6);
203 private static void CalcFloorCeil(
int n,
214 double w = Math.ceil(t) - t;
217 for (i = 2; i <= 2 * n + 2; i += 2)
218 Atflo[i] = i / 2 - 2 - ell;
219 for (i = 1; i <= 2 * n + 2; i += 2)
220 Atflo[i] = i / 2 - 1 - ell;
222 for (i = 2; i <= 2 * n + 2; i += 2)
223 Atcei[i] = i / 2 + ell;
224 for (i = 1; i <= 2 * n + 2; i += 2)
225 Atcei[i] = i / 2 + 1 + ell;
227 }
else if (z > 0.0) {
228 for (i = 1; i <= 2 * n + 2; i++)
229 Atflo[i] = i / 2 - 1 - ell;
231 for (i = 2; i <= 2 * n + 2; i++)
232 Atcei[i] = i / 2 + ell;
236 for (i = 2; i <= 2 * n + 2; i += 2)
237 Atflo[i] = i / 2 - 1 - ell;
238 for (i = 1; i <= 2 * n + 2; i += 2)
239 Atflo[i] = i / 2 - ell;
241 for (i = 2; i <= 2 * n + 2; i += 2)
242 Atcei[i] = i / 2 - 1 + ell;
243 for (i = 1; i <= 2 * n + 2; i += 2)
244 Atcei[i] = i / 2 + ell;
252 for (i = 4; i <= 2 * n + 1; i++)
259 private static double Pomeranz(
int n,
double x) {
261 final double EPS = 1.0e-15;
263 final double RENO = Math.scalb(1.0, ENO);
265 final double t = n * x;
266 double w, sum, minsum;
269 int jlow, jup, klow, kup, kup0;
270 double[] A =
new double[2 * n + 3];
271 double[] Atflo =
new double[2 * n + 3];
272 double[] Atcei =
new double[2 * n + 3];
273 double[][] V =
new double[2][n + 2];
274 double[][] H =
new double[4][n + 2];
276 CalcFloorCeil(n, t, A, Atflo, Atcei);
278 for (j = 1; j <= n + 1; j++)
280 for (j = 2; j <= n + 1; j++)
288 for (j = 1; j <= n + 1; j++)
289 H[0][j] = w * H[0][j - 1] / j;
292 w = (1.0 - 2.0 * A[2]) / n;
293 for (j = 1; j <= n + 1; j++)
294 H[1][j] = w * H[1][j - 1] / j;
298 for (j = 1; j <= n + 1; j++)
299 H[2][j] = w * H[2][j - 1] / j;
302 for (j = 1; j <= n + 1; j++)
307 for (i = 2; i <= 2 * n + 2; i++) {
308 jlow = (int) (2 + Atflo[i]);
311 jup = (int) (Atcei[i]);
315 klow = (int) (2 + Atflo[i - 1]);
318 kup0 = (int) (Atcei[i - 1]);
321 w = (A[i] - A[i - 1]) / n;
323 for (j = 0; j < 4; j++) {
324 if (Math.abs(w - H[j][1]) <= EPS) {
334 for (j = jlow; j <= jup; j++) {
339 for (k = kup; k >= klow; k--)
340 sum += V[r1][k] * H[s][j - k];
346 if (minsum < 1.0e-280) {
348 for (j = jlow; j <= jup; j++)
355 w = Num.lnFactorial(n) - coreno * ENO * Num.LN2 + Math.log(sum);
379 public static double cdf(
int n,
double x) {
380 double u = cdfConnu(n, x);
384 final double w = n * x * x;
387 return DurbinMatrix(n, x);
389 return Pomeranz(n, x);
390 return 1.0 -
barF(n, x);
393 if ((w * x * n <= 7.0) && (n <= NKOLMO))
394 return DurbinMatrix(n, x);
412 public static double barF(
int n,
double x) {
413 double v = barFConnu(n, x);
417 final double w = n * x * x;
420 return 1.0 -
cdf(n, x);
428 return 1.0 -
cdf(n, x);
437 double Res = inverseConnue(n, u);
440 Function f =
new Function(n, u);