25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
54 protected double alpha1;
55 protected double alpha2;
56 protected double beta;
57 protected double logBeta;
59 private static class Optim
implements Uncmin_methods {
63 public Optim(
double[] x,
int n) {
65 this.x =
new double[n];
66 System.arraycopy(x, 0, this.x, 0, n);
69 public double f_to_minimize(
double[] param) {
71 if ((param[1] <= 0.0) || (param[2] <= 0.0) || (param[3] <= 0.0))
75 double sumLog1_Y = 0.0;
76 for (
int i = 0; i < n; i++) {
78 sumLogY += Math.log(x[i] / param[3]);
81 sumLog1_Y += Math.log1p(x[i] / param[3]);
84 return (n * (Math.log(param[3]) +
Num.
lnBeta(param[1], param[2])) - (param[1] - 1.0) * sumLogY
85 + (param[1] + param[2]) * sumLog1_Y);
88 public void gradient(
double[] x,
double[] g) {
91 public void hessian(
double[] x,
double[][] h) {
106 return Math.exp((alpha1 - 1.0) * Math.log(x / beta) - (logBeta + (alpha1 + alpha2) * Math.log1p(x / beta)))
110 public double cdf(
double x) {
111 return cdf(alpha1, alpha2, beta, x);
115 return barF(alpha1, alpha2, beta, x);
119 return inverseF(alpha1, alpha2, beta, u);
123 return getMean(alpha1, alpha2, beta);
139 public static double density(
double alpha1,
double alpha2,
double beta,
double x) {
141 throw new IllegalArgumentException(
"alpha1 <= 0");
143 throw new IllegalArgumentException(
"alpha2 <= 0");
145 throw new IllegalArgumentException(
"beta <= 0");
149 return Math.exp((alpha1 - 1.0) * Math.log(x / beta)
150 - (
Num.
lnBeta(alpha1, alpha2) + (alpha1 + alpha2) * Math.log1p(x / beta))) / beta;
158 public static double cdf(
double alpha1,
double alpha2,
double beta,
double x) {
160 throw new IllegalArgumentException(
"alpha1 <= 0");
162 throw new IllegalArgumentException(
"alpha2 <= 0");
164 throw new IllegalArgumentException(
"beta <= 0");
168 return BetaDist.
cdf(alpha1, alpha2, x / (x + beta));
177 public static double barF(
double alpha1,
double alpha2,
double beta,
double x) {
179 throw new IllegalArgumentException(
"alpha1 <= 0");
181 throw new IllegalArgumentException(
"alpha2 <= 0");
183 throw new IllegalArgumentException(
"beta <= 0");
196 public static double inverseF(
double alpha1,
double alpha2,
double beta,
double u) {
198 throw new IllegalArgumentException(
"alpha1 <= 0");
200 throw new IllegalArgumentException(
"alpha2 <= 0");
202 throw new IllegalArgumentException(
"beta <= 0");
206 return ((y * beta) / (1.0 - y));
223 public static double[]
getMLE(
double[] x,
int n) {
225 throw new IllegalArgumentException(
"n <= 0");
227 double[] parameters =
new double[3];
228 double[] xpls =
new double[4];
229 double[] param =
new double[4];
230 double[] fpls =
new double[4];
231 double[] gpls =
new double[4];
232 int[] itrcmd =
new int[2];
233 double[][] h =
new double[4][4];
234 double[] udiag =
new double[4];
236 Optim system =
new Optim(x, n);
241 for (
int i = 0; i < n; i++) {
243 mean2 += x[i] * x[i];
244 mean3 += x[i] * x[i] * x[i];
250 double r1 = mean2 / (mean * mean);
251 double r2 = mean2 * mean / mean3;
253 param[1] = -(2.0 * (-1.0 + r1 * r2)) / (-2.0 + r1 + r1 * r2);
256 param[2] = (-3.0 - r2 + 4.0 * r1 * r2) / (-1.0 - r2 + 2.0 * r1 * r2);
259 param[3] = (param[2] - 1.0) * mean / param[1];
263 Uncmin_f77.optif0_f77(3, param, system, xpls, fpls, gpls, itrcmd, h, udiag);
265 for (
int i = 0; i < 3; i++)
266 parameters[i] = xpls[i + 1];
281 double parameters[] =
getMLE(x, n);
282 return new Pearson6Dist(parameters[0], parameters[1], parameters[2]);
290 public static double getMean(
double alpha1,
double alpha2,
double beta) {
292 throw new IllegalArgumentException(
"alpha1 <= 0");
294 throw new IllegalArgumentException(
"alpha2 <= 1");
296 throw new IllegalArgumentException(
"beta <= 0");
298 return ((beta * alpha1) / (alpha2 - 1.0));
307 public static double getVariance(
double alpha1,
double alpha2,
double beta) {
309 throw new IllegalArgumentException(
"alpha1 <= 0");
311 throw new IllegalArgumentException(
"alpha2 <= 2");
313 throw new IllegalArgumentException(
"beta <= 0");
315 return (((beta * beta) * alpha1 * (alpha1 + alpha2 - 1.0)) / ((alpha2 - 1.0) * (alpha2 - 1.0) * (alpha2 - 2.0)));
325 return Math.sqrt(
getVariance(alpha1, alpha2, beta));
354 public void setParam(
double alpha1,
double alpha2,
double beta) {
356 throw new IllegalArgumentException(
"alpha1 <= 0");
358 throw new IllegalArgumentException(
"alpha2 <= 0");
360 throw new IllegalArgumentException(
"beta <= 0");
362 this.alpha1 = alpha1;
363 this.alpha2 = alpha2;
373 double[] retour = { alpha1, alpha2, beta };
381 return getClass().getSimpleName() +
" : alpha1 = " + alpha1 +
", alpha2 = " + alpha2 +
", beta = " + beta;
Extends the class ContinuousDistribution for the beta distribution.
double inverseF(double u)
Returns the inverse distribution function .
double barF(double x)
Returns the complementary distribution function.
double cdf(double x)
Returns the distribution function .
Classes implementing continuous distributions should inherit from this base class.
double cdf(double x)
Returns the distribution function .
double[] getParams()
Return a table containing the parameters of the current distribution.
double inverseF(double u)
Returns the inverse distribution function .
double getAlpha2()
Returns the parameter of this object.
Pearson6Dist(double alpha1, double alpha2, double beta)
Constructs a Pearson6Dist object with parameters = alpha1, = alpha2 and = beta.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the Pearson VI distribution using the maximum likelihood method,...
static double density(double alpha1, double alpha2, double beta, double x)
Computes the density function of a Pearson VI distribution with shape parameters and ,...
double getMean()
Returns the mean.
static double getStandardDeviation(double alpha1, double alpha2, double beta)
Computes and returns the standard deviation of a Pearson VI distribution with shape parameters and.
double getAlpha1()
Returns the parameter of this object.
static double getVariance(double alpha1, double alpha2, double beta)
Computes and returns the variance of a Pearson VI distribution with shape parameters and ,...
String toString()
Returns a String containing information about the current distribution.
void setParam(double alpha1, double alpha2, double beta)
Sets the parameters , and.
double getVariance()
Returns the variance.
double barF(double x)
Returns the complementary distribution function.
double getBeta()
Returns the parameter of this object.
static double inverseF(double alpha1, double alpha2, double beta, double u)
Computes the inverse distribution function of a Pearson VI distribution with shape parameters and.
static double cdf(double alpha1, double alpha2, double beta, double x)
Computes the distribution function of a Pearson VI distribution with shape parameters and ,...
double getStandardDeviation()
Returns the standard deviation.
static Pearson6Dist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a Pearson VI distribution with parameters.
double density(double x)
Returns , the density evaluated at .
static double barF(double alpha1, double alpha2, double beta, double x)
Computes the complementary distribution function of a Pearson VI distribution with shape parameters ...
static double getMean(double alpha1, double alpha2, double beta)
Computes and returns the mean of a Pearson VI distribution with shape parameters and ,...
This class provides various constants and methods to compute numerical quantities such as factorials,...
static double lnBeta(double lam, double nu)
Computes the natural logarithm of the Beta function .