Distributions
The Chi language has three kinds of distributions:
-
Constant distributions, distributions returning always the same value
-
Discrete distributions, distributions returning a boolean or integer value
-
Continuous distributions, distributions returning a real number value
The constant distributions are used during creation of the Chi program. Before adding stochastic behavior, you want to make sure the program itself is correct. It is much easier to verify correctness without stochastic behavior, but if you have to change the program again after the verification, you may introduce new errors in the process.
The constant distributions solve this by allowing you to program with stochastic sampling in the code, but it is not doing anything (since you get the same predictable value on each sample operation). After verifying correctness of the program, you only need to modify the distributions that you use to get proper stochastic behavior.
Constant distributions
The constant distributions have very predictable samples, which makes them ideal for testing functioning of the program before adding stochastic behavior.
-
dist
bool
constant(bool b)
Distribution always returning
b
.Range b
Mean b
Variance -
-
dist
int
constant(int i)
Distribution always returning
i
.Range i
Mean i
Variance -
-
dist
real
constant(real r)
Distribution always returning
r
.Range r
Mean r
Variance -
Discrete distributions
The discrete distributions return integer or boolean sample values.
-
dist
bool
bernoulli(real p)
Outcome of an experiment with chance
p
(0 <= p <= 1)
.Range {false, true}
Mean p
(wherefalse
is interpreted as0
, andtrue
is interpreted as1
)Variance 1 - p
(wherefalse
is interpreted as0
, andtrue
is interpreted as1
)See also Bernoulli(p), [Law (2007)], page 302
-
dist
int
binomial(int n, real p)
Number of successes when performing
n
experiments(n > 0)
with chancep
(0 <= p <= 1)
.Range {0, 1, ..., n}
Mean n * p
Variance n * p * (1 - p)
See also bin(n, p), [Law (2007)], page 304
-
dist
int
geometric(real p)
Geometric distribution, number of failures before success for an experiment with chance
p
(0 < p <= 1)
.Range {0, 1, ...}
Mean (1 - p) / p
Variance (1 - p) / p^2
See also geom(p), [Law (2007)], page 305
-
dist
int
poisson(real lambda)
Poisson distribution.
Range {0, 1, ...}
Mean lambda
Variance lambda
See also Poison(lambda), [Law (2007)], page 308
-
dist
int
uniform(int a, b)
Integer uniform distribution from
a
tob
excluding the upper bound.Range {a, a+1, ..., b-1}
Mean (a + b - 1) / 2
Variance ((b - a)^2 - 1) / 12
See also DU(a, b - 1), [Law (2007)], page 303
Continuous distributions
-
dist
real
beta(real p, q)
Beta distribution with shape parameters
p
andq
, withp > 0
andq > 0
.Range [0, 1]
Mean p / (p + q)
Variance p * q / ((p + q)^2 * (p + q + 1))
See also Beta(p, q), [Law (2007)], page 291
-
dist
real
erlang(double m, int k)
Erlang distribution with
k
a positive integer andm > 0
. Equivalent togamma(k, m / k)
.Mean m
Variance m * m / k
See also ERL(m, k), [Banks (1998)], page 153
-
dist
real
exponential(real m)
(Negative) exponential distribution with mean
m
, withm > 0
.Range [0, infinite)
Mean m
Variance m * m
See also expo(m), [Law (2007)], page 283
-
dist
real
gamma(real a, b)
Gamma distribution, with shape parameter
a > 0
and scale parameterb > 0
.Mean a * b
Variance a * b^2
-
dist
real
lognormal(real m, v2)
Log-normal distribution.
Range [0, infinite)
Mean exp(m + v2/2)
Variance exp(2*m + v2) * (exp(v2) - 1)
See also N(m, v2), [Law (2007)], page 290
-
dist
real
normal(real m, v2)
Normal distribution.
Range (-infinite, infinite)
Mean m
Variance v2
See also N(m, v2), [Law (2007)], page 288
-
dist
real
random()
Random number generator.
Range [0, 1)
Mean 0.5
Variance 1 / 12
-
dist
real
triangle(real a, b, c)
Triangle distribution, with
a < b < c
.Range [a, c]
Mean (a + b + c) /3
Variance (a^2 + c^2 + b^2 - a*b - a*c - b*c) / 18
See also Triangle(a, c, b), [Law (2007)], page 300
-
dist
real
uniform(real a, b)
Real uniform distribution from
a
tob
, excluding upper bound.Range [a, b)
Mean (a + b) / 2
Variance (b - a)^2 / 12
See also U(a,b), [Law (2007)], page 282, except that distribution has an inclusive upper bound.
-
dist
real
weibull(real a, b)
Weibull distribution with shape parameter
a
and scale parameterb
, witha > 0
andb > 0
.Range [0, infinite)
Mean (b / a) * G(1 / a)
Variance (b^2 / a) * (2 * G(2 / a) - (1 / a) * G(1 / a)^2)
withG(x)
the Gamma function,G(x)
=
integral overt
from0
toinfinity
, fort^(x - 1) * exp(-t)
See also Weibull(a, b), [Law (2007)], page 284
References
-
[Banks (1998)] Jerry Banks, "Handbook of Simulation: Principles, Methodology, Advances, Applications, and Practice", John Wiley & Sons, Inc., 1998, doi:10.1002/9780470172445
-
[Law (2007)] Averill M. Law, "Simulation Modeling and Analysis", fourth edition, McGraw-Hill, 2007