25package umontreal.ssj.probdist;
27import umontreal.ssj.util.*;
28import umontreal.ssj.functions.MathFunction;
50 private static final double XSEPARE = 0.15;
51 private static final double PI = Math.PI;
52 private static final int JMAX = 10;
59 public Function(
int n,
double u) {
64 public double evaluate(
double x) {
69 private static double cdfn(
int n,
double x) {
72 double v = Math.exp(-0.125 / x);
77 double a = (2 * j + 1) * (2 * j + 1);
78 terme = Math.pow(v, (
double) (2 * j + 1) * (2 * j + 1));
79 double der = terme * (a - 4.0 * x) / (8.0 * x * x);
80 somme += (5.0 * x - 1.0 / 12.0) * der / 12.0;
81 der = terme * (a * a - 24.0 * a * x + 48.0 * x * x) / (64.0 * x * x * x * x);
82 somme += x * x * der / 6.0;
84 }
while (!(terme <= Math.abs(somme) *
Num.
DBL_EPSILON || j > JMAX));
86 System.err.println(x +
": watsonU: somme 1/n has not converged");
88 v = -2.0 * somme / (n * Math.sqrt(2.0 * PI * x));
103 public double cdf(
double x) {
130 public static double density(
int n,
double x) {
132 throw new IllegalArgumentException(
"n < 2");
134 if (x <= 1.0 / (12.0 * n) || x >= n / 12.0 || x >= XBIG)
137 final double EPS = 1.0 / 100.0;
138 return (
cdf(n, x + EPS) -
cdf(n, x - EPS)) / (2.0 * EPS);
168 public static double cdf(
int n,
double x) {
170 throw new IllegalArgumentException(
"n < 2");
172 if (x <= 1.0 / (12.0 * n))
174 if (x > 3.95 || x >= n / 12.0)
182 return 2.0 * Math.sqrt(2.0 * x - 1.0 / 12.0);
186 return 1.0 -
barF(n, x);
190 double v = Math.exp(-0.125 / x);
195 terme = Math.pow(v, (
double) (2 * j - 1) * (2 * j - 1));
198 }
while (!(terme <= somme * Num.DBL_EPSILON || j > JMAX));
200 System.err.println(x +
": watsonU: sum2 has not converged");
202 v = 2.0 * somme / Math.sqrt(2.0 * PI * x);
215 public static double barF(
int n,
double x) {
217 throw new IllegalArgumentException(
"n < 2");
219 if (x <= 1.0 / (12.0 * n))
221 if (x >= XBIG || x >= n / 12.0)
225 return 1.0 - 2.0 * Math.sqrt(2.0 * x - 1.0 / 12.0);
230 double v = Math.exp(-2.0 * PI * PI * x);
237 terme = Math.pow(v, (
double) j * j);
238 somme += signe * terme;
239 double h = 2 * j * PI * x;
240 ter = (5.0 * x - h * h - 1.0 / 12.0) * j * j;
241 son += signe * terme * ter;
244 }
while (!(terme < Num.DBL_EPSILON || j > JMAX));
246 System.err.println(x +
": watsonU: sum1 has not converged");
247 v = 2.0 * somme + PI * PI * son / (3.0 * n);
255 return (1.0 -
cdf(n, x));
265 throw new IllegalArgumentException(
"n < 2");
266 if (u < 0.0 || u > 1.0)
267 throw new IllegalArgumentException(
"u must be in [0,1]");
271 return 1.0 / (12.0 * n);
274 return 1.0 / 24.0 + u * u / 8.0;
276 Function f =
new Function(n, u);
296 return (n - 1) / (360.0 * n);
321 throw new IllegalArgumentException(
"n < 2");
323 supportA = 1.0 / (12.0 * n);
331 double[] retour = { n };
339 return getClass().getSimpleName() +
" : n = " + n;
Classes implementing continuous distributions should inherit from this base class.
double getStandardDeviation()
Returns the standard deviation.
double barF(double x)
Returns the complementary distribution function.
double getVariance()
Returns the variance.
int getN()
Returns the parameter of this object.
double density(double x)
Returns , the density evaluated at .
static double getMean(int n)
Returns the mean of the Watson distribution with parameter.
WatsonUDist(int n)
Constructs a Watson U distribution for a sample of size .
static double getVariance(int n)
Returns the variance of the Watson distribution with parameter .
static double barF(int n, double x)
Computes the complementary distribution function , where is the Watson distribution with parameter ...
static double inverseF(int n, double u)
Computes , where is the Watson.
String toString()
Returns a String containing information about the current distribution.
double[] getParams()
Return an array containing the parameter of this object.
double getMean()
Returns the mean.
double inverseF(double u)
Returns the inverse distribution function .
static double density(int n, double x)
Computes the density of the Watson U distribution with parameter .
static double cdf(int n, double x)
Computes the Watson distribution function, i.e.
double cdf(double x)
Returns the distribution function .
static double getStandardDeviation(int n)
Returns the standard deviation of the Watson distribution with parameter .
void setN(int n)
Sets the parameter of this object.
This class provides various constants and methods to compute numerical quantities such as factorials,...
static final double DBL_EPSILON
Difference between 1.0 and the smallest double greater than 1.0.
This class provides numerical methods to solve non-linear equations.
static double brentDekker(double a, double b, MathFunction f, double tol)
Computes a root of the function in f using the Brent-Dekker method.
This interface should be implemented by classes which represent univariate mathematical functions.