25package umontreal.ssj.probdist;
27import umontreal.ssj.util.RootFinder;
28import umontreal.ssj.functions.MathFunction;
49 private static final double EPSI = 1.0E-10;
54 protected double mean;
57 public Function(
int m,
int max,
double mean,
int[] Fj) {
61 this.Fj =
new int[Fj.length];
62 System.arraycopy(Fj, 0, this.Fj, 0, Fj.length);
65 public double evaluate(
double p) {
67 double s = (p * mean) / (1.0 - p);
69 for (
int j = 0; j < max; j++)
70 sum += Fj[j] / (s + (
double) j);
72 return sum + m * Math.log(p);
75 public double evaluateN(
int n,
double p) {
78 for (
int j = 0; j < max; j++)
79 sum += Fj[j] / (n + j);
81 return sum + m * Math.log(p);
112 public static double[]
getMLE(
int[] x,
int m) {
114 throw new IllegalArgumentException(
"m <= 0");
117 int max = Integer.MIN_VALUE;
118 for (
int i = 0; i < m; i++) {
123 double mean = (double) sum / (
double) m;
126 for (
int i = 0; i < m; i++)
127 var += (x[i] - mean) * (x[i] - mean);
131 throw new UnsupportedOperationException(
"mean >= variance");
133 int[] Fj =
new int[max];
134 for (
int j = 0; j < max; j++) {
136 for (
int i = 0; i < m; i++)
143 double[] parameters =
new double[2];
144 Function f =
new Function(m, max, mean, Fj);
147 if (parameters[1] >= 1.0)
148 parameters[1] = 1.0 - 1e-15;
150 parameters[0] = Math.round((parameters[1] * mean) / (1.0 - parameters[1]));
151 if (parameters[0] == 0)
166 double parameters[] =
getMLE(x, m);
167 return new PascalDist((
int) parameters[0], parameters[1]);
174 return (
int) (n + 0.5);
181 super.setParams((
double) n, p);
188 return getClass().getSimpleName() +
" : n = " +
getN1() +
", p = " +
getP();
double getP()
Returns the parameter of this object.
String toString()
Returns a String containing information about the current distribution.
void setParams(int n, double p)
Sets the parameter and of this object.
static double[] getMLE(int[] x, int m)
Estimates the parameter of the Pascal distribution using the maximum likelihood method,...
PascalDist(int n, double p)
Creates an object that contains the probability terms ( fmass-pascal ) and the distribution function ...
static PascalDist getInstanceFromMLE(int[] x, int m)
Creates a new instance of a Pascal distribution with parameters.
int getN1()
Returns the parameter of this object.
This class provides numerical methods to solve non-linear equations.
static double brentDekker(double a, double b, MathFunction f, double tol)
Computes a root of the function in f using the Brent-Dekker method.
This interface should be implemented by classes which represent univariate mathematical functions.