25package umontreal.ssj.probdist;
27import java.util.Formatter;
28import java.util.Locale;
29import umontreal.ssj.util.*;
30import umontreal.ssj.functions.MathFunction;
85 private static double[] computeH(
double[] lambda) {
86 int k = lambda.length;
87 double[] H =
new double[k];
90 for (
int i = 0; i < k; i++) {
92 for (j = 0; j < i; j++)
93 tem *= lambda[j] / (lambda[j] - lambda[i]);
94 for (j = i + 1; j < k; j++)
95 tem *= lambda[j] / (lambda[j] - lambda[i]);
101 private static double m_density(
double[] lambda,
double[] H,
double x) {
105 int k = lambda.length;
108 for (
int j = 0; j < k; j++) {
109 tem = Math.exp(-lambda[j] * x);
111 prob += lambda[j] * H[j] * tem;
117 private static double m_barF(
double[] lambda,
double[] H,
double x) {
121 int k = lambda.length;
124 for (
int j = 0; j < k; j++) {
125 tem = Math.exp(-lambda[j] * x);
132 private static double m_cdf(
double[] lambda,
double[] H,
double x) {
136 int k = lambda.length;
137 double tem = Math.exp(-lambda[0] * x);
142 for (
int j = 0; j < k; j++) {
143 tem = Math.expm1(-lambda[j] * x);
151 private double[] m_lam;
154 public myFunc(
double[] lam,
double u) {
159 public double evaluate(
double x) {
179 return m_density(m_lambda, m_H, x);
182 public double cdf(
double x) {
183 return m_cdf(m_lambda, m_H, x);
187 return m_barF(m_lambda, m_H, x);
191 return m_inverseF(m_lambda, m_H, u);
202 public static double density(
double[] lambda,
double x) {
204 double[] H = computeH(lambda);
205 return m_density(lambda, H, x);
216 public static double cdf(
double[] lambda,
double x) {
218 double[] H = computeH(lambda);
219 return m_cdf(lambda, H, x);
230 public static double barF(
double[] lambda,
double x) {
232 double[] H = computeH(lambda);
233 return m_barF(lambda, H, x);
244 public static double inverseF(
double[] lambda,
double u) {
246 double[] H = computeH(lambda);
247 return m_inverseF(lambda, H, u);
250 private static double m_inverseF(
double[] lambda,
double[] H,
double u) {
251 if (u < 0.0 || u > 1.0)
252 throw new IllegalArgumentException(
"u not in [0,1]");
254 return Double.POSITIVE_INFINITY;
258 final double EPS = 1.0e-12;
259 myFunc fonc =
new myFunc(lambda, u);
261 double v = m_cdf(lambda, H, x1);
266 double x2 = 4.0 * x1 + 1.0;
267 v = m_cdf(lambda, H, x2);
271 v = m_cdf(lambda, H, x2);
279 super.setLambda(lambda);
280 m_H = computeH(lambda);
284 StringBuilder sb =
new StringBuilder();
285 Formatter formatter =
new Formatter(sb, Locale.US);
287 int k = m_lambda.length;
288 for (
int i = 0; i < k; i++) {
289 formatter.format(
" %f%n", m_lambda[i]);
291 formatter.format(
"}%n");
292 return sb.toString();
String toString()
Returns a String containing information about the current distribution.
static double inverseF(double[] lambda, double u)
Computes the inverse distribution function , with.
double inverseF(double u)
Returns the inverse distribution function .
double density(double x)
Returns , the density evaluated at .
double cdf(double x)
Returns the distribution function .
static double density(double[] lambda, double x)
Computes the density function , with lambda[ ], .
double barF(double x)
Returns the complementary distribution function.
static double cdf(double[] lambda, double x)
Computes the distribution function , with lambda[ ], .
void setLambda(double[] lambda)
Sets the values lambda[ ], for this object.
static double barF(double[] lambda, double x)
Computes the complementary distribution , with.
HypoExponentialDistQuick(double[] lambda)
Constructs a HypoExponentialDistQuick object, with rates.
double getMean()
Returns the mean.
HypoExponentialDist(double[] lambda)
Constructs a HypoExponentialDist object, with rates lambda[ ], .
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.