Special probabilistic functions
Certain(u)
Returns the mid (deterministic) value of u even if u is uncertain and evaluated in a prob (probabilistic) context. It is not strictly a probability distribution. It is sometimes useful in browse mode, when you want to replace an existing probability distribution defined for an input (see Using input nodes) with a non-probabilistic value.
Library: Distribution
Shuffle(a, i)
Shuffle returns a random reordering (permutation) of the values in array a over index i. If you omit i, it evaluates a in prob mode, and shuffles the resulting sample over Run. You can use it to generate an independent random sample from an existing probability distributiona.
If a contains dimensions other than i, it shuffles each slice over those other dimensions independently over i. If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method:
a[@i = Shuffle(@i, i)]
This shuffles a over index i, without shuffling each slice over its other indexes.
Truncate(u, min, max)
Truncates an uncertain quantity u so that it has no values below min or above max. You must specify one or both min and max.
It does not discard sample values below min or above max. Instead, it generates a new sample that has approximately same probability distribution as u between min and max, and no values outside them. The values of the result sample have the same rank order as the input u, so the result retains the same rank-correlation that u had with any predecessor.
It gives an error if u is not uncertain, or if min is greater than max. It gives a warning if no sample values of u are in the range min to max. In mid mode, it returns an estimate of the median of the truncated distribution. Unlike other distribution functions, even in mid mode, it evaluates its parameter u (and therefore any of its predecessors) in prob mode. It always evaluates min and max in mid mode.
Examples: We define a normal distribution, X
, and variables A, B
, and C
that truncate X
below, above, and on
both sides. Then we define a variable to compare A, B
, and C
and display its result in the probability density view:
Chance X := Normal(10, 2) Chance A := Truncate(X, 7) Chance B := Truncate(X, , 10) Chance C := Truncate(X, 8, 12) Variable Compare_truncated_x := [A, B, C]
Library: Distribution
Random(expr)
Generates a single value randomly sampled from expr, which, if given, must be a call to a probability distribution with all needed parameters, for example:
Random(Uniform(-100, 100))
This returns a single real-valued random number uniformly selected between -100 and 100. If you omit parameter expr, it generates one sample from the uniform distribution 0 to 1, for example:
Random(Uniform(-100, 100)) → 74.4213148 Random() → 0.265569265
Random is not a true distribution function, since it generates only a single value from the distribution, whether in mid or prob context. It generates each single sample using Monte Carlo, not Latin hypercube sampling, no matter what the global setting in the uncertainty setup. It is often useful when you need a random number generator stream, such as for rejection sampling, Metropolis-Hastings simulation, and so on.
Random has these parameters, all optional.
Parameters:
- dist: If specified, must be a call to a distribution function that supports single-sample generation (see below). Defaults to Uniform(0, 1).
- Method: Selects the random number generator of 0=default, 1=Minimal standard, 2=L’Ecuyer, or 3=Knuth.
- Over: A convenient way to list index(es) so that the result is an array of independent random numbers with this index or indexes. For example:
Random(Over: I)
returns an array of independent uniform random numbers between 0 and 1 indexed by I. It is equivalent to:
Random(Uniform(0, 1, Over: i))
Supported distributions: Random supports all built-in probability distribution functions with the exception of Fractiles, ProbDist, and Truncate. It supports Bernoulli, Beta, Binomial, Certain, ChiSquared, CumDist, Exponential, Gamma, Geometric, HyperGeometric, Logistic, LogNormal, NegativeBinomial, Normal, Poisson, StudentT, Triangular, Uniform, Weibull.
It supports these distributions in the Distribution Variations library: Beta_m_sd, Chancedist, Erlang, Gamma_m_sd, InverseGaussian, Lorenzian, Pareto, Pert, Rayleigh, Smooth_Fractile, and Wald, and these distributions from the Multivariate Distributions library: BiNormal, Dirichlet, Dist_additive_growth, Dist_compound_growth, Dist_serial_correl, Gaussian, Multinomial, Multi-Normal, MultiUniform, Normal_additive_gro, Normal_compound_gro, Normal_correl, Normal_serial_correl, UniformSpherical, Wishart, and InvertedWishart.
User-defined functions can be used as a parameter to Random, if they are given an optional parameter declared as:
singleSampleMethod: Optional Atom Number
If the parameter is provided, the distribution function must return a single random variate from the distribution indicated by the other parameters. The value specifies the random number generator to use 0=default, 1=Minimal standard, 2=L’Ecuyer, and 3=Knuth.
See Also
Enable comment auto-refresher