25package umontreal.ssj.probdist;
50 private double lambda;
52 private static class Optim
implements Lmder_fcn {
53 protected double[] xi;
56 public Optim(
double[] x,
int n) {
58 this.xi =
new double[n];
59 System.arraycopy(x, 0, this.xi, 0, n);
62 public void fcn(
int m,
int n,
double[] x,
double[] fvec,
double[][] fjac,
int iflag[]) {
64 final double BIG = 1.0e100;
79 for (
int i = 0; i < n; i++)
80 sum += (1.0 / (1.0 + Math.exp(x[2] * (xi[i] - x[1]))));
81 fvec[1] = sum - n / 2.0;
84 for (
int i = 0; i < n; i++) {
85 prod = x[2] * (xi[i] - x[1]);
86 sum -= prod * Math.tanh(prod / 2.0);
89 }
else if (iflag[1] == 2) {
91 for (
int i = 0; i < n; i++) {
92 prod = Math.exp(x[2] * (xi[i] - x[1]));
93 sum -= x[2] * prod / ((1 + prod) * (1 + prod));
98 for (
int i = 0; i < n; i++) {
99 prod = Math.exp(x[2] * (xi[i] - x[1]));
100 sum -= (xi[i] - x[1]) * prod / ((1 + prod) * (1 + prod));
105 for (
int i = 0; i < n; i++) {
106 prod = Math.exp(x[2] * (xi[i] - x[1]));
107 sum -= (x[2] * ((-1.0 + prod) * (1.0 + prod) - (2.0 * (x[2] * (xi[i] - x[1])) * prod)))
108 / ((1.0 + prod) * (1.0 + prod));
113 for (
int i = 0; i < n; i++) {
114 prod = Math.exp(x[2] * (xi[i] - x[1]));
115 sum -= ((x[1] - xi[1]) * ((-1.0 + prod) * (1.0 + prod) - (2.0 * (x[2] * (xi[i] - x[1])) * prod)))
116 / ((1.0 + prod) * (1.0 + prod));
141 return density(alpha, lambda, x);
144 public double cdf(
double x) {
145 return cdf(alpha, lambda, x);
149 return barF(alpha, lambda, x);
165 return LogisticDist.getStandardDeviation(alpha, lambda);
171 public static double density(
double alpha,
double lambda,
double x) {
173 throw new IllegalArgumentException(
"lambda <= 0");
174 double z = lambda * (x - alpha);
176 double v = Math.exp(-z);
177 return lambda * v / ((1.0 + v) * (1.0 + v));
179 return lambda * Math.exp(z);
185 public static double cdf(
double alpha,
double lambda,
double x) {
187 throw new IllegalArgumentException(
"lambda <= 0");
188 double z = lambda * (x - alpha);
190 return 1.0 / (1.0 + Math.exp(-z));
197 public static double barF(
double alpha,
double lambda,
double x) {
199 throw new IllegalArgumentException(
"lambda <= 0");
200 double z = lambda * (x - alpha);
202 return 1.0 / (1.0 + Math.exp(z));
209 public static double inverseF(
double alpha,
double lambda,
double u) {
211 throw new IllegalArgumentException(
"lambda <= 0");
212 if (u < 0.0 || u > 1.0)
213 throw new IllegalArgumentException(
"u not in [0, 1]");
215 return Double.POSITIVE_INFINITY;
217 return Double.NEGATIVE_INFINITY;
219 return Math.log(u / (1.0 - u)) / lambda + alpha;
240 public static double[]
getMLE(
double[] x,
int n) {
242 throw new IllegalArgumentException(
"n <= 0");
245 for (
int i = 0; i < n; i++)
248 double[] param =
new double[3];
249 param[1] = sum / (double) n;
252 for (
int i = 0; i < n; i++)
253 sum += ((x[i] - param[1]) * (x[i] - param[1]));
255 param[2] = Math.sqrt(Math.PI * Math.PI * n / (3.0 * sum));
257 double[] fvec =
new double[3];
258 double[][] fjac =
new double[3][3];
259 int[] iflag =
new int[2];
260 int[] info =
new int[2];
261 int[] ipvt =
new int[3];
262 Optim system =
new Optim(x, n);
264 Minpack_f77.lmder1_f77(system, 2, 2, param, fvec, fjac, 1e-5, info, ipvt);
266 double parameters[] =
new double[2];
267 parameters[0] = param[1];
268 parameters[1] = param[2];
283 double parameters[] =
getMLE(x, n);
293 public static double getMean(
double alpha,
double lambda) {
295 throw new IllegalArgumentException(
"lambda <= 0");
310 throw new IllegalArgumentException(
"lambda <= 0");
312 return ((Math.PI * Math.PI / 3) * (1 / (lambda * lambda)));
323 throw new IllegalArgumentException(
"lambda <= 0");
325 return (Math.sqrt(1.0 / 3.0) * Math.PI / lambda);
347 throw new IllegalArgumentException(
"lambda <= 0");
349 this.lambda = lambda;
357 double[] retour = { alpha, lambda };
365 return getClass().getSimpleName() +
" : alpha = " + alpha +
", lambda = " + lambda;
Classes implementing continuous distributions should inherit from this base class.
double getVariance()
Returns the variance.
static double getMean(double alpha, double lambda)
Computes and returns the mean of the logistic distribution with parameters and .
static double[] getMLE(double[] x, int n)
Estimates the parameters of the logistic distribution using the maximum likelihood method,...
double[] getParams()
Return a table containing the parameters of the current distribution.
static double density(double alpha, double lambda, double x)
Computes the density function .
double cdf(double x)
Returns the distribution function .
LogisticDist()
Constructs a LogisticDist object with default parameters.
static double getStandardDeviation(double alpha, double lambda)
Computes and returns the standard deviation of the logistic distribution with parameters and .
LogisticDist(double alpha, double lambda)
Constructs a LogisticDist object with parameters = alpha and = lambda.
double density(double x)
Returns , the density evaluated at .
static double barF(double alpha, double lambda, double x)
Computes the complementary distribution function .
double getStandardDeviation()
Returns the standard deviation.
double getLambda()
Returns the parameter of this object.
double barF(double x)
Returns the complementary distribution function.
double getMean()
Returns the mean.
static double getVariance(double alpha, double lambda)
Computes and returns the variance of the logistic distribution with parameters.
static LogisticDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a logistic distribution with parameters.
double inverseF(double u)
Returns the inverse distribution function .
void setParams(double alpha, double lambda)
Sets the parameters and of this object.
static double inverseF(double alpha, double lambda, double u)
Computes the inverse distribution function .
String toString()
Returns a String containing information about the current distribution.
double getAlpha()
Return the parameter of this object.
static double cdf(double alpha, double lambda, double x)
Computes the distribution function .