SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
HypoExponentialDistEqual.java
1/*
2 * Class: HypoExponentialDistEqual
3 * Description: Hypo-exponential distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Richard Simard
9 * @since February 2014
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.probdist;
26
27import java.util.Formatter;
28import java.util.Locale;
29import umontreal.ssj.util.*;
30import umontreal.ssj.functions.MathFunction;
31
55 private double m_h;
56 private int m_n;
57 private int m_k;
58
67 public HypoExponentialDistEqual(int n, int k, double h) {
68 super(null);
69 setParams(n, k, h);
70 }
71
72 public double density(double x) {
73 return density(m_n, m_k, m_h, x);
74 }
75
76 public double cdf(double x) {
77 return cdf(m_n, m_k, m_h, x);
78 }
79
80 public double barF(double x) {
81 return barF(m_n, m_k, m_h, x);
82 }
83
84 public double inverseF(double u) {
85 return inverseF(m_n, m_k, m_h, u);
86 }
87
98 public static double density(int n, int k, double h, double x) {
99 if (x < 0)
100 return 0;
101 double r = -Math.expm1(-h * x);
102 double v = BetaDist.density(k, n - k + 1, r);
103 return h * v * Math.exp(-h * x);
104 }
105
116 public static double cdf(int n, int k, double h, double x) {
117 if (x <= 0)
118 return 0;
119 double r = -Math.expm1(-h * x);
120 double u = BetaDist.cdf(k, n - k + 1, r);
121 return u;
122 }
123
135 public static double barF(int n, int k, double h, double x) {
136 if (x <= 0)
137 return 1.0;
138 double r = Math.exp(-h * x);
139 double v = BetaDist.cdf(n - k + 1, k, r);
140 return v;
141 }
142
153 public static double inverseF(int n, int k, double h, double u) {
154 if (u < 0.0 || u > 1.0)
155 throw new IllegalArgumentException("u not in [0,1]");
156 if (u >= 1.0)
157 return Double.POSITIVE_INFINITY;
158 if (u <= 0.0)
159 return 0.0;
160
161 double z = BetaDist.inverseF(k, n - k + 1, u);
162 return -Math.log1p(-z) / h;
163 }
164
171 public double[] getParams() {
172 double[] par = new double[] { m_n, m_k, m_h };
173 return par;
174 }
175
176 public void setParams(int n, int k, double h) {
177 m_n = n;
178 m_k = k;
179 m_h = h;
180 m_lambda = new double[k];
181 for (int i = 0; i < k; i++) {
182 m_lambda[i] = (n - i) * h;
183 }
184 }
185
186 public String toString() {
187 StringBuilder sb = new StringBuilder();
188 Formatter formatter = new Formatter(sb, Locale.US);
189 formatter.format(getClass().getSimpleName() + " : params = {" + PrintfFormat.NEWLINE);
190 formatter.format(" %d, %d, %f", m_n, m_k, m_h);
191 formatter.format("}%n");
192 return sb.toString();
193 }
194}
Extends the class ContinuousDistribution for the beta distribution.
Definition BetaDist.java:54
double inverseF(double u)
Returns the inverse distribution function .
double cdf(double x)
Returns the distribution function .
double density(double x)
Returns , the density evaluated at .
String toString()
Returns a String containing information about the current distribution.
HypoExponentialDistEqual(int n, int k, double h)
Constructor for equidistant rates.
double[] getParams()
Returns the three parameters of this hypoexponential distribution as array .
static double density(int n, int k, double h, double x)
Computes the density function , with the same arguments as in the constructor.
double barF(double x)
Returns the complementary distribution function.
static double cdf(int n, int k, double h, double x)
Computes the distribution function , with arguments as in the constructor.
static double barF(int n, int k, double h, double x)
Computes the complementary distribution , as in formula ( conv-hypo-equal ).
double cdf(double x)
Returns the distribution function .
static double inverseF(int n, int k, double h, double u)
Computes the inverse distribution , with arguments as in the constructor.
double density(double x)
Returns , the density evaluated at .
double inverseF(double u)
Returns the inverse distribution function .
HypoExponentialDist(double[] lambda)
Constructs a HypoExponentialDist object, with rates lambda[ ], .
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.