25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
28import umontreal.ssj.util.Misc;
53 private static class Optim
implements Uncmin_methods {
57 public Optim(
double[] x,
int n) {
59 this.xi =
new double[n];
60 System.arraycopy(x, 0, this.xi, 0, n);
63 public double f_to_minimize(
double[] p) {
64 if ((p[1] <= 0.0) || (p[2] <= 0.0))
68 for (
int i = 0; i < n; i++) {
69 double tmp =
density(p[1], p[2], xi[i]);
78 public void gradient(
double[] x,
double[] g) {
81 public void hessian(
double[] x,
double[][] h) {
97 public double cdf(
double x) {
98 return cdf(alpha, beta, x);
102 return barF(alpha, beta, x);
128 public static double density(
double alpha,
double beta,
double x) {
132 throw new IllegalArgumentException(
"alpha <= 0");
134 throw new IllegalArgumentException(
"beta <= 0");
135 if (x <= 0.0 || x >= Double.MAX_VALUE / 2.0)
139 double v = Math.pow(x / beta, alpha);
140 denominateur = 1.0 + v;
141 denominateur *= denominateur * beta;
142 return alpha * v * beta / (x * denominateur);
144 double v = Math.pow(beta / x, alpha);
145 denominateur = 1.0 + v;
146 denominateur *= denominateur * beta;
147 return alpha * v * beta / (x * denominateur);
158 public static double cdf(
double alpha,
double beta,
double x) {
160 throw new IllegalArgumentException(
"alpha <= 0");
162 throw new IllegalArgumentException(
"beta <= 0");
165 if (x >= Double.MAX_VALUE / 2.0)
169 return 1.0 / (1.0 + Math.pow(1.0 / z, alpha));
170 double v = Math.pow(z, alpha);
171 return v / (v + 1.0);
181 public static double barF(
double alpha,
double beta,
double x) {
185 throw new IllegalArgumentException(
"alpha <= 0");
187 throw new IllegalArgumentException(
"beta <= 0");
190 if (x >= Double.MAX_VALUE / 2.0)
195 return 1.0 / (1.0 + Math.pow(z, alpha));
196 double v = Math.pow(1.0 / z, alpha);
197 return v / (v + 1.0);
204 public static double inverseF(
double alpha,
double beta,
double u) {
206 throw new IllegalArgumentException(
"alpha <= 0");
208 throw new IllegalArgumentException(
"beta <= 0");
209 if (u < 0.0 || u > 1.0)
210 throw new IllegalArgumentException(
"u not in (0, 1]");
212 return Double.POSITIVE_INFINITY;
217 return (beta * Math.pow(u / (1.0 - u), 1.0 / alpha));
219 return (beta / Math.pow((1.0 - u) / u, 1.0 / alpha));
236 public static double[]
getMLE(
double[] x,
int n) {
240 throw new IllegalArgumentException(
"n <= 0");
242 Optim system =
new Optim(x, n);
244 double[] parameters =
new double[2];
245 double[] xpls =
new double[3];
246 double[] param =
new double[3];
247 double[] fpls =
new double[3];
248 double[] gpls =
new double[3];
249 int[] itrcmd =
new int[2];
250 double[][] a =
new double[3][3];
251 double[] udiag =
new double[3];
256 throw new IllegalArgumentException(
"median < 0");
260 int m = Math.round((
float) n / 4.0f);
264 throw new IllegalArgumentException(
"x[i] < 0");
266 param[1] = Math.log(3) / (Math.log(param[2]) - Math.log(q1));
270 Uncmin_f77.optif0_f77(2, param, system, xpls, fpls, gpls, itrcmd, a, udiag);
272 for (
int i = 0; i < 2; i++)
273 parameters[i] = xpls[i + 1];
288 double parameters[] =
getMLE(x, n);
301 public static double getMean(
double alpha,
double beta) {
305 throw new IllegalArgumentException(
"alpha <= 1");
307 throw new IllegalArgumentException(
"beta <= 0");
309 theta = Math.PI / alpha;
311 return (beta * theta / Math.sin(theta));
330 throw new IllegalArgumentException(
"alpha <= 2");
332 throw new IllegalArgumentException(
"beta <= 0");
334 theta = Math.PI / alpha;
336 return (beta * beta * theta * ((2.0 / Math.sin(2.0 * theta)) - (theta / (Math.sin(theta) * Math.sin(theta)))));
368 throw new IllegalArgumentException(
"alpha <= 0");
370 throw new IllegalArgumentException(
"beta <= 0");
382 double[] retour = { alpha, beta };
390 return getClass().getSimpleName() +
" : alpha = " + alpha +
", beta = " + beta;
Classes implementing continuous distributions should inherit from this base class.
Extends DiscreteDistribution to an empirical distribution function, based on the observations (sorte...
double getMedian()
Returns the median.
static double getMean(double alpha, double beta)
Computes and returns the mean of the log-logistic distribution with parameters and.
double getVariance()
Returns the variance.
static double getStandardDeviation(double alpha, double beta)
Computes and returns the standard deviation of the log-logistic distribution with parameters and .
double getAlpha()
Return the parameter of this object.
double getMean()
Returns the mean.
double cdf(double x)
Returns the distribution function .
double getStandardDeviation()
Returns the standard deviation.
static double getVariance(double alpha, double beta)
Computes and returns the variance.
double density(double x)
Returns , the density evaluated at .
static double inverseF(double alpha, double beta, double u)
Computes the inverse of the log-logistic distribution with parameters and .
static LoglogisticDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a log-logistic distribution with parameters and estimated using the maxim...
double inverseF(double u)
Returns the inverse distribution function .
double barF(double x)
Returns the complementary distribution function.
double[] getParams()
Return a table containing the parameters of the current distribution.
static double barF(double alpha, double beta, double x)
Computes the complementary distribution function ( Fbarloglogistic ) of the log-logistic distribution...
void setParams(double alpha, double beta)
Sets the parameters and of this object.
static double cdf(double alpha, double beta, double x)
Computes the distribution function ( Floglogistic ) of the log-logistic distribution with parameters.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the log-logistic distribution using the maximum likelihood method,...
LoglogisticDist(double alpha, double beta)
Constructs a log-logistic distribution with parameters and .
String toString()
Returns a String containing information about the current distribution.
static double density(double alpha, double beta, double x)
Computes the density function ( floglogistic ) for a log-logisitic distribution with parameters.
double getBeta()
Returns the parameter of this object.
This class provides miscellaneous functions that are hard to classify.
static double quickSelect(double[] A, int n, int k)
Returns the smallest item of the array of size.