25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
28import umontreal.ssj.functions.MathFunction;
49 private double factor;
50 private static final int NLIM1 = 100000;
65 private static double cdfGaver(
int n,
double x) {
68 double v = Math.log1p(x * x / n) / (n - 1.5);
69 double z = -(n - 1) * Math.sqrt(v);
76 private static double invGaver(
int n,
double u) {
80 double q = z / (n - 1.0);
81 double v = q * q * (n - 1.5);
82 double t = Math.sqrt(n * Math.expm1(v));
93 public Function(
double[] x,
int n) {
95 this.xi =
new double[n];
96 System.arraycopy(x, 0, this.xi, 0, n);
99 public double evaluate(
double x) {
103 for (
int i = 0; i < n; i++)
104 sum += Math.log(
density((
int) Math.round(x), xi[i]));
117 return factor * Math.pow(1.0 / (1.0 + x * x / n), (n + 1) / 2.0);
120 public double cdf(
double x) {
149 public static double density(
int n,
double x) {
151 return factor * Math.pow(1.0 / (1.0 + x * x / n), (n + 1) / 2.0);
162 public static double cdf(
int n,
double x) {
164 throw new IllegalArgumentException(
"n < 1");
171 return cdfGaver(n, x);
173 double r = Math.abs(x);
175 r = Math.sqrt(n + x * x);
179 z = 0.5 * (1.0 + x / r);
181 z = 0.5 * n / (r * (r - x));
192 public static double cdf2(
int n,
int d,
double x) {
194 throw new IllegalArgumentException(
"student2: d <= 0");
205 public static double barF(
int n,
double x) {
207 throw new IllegalArgumentException(
"n < 1");
212 double z = Math.abs(x);
214 z = Math.sqrt(2.0 + x * x);
218 return 0.5 * (1.0 - x / z);
220 return 1.0 / (z * (z + x));
235 throw new IllegalArgumentException(
"Student: n < 1");
236 if (u > 1.0 || u < 0.0)
237 throw new IllegalArgumentException(
"Student: u not in [0, 1]");
239 return Double.NEGATIVE_INFINITY;
241 return Double.POSITIVE_INFINITY;
247 return (2.0 * u - 1.0) / Math.sqrt(2.0 * u * (1.0 - u));
250 return invGaver(n, u);
252 return (z - 0.5) * Math.sqrt(n / (z * (1.0 - z)));
265 public static double[]
getMLE(
double[] x,
int m) {
267 double[] parameters =
new double[1];
270 throw new IllegalArgumentException(
"m <= 0");
273 for (
int i = 0; i < m; i++)
277 Function f =
new Function(x, m);
279 double n0 = Math.round((2.0 * var) / (var - 1.0));
280 double fn0 = f.evaluate(n0);
282 double fn1 = f.evaluate(n0 + 1.0);
283 double fn_1 = f.evaluate(n0 - 1.0);
290 while (((y = f.evaluate(n)) > min) && (n >= 1.0)) {
296 }
else if (fn1 > fn0) {
299 while ((y = f.evaluate(n)) > min) {
317 double parameters[] =
getMLE(x, m);
329 throw new IllegalArgumentException(
"n <= 1");
342 throw new IllegalArgumentException(
"n <= 2");
343 return (n / (n - 2.0));
368 throw new IllegalArgumentException(
"n <= 0");
377 double[] retour = { n };
385 return getClass().getSimpleName() +
" : n = " + n;
Specializes the class BetaDist to the case of a symmetrical beta distribution over the interval ,...
double inverseF(double u)
Returns the inverse distribution function .
double cdf(double x)
Returns the distribution function .
Extends the class ContinuousDistribution for the Cauchy distribution tjoh95a (page 299) with locatio...
double inverseF(double u)
Returns the inverse distribution function .
double cdf(double x)
Returns the distribution function .
double barF(double x)
Returns the complementary distribution function.
Classes implementing continuous distributions should inherit from this base class.
Extends the class ContinuousDistribution for the normal distribution (e.g., tjoh95a (page 80)).
static double inverseF01(double u)
Same as inverseF(0, 1, u).
static double cdf01(double x)
Same as cdf(0, 1, x).
static double density(int n, double x)
Computes the density function ( fstudent ) of a Student -distribution with degrees of freedom.
void setN(int n)
Sets the parameter associated with this object.
static double getVariance(int n)
Computes and returns the variance of the Student -distribution with parameter .
double getVariance()
Returns the variance.
static double getMean(int n)
Returns the mean of the Student -distribution with parameter .
static double cdf(int n, double x)
Computes the Student -distribution function with.
StudentDist(int n)
Constructs a StudentDist object with n degrees of freedom.
static double cdf2(int n, int d, double x)
Same as cdf(n, x).
static StudentDist getInstanceFromMLE(double[] x, int m)
Creates a new instance of a Student -distribution with parameter estimated using the maximum likelih...
double getMean()
Returns the mean.
double[] getParams()
Return a table containing the parameter of the current distribution.
static double[] getMLE(double[] x, int m)
Estimates the parameter of the Student -distribution using the maximum likelihood method,...
static double inverseF(int n, double u)
Returns the inverse of Student.
double density(double x)
Returns , the density evaluated at .
double cdf(double x)
Returns the distribution function .
String toString()
Returns a String containing information about the current distribution.
double barF(double x)
Returns the complementary distribution function.
double inverseF(double u)
Returns the inverse distribution function .
double getStandardDeviation()
Returns the standard deviation.
static double getStandardDeviation(int n)
Computes and returns the standard deviation of the Student.
static double barF(int n, double x)
Computes the complementary distribution function with degrees of freedom.
int getN()
Returns the parameter associated with this object.
This class provides various constants and methods to compute numerical quantities such as factorials,...
static double gammaRatioHalf(double x)
Returns the value of the ratio of two gamma functions.
This interface should be implemented by classes which represent univariate mathematical functions.