25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Misc;
51 private static class Optim
implements Uncmin_methods {
55 public Optim(
double[] x,
int n) {
57 this.xi =
new double[n];
58 System.arraycopy(x, 0, this.xi, 0, n);
61 public double f_to_minimize(
double[] p) {
67 for (
int i = 0; i < n; i++)
68 sum -= Math.log(
density(p[1], p[2], xi[i]));
73 public void gradient(
double[] x,
double[] g) {
76 public void hessian(
double[] x,
double[][] h) {
100 public double cdf(
double x) {
101 return cdf(alpha, beta, x);
105 return barF(alpha, beta, x);
121 return CauchyDist.getStandardDeviation(alpha, beta);
127 public static double density(
double alpha,
double beta,
double x) {
129 throw new IllegalArgumentException(
"beta <= 0");
130 double t = (x - alpha) / beta;
131 return 1.0 / (beta * Math.PI * (1 + t * t));
137 public static double cdf(
double alpha,
double beta,
double x) {
139 throw new IllegalArgumentException(
"beta <= 0");
140 double z = (x - alpha) / beta;
142 return Math.atan(-1. / z) / Math.PI;
143 return Math.atan(z) / Math.PI + 0.5;
149 public static double barF(
double alpha,
double beta,
double x) {
151 throw new IllegalArgumentException(
"beta <= 0");
152 double z = (x - alpha) / beta;
154 return Math.atan(1. / z) / Math.PI;
155 return 0.5 - Math.atan(z) / Math.PI;
161 public static double inverseF(
double alpha,
double beta,
double u) {
163 throw new IllegalArgumentException(
"beta <= 0");
164 if (u < 0.0 || u > 1.0)
165 throw new IllegalArgumentException(
"u must be in [0,1]");
167 return Double.NEGATIVE_INFINITY;
169 return Double.POSITIVE_INFINITY;
171 return alpha - 1.0 / Math.tan(Math.PI * u) * beta;
172 return alpha + Math.tan(Math.PI * (u - 0.5)) * beta;
189 public static double[]
getMLE(
double[] x,
int n) {
193 throw new IllegalArgumentException(
"n <= 0");
195 Optim system =
new Optim(x, n);
197 double[] parameters =
new double[2];
198 double[] xpls =
new double[3];
199 double[] param =
new double[3];
200 double[] fpls =
new double[3];
201 double[] gpls =
new double[3];
202 int[] itrcmd =
new int[2];
203 double[][] a =
new double[3][3];
204 double[] udiag =
new double[3];
208 int m = Math.round((
float) n / 4.0f);
211 param[2] = (q3 - q1) / 2.0;
213 Uncmin_f77.optif0_f77(2, param, system, xpls, fpls, gpls, itrcmd, a, udiag);
215 for (
int i = 0; i < 2; i++)
216 parameters[i] = xpls[i + 1];
231 double parameters[] =
getMLE(x, n);
232 return new CauchyDist(parameters[0], parameters[1]);
241 public static double getMean(
double alpha,
double beta) {
243 throw new IllegalArgumentException(
"beta <= 0");
245 throw new UnsupportedOperationException(
"Undefined mean");
255 throw new IllegalArgumentException(
"beta <= 0");
257 return Double.POSITIVE_INFINITY;
266 return Double.POSITIVE_INFINITY;
289 throw new IllegalArgumentException(
"beta <= 0");
299 double[] retour = { alpha, beta };
307 return getClass().getSimpleName() +
" : alpha = " + alpha +
", beta = " + beta;
static double density(double alpha, double beta, double x)
Computes the density function.
double density(double x)
Returns , the density evaluated at .
double getMean()
Returns the mean.
double getStandardDeviation()
Returns the standard deviation.
static double getMean(double alpha, double beta)
Throws an exception since the mean does not exist.
static double getStandardDeviation(double alpha, double beta)
Returns since the standard deviation does not exist.
String toString()
Returns a String containing information about the current distribution.
static double getVariance(double alpha, double beta)
Returns since the variance does not exist.
double inverseF(double u)
Returns the inverse distribution function .
static double cdf(double alpha, double beta, double x)
Computes the distribution function.
CauchyDist(double alpha, double beta)
Constructs a CauchyDist object with parameters alpha and beta.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the Cauchy distribution using the maximum likelihood method,...
double getAlpha()
Returns the value of for this object.
double cdf(double x)
Returns the distribution function .
double[] getParams()
Return a table containing parameters of the current distribution.
double getBeta()
Returns the value of for this object.
CauchyDist()
Constructs a CauchyDist object with parameters and .
double getVariance()
Returns the variance.
static CauchyDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a Cauchy distribution with parameters.
static double barF(double alpha, double beta, double x)
Computes the complementary distribution.
double barF(double x)
Returns the complementary distribution function.
void setParams(double alpha, double beta)
Sets the value of the parameters and for this object.
static double inverseF(double alpha, double beta, double u)
Computes the inverse of the distribution.
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.
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.