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.
-
distboolconstant(bool b)Distribution always returning
b.Range bMean bVariance -
-
distintconstant(int i)Distribution always returning
i.Range iMean iVariance -
-
distrealconstant(real r)Distribution always returning
r.Range rMean rVariance -
Discrete distributions
The discrete distributions return integer or boolean sample values.
-
distboolbernoulli(real p)Outcome of an experiment with chance
p(0 <= p <= 1).Range {false, true}Mean p(wherefalseis interpreted as0, andtrueis interpreted as1)Variance 1 - p(wherefalseis interpreted as0, andtrueis interpreted as1)See also Bernoulli(p), [Law (2007)], page 302
-
distintbinomial(int n, real p)Number of successes when performing
nexperiments(n > 0)with chancep(0 <= p <= 1).Range {0, 1, ..., n}Mean n * pVariance n * p * (1 - p)See also bin(n, p), [Law (2007)], page 304
-
distintgeometric(real p)Geometric distribution, number of failures before success for an experiment with chance
p(0 < p <= 1).Range {0, 1, ...}Mean (1 - p) / pVariance (1 - p) / p^2See also geom(p), [Law (2007)], page 305
-
distintpoisson(real lambda)Poisson distribution.
Range {0, 1, ...}Mean lambdaVariance lambdaSee also Poison(lambda), [Law (2007)], page 308
-
distintuniform(int a, b)Integer uniform distribution from
atobexcluding the upper bound.Range {a, a+1, ..., b-1}Mean (a + b - 1) / 2Variance ((b - a)^2 - 1) / 12See also DU(a, b - 1), [Law (2007)], page 303
Continuous distributions
-
distrealbeta(real p, q)Beta distribution with shape parameters
pandq, withp > 0andq > 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
-
distrealerlang(double m, int k)Erlang distribution with
ka positive integer andm > 0. Equivalent togamma(k, m / k).Mean mVariance m * m / kSee also ERL(m, k), [Banks (1998)], page 153
-
distrealexponential(real m)(Negative) exponential distribution with mean
m, withm > 0.Range [0, infinite)Mean mVariance m * mSee also expo(m), [Law (2007)], page 283
-
distrealgamma(real a, b)Gamma distribution, with shape parameter
a > 0and scale parameterb > 0.Mean a * bVariance a * b^2 -
distreallognormal(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
-
distrealnormal(real m, v2)Normal distribution.
Range (-infinite, infinite)Mean mVariance v2See also N(m, v2), [Law (2007)], page 288
-
distrealrandom()Random number generator.
Range [0, 1)Mean 0.5Variance 1 / 12 -
distrealtriangle(real a, b, c)Triangle distribution, with
a < b < c.Range [a, c]Mean (a + b + c) /3Variance (a^2 + c^2 + b^2 - a*b - a*c - b*c) / 18See also Triangle(a, c, b), [Law (2007)], page 300
-
distrealuniform(real a, b)Real uniform distribution from
atob, excluding upper bound.Range [a, b)Mean (a + b) / 2Variance (b - a)^2 / 12See also U(a,b), [Law (2007)], page 282, except that distribution has an inclusive upper bound.
-
distrealweibull(real a, b)Weibull distribution with shape parameter
aand scale parameterb, witha > 0andb > 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 overtfrom0toinfinity, 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