SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
FDist.java
1/*
2 * Class: FDist
3 * Description: Empirical distributions
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.gof;
26
33public class FDist {
34 private FDist() {
35 }
36
68 public static double kolmogorovSmirnovPlusJumpOne(int N, double a, double x) {
69 final double EPSILONLR = 1.E-15;
70 final double EPSILON = 1.0E-290;
71 final double NXAPARAM = 6.5; // frontier: alternating series
72 double LogCom;
73 double q, p1, q1;
74 double Sum = 0.0;
75 double term;
76 double Njreal;
77 double jreal;
78 int Sign;
79 int j;
80 int jmax;
81
82 if (N < 1)
83 throw new IllegalArgumentException("Calling kolmogorovSmirnovPlusJumpOne " + "with N < 1");
84 if (a >= 1.0 || a <= 0.0)
85 throw new IllegalArgumentException("Calling kolmogorovSmirnovPlusJumpOne " + "with a outside (0, 1)");
86 if (x <= 0.0)
87 return 0.0;
88 if (x + a >= 1.0)
89 return 1.0;
90 LogCom = Math.log((double) N);
91
92 // --------------------------------------------------------------------
93 // the alternating series is stable and fast for N*(x + a) very small
94 // --------------------------------------------------------------------
95 if (N * (x + a) < NXAPARAM && a + x < 0.5) {
96 jmax = (int) (N * (x + a));
97 for (j = 1; j <= jmax; j++) {
98 jreal = j;
99 Njreal = N - j;
100 q = jreal / N - x;
101 if ((q < 0.0 && ((j & 1) != 0)) || ((q > 1.0) && (((N - j - 1) & 1) != 0)))
102 Sign = -1;
103 else
104 Sign = 1;
105
106 // we must avoid log (0.0)
107 q1 = Math.abs(q);
108 p1 = Math.abs(1.0 - q);
109 if (q1 > EPSILON && p1 > EPSILON) {
110 term = LogCom + jreal * Math.log(q1) + (Njreal - 1.0) * Math.log(p1);
111 Sum += Sign * Math.exp(term);
112 }
113 LogCom += Math.log(Njreal / (jreal + 1.0));
114 }
115 // add the term j = 0
116 Sum += Math.exp((N - 1) * Math.log(1.0 + x));
117 return Sum * x;
118 }
119
120 // ---------------------------------------------
121 // For N (x + a) >= NxaParam or (a + x) > 0.5,
122 // use the non-alternating series.
123 // ---------------------------------------------
124
125 // EpsilonLR because the distribution has a jump
126 jmax = (int) (N * (1.0 - a - x - EPSILONLR));
127 for (j = 1; j <= jmax; j++) {
128 jreal = j;
129 Njreal = N - jreal;
130 q = jreal / N + x;
131 if (1.0 - q > EPSILON) {
132 term = LogCom + (jreal - 1.0) * Math.log(q) + Njreal * Math.log(1.0 - q);
133 Sum += Math.exp(term);
134 }
135 LogCom += Math.log(Njreal / (jreal + 1.0));
136 }
137 Sum *= x;
138
139 // add the term j = 0
140 if (1.0 - x > EPSILON)
141 Sum += Math.exp(N * Math.log(1.0 - x));
142 return 1.0 - Sum;
143 }
144
156 public static double scan(int N, double d, int m) {
157 return 1.0 - FBar.scan(N, d, m);
158 }
159}
This class is similar to FDist, except that it provides static methods to compute or approximate the ...
Definition FBar.java:40
static double scan(int n, double d, int m)
Return , where is the scan statistic(see tgla89a, tgla01a  and GofStat.scan ), defined as.
Definition FBar.java:234
static double kolmogorovSmirnovPlusJumpOne(int N, double a, double x)
Similar to umontreal.ssj.probdist.KolmogorovSmirnovPlusDist but for the case where the distribution f...
Definition FDist.java:68
static double scan(int N, double d, int m)
Returns , the distribution function of the scan statistic with parameters and , evaluated at .
Definition FDist.java:156