25package umontreal.ssj.probdist;
27import java.util.Formatter;
28import java.util.Locale;
29import cern.colt.matrix.*;
30import cern.colt.matrix.impl.*;
31import umontreal.ssj.util.*;
32import umontreal.ssj.functions.MathFunction;
75 protected double[] m_lambda;
77 protected static void testLambda(
double[] lambda) {
78 int m = lambda.length;
79 for (
int j = 0; j < m; ++j) {
81 throw new IllegalArgumentException(
"lambda_j <= 0");
86 private static DoubleMatrix2D buildMatrix(
double[] lambda,
double x) {
87 int m = lambda.length;
89 DoubleFactory2D F2 = DoubleFactory2D.dense;
90 DoubleMatrix2D A = F2.make(m, m);
91 for (
int j = 0; j < m - 1; j++) {
92 A.setQuick(j, j, -lambda[j] * x);
93 A.setQuick(j, j + 1, lambda[j] * x);
95 A.setQuick(m - 1, m - 1, -lambda[m - 1] * x);
101 private double[] m_lam;
104 public myFunc(
double[] lam,
double u) {
109 public double evaluate(
double x) {
129 public double cdf(
double x) {
130 return cdf(m_lambda, x);
134 return barF(m_lambda, x);
161 public static double density(
double[] lambda,
double x) {
164 DoubleMatrix2D Ax = buildMatrix(lambda, x);
166 int m = lambda.length;
167 return lambda[m - 1] * T.getQuick(0, m - 1);
178 public static double cdf(
double[] lambda,
double x) {
181 if (x >= Double.MAX_VALUE)
185 double LOW = mean - 1.5 * std;
188 double LIMIT = 1.0e-3;
193 DoubleMatrix2D T = buildMatrix(lambda, x);
194 DoubleFactory1D fac1 = DoubleFactory1D.dense;
195 int m = lambda.length;
196 DoubleMatrix1D C = fac1.make(m, 1.0);
198 return Math.abs(B.getQuick(0));
211 public static double cdf2(
double[] lambda,
double x) {
214 if (x >= Double.MAX_VALUE)
227 public static double barF(
double[] lambda,
double x) {
230 if (x >= Double.MAX_VALUE)
232 DoubleMatrix2D T = buildMatrix(lambda, x);
233 DoubleFactory1D fac1 = DoubleFactory1D.dense;
234 int m = lambda.length;
235 DoubleMatrix1D C = fac1.make(m, 1.0);
237 return B.getQuick(0);
248 public static double inverseF(
double[] lambda,
double u) {
249 if (u < 0.0 || u > 1.0)
250 throw new IllegalArgumentException(
"u not in [0,1]");
252 return Double.POSITIVE_INFINITY;
256 final double EPS = 1.0e-12;
257 myFunc fonc =
new myFunc(lambda, u);
259 double v =
cdf(lambda, x1);
264 double x2 = 4.0 * x1 + 1.0;
282 public static double getMean(
double[] lambda) {
284 int k = lambda.length;
286 for (
int j = 0; j < k; j++)
287 sum += 1.0 / lambda[j];
301 int k = lambda.length;
303 for (
int j = 0; j < k; j++)
304 sum += 1.0 / (lambda[j] * lambda[j]);
336 int k = lambda.length;
337 m_lambda =
new double[k];
339 System.arraycopy(lambda, 0, m_lambda, 0, k);
353 StringBuilder sb =
new StringBuilder();
354 Formatter formatter =
new Formatter(sb, Locale.US);
356 int k = m_lambda.length;
357 for (
int i = 0; i < k; i++) {
358 formatter.format(
" %g%n", m_lambda[i]);
360 formatter.format(
"}%n");
361 return sb.toString();
Classes implementing continuous distributions should inherit from this base class.
double getMean()
Returns the mean.
static double getMean(double[] lambda)
Returns the mean, , of the hypoexponential distribution with rates lambda[ ], .
double getVariance()
Returns the variance.
static double density(double[] lambda, double x)
Computes the density function , with lambda[ ], .
void setLambda(double[] lambda)
Sets the values lambda[ ], for this object.
double cdf(double x)
Returns the distribution function .
static double getVariance(double[] lambda)
Returns the variance, , of the hypoexponential distribution with rates.
HypoExponentialDist(double[] lambda)
Constructs a HypoExponentialDist object, with rates lambda[ ], .
double barF(double x)
Returns the complementary distribution function.
static double barF(double[] lambda, double x)
Computes the complementary distribution , with.
String toString()
Returns a String containing information about the current distribution.
double density(double x)
Returns , the density evaluated at .
double getStandardDeviation()
Returns the standard deviation.
double[] getLambda()
Returns the values for this object.
static double cdf2(double[] lambda, double x)
Computes the distribution function , with lambda[ ], .
static double getStandardDeviation(double[] lambda)
Returns the standard deviation of the hypoexponential distribution with rates lambda[ ],...
static double cdf(double[] lambda, double x)
Computes the distribution function , with lambda[ ], .
static double inverseF(double[] lambda, double u)
Computes the inverse distribution function , with.
double inverseF(double u)
Returns the inverse distribution function .
double[] getParams()
Same as getLambda.
This class implements a few methods for matrix calculations when the matrix entries are in double.
static DoubleMatrix2D expmiBidiagonal(final DoubleMatrix2D A)
Computes , where is the exponential of the bidiagonal square matrix .
static DoubleMatrix2D expBidiagonal(final DoubleMatrix2D A)
Returns , the exponential of the bidiagonal square matrix.
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.