en ru

Docs

NAME

createDistribution - create object that represents a probability distribution

SYNOPSIS

function createDistribution(distr, p1);
function createDistribution(distr, p1, p2);
function createDistribution(distr, luaQuantileFunction);

DESCRIPTION

The first two implementations are used to create predefined probability distributions. Argument distr determines distribution type and how many parameters from p1, p2 does it need. Do not pass less parameters than required.

The last implementation is for custom probability distributions. In this case, distr must be set to DISTR.CUSTOM, while luaQuantileFunction must refer to a Lua function, taking one numeric argument and returning one numeric value. This Lua function is used to evaluate inverse of cumulative distribution function.

RETURN VALUES

Upon successful completion, createDistribution returns a unique id of newly created object. Otherwise, 0 is returned.

NOTES

Try to work with predefined probability distributions, if possible. Using of custom distributions significantly slows down overall performance.

Don't forget to call closeId function to release the object when it is no longer needed.

EXAMPLES

To create exponential distribution F(x) = 1 - exp(-3x):

expDistr = createDistribution(DISTR.EXP, 3.0);

To create Weibull distribution F(x) = 1 - exp(-3x2):

wblDistr = createDistribution(DISTR.WEIBULL, 3.0, 2.0);

To create custom probability distribution F(x) = (x - 3) / (5 - 3), where 3 ≤ x ≤ 5:

function uniformQuantileFunction(p)
   return (5.0 - 3.0) * p + 3.0;
   end;

uniDistr = createDistribution(DISTR.CUSTOM, uniformQuantileFunction);

SEE ALSO

DISTR, createInterruptManager, closeId

Verbatim copying and distribution of this entire article are permitted in any medium, provided this notice is preserved.
Send suggestions, questions and bug reports to neurowombatmail@gmail.com
Copyright © 2009, 2010, 2011, 2012 Andrew Timashov