25package umontreal.ssj.probdist;
50 protected double sigma;
51 private static final double ZLIMB = 500.0;
52 private static final double ZLIMS = 50.0;
54 private static class Optim
implements Uncmin_methods {
58 public Optim(
double[] x,
int n) {
60 this.xi =
new double[n];
61 System.arraycopy(x, 0, this.xi, 0, n);
64 public double f_to_minimize(
double[] p) {
70 for (
int i = 0; i < n; i++)
71 sum -= Math.log(
density(p[1], p[2], xi[i]));
76 public void gradient(
double[] x,
double[] g) {
79 public void hessian(
double[] x,
double[][] h) {
96 public double cdf(
double x) {
127 public static double density(
double mu,
double sigma,
double x) {
129 throw new IllegalArgumentException(
"sigma <= 0");
130 double y = (x - mu) / sigma;
131 if (Math.abs(y) >= ZLIMB)
134 return (1.0 / (Math.cosh(Math.PI * y / 2.0) * 2.0 * sigma));
141 public static double cdf(
double mu,
double sigma,
double x) {
143 throw new IllegalArgumentException(
"sigma <= 0");
144 double y = (x - mu) / sigma;
147 else if (y <= -ZLIMB)
150 return (2.0 * Math.atan(Math.exp(Math.PI * y / 2.0))) / Math.PI;
157 public static double barF(
double mu,
double sigma,
double x) {
159 throw new IllegalArgumentException(
"sigma <= 0");
161 double y = (x - mu) / sigma;
164 else if (y <= -ZLIMS)
167 return 2.0 / Math.PI * Math.atan(Math.exp(-Math.PI * y / 2.0));
174 public static double inverseF(
double mu,
double sigma,
double u) {
176 throw new IllegalArgumentException(
"sigma <= 0");
177 if (u < 0.0 || u > 1.0)
178 throw new IllegalArgumentException(
"u not in [0,1]");
181 return Double.POSITIVE_INFINITY;
183 return Double.NEGATIVE_INFINITY;
185 return (mu + (2.0 * sigma / Math.PI * Math.log(Math.tan(Math.PI / 2.0 * u))));
202 public static double[]
getMLE(
double[] x,
int n) {
206 throw new IllegalArgumentException(
"n <= 0");
208 Optim system =
new Optim(x, n);
210 double[] parameters =
new double[2];
211 double[] xpls =
new double[3];
212 double[] param =
new double[3];
213 double[] fpls =
new double[3];
214 double[] gpls =
new double[3];
215 int[] itrcmd =
new int[2];
216 double[][] a =
new double[3][3];
217 double[] udiag =
new double[3];
220 for (
int i = 0; i < n; i++)
222 param[1] = sum / (double) n;
225 for (
int i = 0; i < n; i++)
226 sum += (x[i] - param[1]) * (x[i] - param[1]);
227 param[2] = Math.sqrt(sum / (
double) n);
229 Uncmin_f77.optif0_f77(2, param, system, xpls, fpls, gpls, itrcmd, a, udiag);
231 for (
int i = 0; i < 2; i++)
232 parameters[i] = xpls[i + 1];
247 double parameters[] =
getMLE(x, n);
257 public static double getMean(
double mu,
double sigma) {
259 throw new IllegalArgumentException(
"sigma <= 0");
272 throw new IllegalArgumentException(
"sigma <= 0");
274 return (sigma * sigma);
306 throw new IllegalArgumentException(
"sigma <= 0");
317 double[] retour = { mu, sigma };
325 return getClass().getSimpleName() +
" : mu = " + mu +
", sigma = " + sigma;
Classes implementing continuous distributions should inherit from this base class.
static double getMean(double mu, double sigma)
Computes and returns the mean of the hyperbolic secant distribution with parameters and .
void setParams(double mu, double sigma)
Sets the parameters and of this object.
static double cdf(double mu, double sigma, double x)
Computes the distribution function of the hyperbolic secant distribution with parameters and .
double getSigma()
Returns the parameter of this object.
static double getStandardDeviation(double mu, double sigma)
Computes and returns the standard deviation of the hyperbolic secant distribution with parameters an...
double barF(double x)
Returns the complementary distribution function.
String toString()
Returns a String containing information about the current distribution.
static HyperbolicSecantDist getInstanceFromMLE(double[] x, int n)
Creates a new instance of a hyperbolic secant distribution with parameters and estimated using the ...
double getMu()
Returns the parameter of this object.
static double[] getMLE(double[] x, int n)
Estimates the parameters of the hyperbolic secant distribution using the maximum likelihood method,...
static double barF(double mu, double sigma, double x)
Computes the complementary distribution function of the hyperbolic secant distribution with parameter...
static double density(double mu, double sigma, double x)
Computes the density function ( fHyperbolicSecant ) for a hyperbolic secant distribution with paramet...
double[] getParams()
Return a table containing the parameters of the current distribution.
double getMean()
Returns the mean.
HyperbolicSecantDist(double mu, double sigma)
Constructs a hyperbolic secant distribution with parameters.
double cdf(double x)
Returns the distribution function .
double density(double x)
Returns , the density evaluated at .
double inverseF(double u)
Returns the inverse distribution function .
double getVariance()
Returns the variance.
static double inverseF(double mu, double sigma, double u)
Computes the inverse of the hyperbolic secant distribution with parameters and .
static double getVariance(double mu, double sigma)
Computes and returns the variance of the hyperbolic secant distribution with parameters and.
double getStandardDeviation()
Returns the standard deviation.