25package umontreal.ssj.probdist;
27import umontreal.ssj.util.Num;
58 public double prob(
int x) {
62 public double cdf(
int x) {
66 public double barF(
int x) {
71 if (u > 1.0 || u < 0.0)
72 throw new IllegalArgumentException(
"u not in [0,1]");
78 if (u >= 1.0 || p <= 0.0)
79 return Integer.MAX_VALUE;
81 return (
int) Math.floor(Math.log1p(-u) / vp);
100 public static double prob(
double p,
int x) {
102 throw new IllegalArgumentException(
"p not in range (0,1)");
109 return p * Math.pow(1 - p, x);
115 public static double cdf(
double p,
int x) {
116 if (p < 0.0 || p > 1.0)
117 throw new IllegalArgumentException(
"p not in [0,1]");
124 return 1.0 - Math.pow(1.0 - p, (
double) x + 1.0);
132 public static double barF(
double p,
int x) {
133 if (p < 0.0 || p > 1.0)
134 throw new IllegalArgumentException(
"p not in [0,1]");
142 return Math.pow(1.0 - p, x);
150 if (p > 1.0 || p < 0.0)
151 throw new IllegalArgumentException(
"p not in [0,1]");
152 if (u > 1.0 || u < 0.0)
153 throw new IllegalArgumentException(
"u not in [0,1]");
158 if (u >= 1.0 || p <= 0.0)
159 return Integer.MAX_VALUE;
161 double v = Math.log1p(-p);
162 return (
int) Math.floor(Math.log1p(-u) / v);
178 public static double[]
getMLE(
int[] x,
int n) {
180 throw new IllegalArgumentException(
"n <= 0");
183 parameters =
new double[1];
185 for (
int i = 0; i < n; i++) {
189 parameters[0] = 1.0 / (((double) sum / (double) n) + 1.0);
204 double parameters[] =
getMLE(x, n);
216 if (p < 0.0 || p > 1.0)
217 throw new IllegalArgumentException(
"p not in range (0,1)");
230 if (p < 0.0 || p > 1.0)
231 throw new IllegalArgumentException(
"p not in range (0,1)");
233 return ((1 - p) / (p * p));
258 throw new IllegalArgumentException(
"p not in range (0,1)");
268 double[] retour = { p };
276 return getClass().getSimpleName() +
" : p = " + p;
Classes implementing discrete distributions over the integers should inherit from this class.
static double prob(double p, int x)
Computes the geometric probability given in ( fgeom ) .
int inverseFInt(double u)
Returns the inverse distribution function , where.
static GeometricDist getInstanceFromMLE(int[] x, int n)
Creates a new instance of a geometric distribution with parameter.
double prob(int x)
Returns , the probability of .
double cdf(int x)
Returns the distribution function evaluated at (see ( FDistDisc )).
double getP()
Returns the associated with this object.
GeometricDist(double p)
Constructs a geometric distribution with parameter .
static double getVariance(double p)
Computes and returns the variance of the geometric distribution with parameter .
double getStandardDeviation()
Returns the standard deviation of the distribution function.
double getMean()
Returns the mean of the distribution function.
static double barF(double p, int x)
Computes the complementary distribution function.
double[] getParams()
Return a table containing the parameters of the current distribution.
double barF(int x)
Returns , the complementary distribution function.
static double getStandardDeviation(double p)
Computes and returns the standard deviation of the geometric distribution with parameter .
void setP(double p)
Resets the value of associated with this object.
static int inverseF(double p, double u)
Computes the inverse of the geometric distribution, given by ( FInvgeom ).
String toString()
Returns a String containing information about the current distribution.
static double[] getMLE(int[] x, int n)
Estimates the parameter of the geometric distribution using the maximum likelihood method,...
static double getMean(double p)
Computes and returns the mean of the geometric distribution with parameter .
static double cdf(double p, int x)
Computes the distribution function .
double getVariance()
Returns the variance of the distribution function.