Did you know ... Search Documentation:
Pack plrand -- prolog/prob/meta.pl
PublicShow source

This module provides a mini language for describing and sampling from random variables.

 rv(-Spec, -Type) is multi[multifile]
Unifies Spec and Type with specifications for all the distributions known to the system.
Arguments:
Spec- is a term representing a distribution that can be used with sample/2 or sample/4. The head functor represents the distribution to sampled from and any arguments represent the types of the corresponding arguments to be used when sampling.
Type- represents the type of the sampled value.
 sample(+DistExpression, -Value) is det
 sample(+DistExpression, -Value, +StateIn, -StateOut) is det
sample/2 and sample/4 implement a small language for describing and sampling from a distribution.

sample/2 uses and modifies the global state. sample/4 uses a given random generator state and returns the state on completion, and is designed to compatible with DCG syntax to hide the threading of the random state through several consecutive calls.

DistExpression is an expression describing a distribution. The head functor can be a distribution name (as listed by rv/2) or one of a number of arithmetic operators or term constructors. The arguments (in almost all cases) can then be further DistExpressions which are evaluated recursively. Valid non-distributional termsare:

X * Y
returns product of samples from X and Y
X / Y
returns ratio of samples from X and Y
X + Y
returns sum of samples from X and Y
X - Y
returns difference of samples from X and Y
- X
returns the negation of a sample from X
sqrt(X)
returns square root of sample from X
[X, Y, ...]

return samples from X, Y etc in a list

  • rep(N,X)

returns N independent sample from X in a list (N must be a constant)

  • factorial(N,X) returns N independent sample from X in an N argument term \(X1,...,XN)
  • <any number> returns itself as a constant

    For example

    ?- sample(invgamma(1)*rep(8,discrete(dirichlet(rep(4,0.5)))),X).
    X = [3, 2, 3, 3, 3, 1, 2, 2] .
 sample(+DistExpression, -Value) is det[multifile]
 sample(+DistExpression, -Value, +StateIn, -StateOut) is det[multifile]
sample/2 and sample/4 implement a small language for describing and sampling from a distribution.

sample/2 uses and modifies the global state. sample/4 uses a given random generator state and returns the state on completion, and is designed to compatible with DCG syntax to hide the threading of the random state through several consecutive calls.

DistExpression is an expression describing a distribution. The head functor can be a distribution name (as listed by rv/2) or one of a number of arithmetic operators or term constructors. The arguments (in almost all cases) can then be further DistExpressions which are evaluated recursively. Valid non-distributional termsare:

X * Y
returns product of samples from X and Y
X / Y
returns ratio of samples from X and Y
X + Y
returns sum of samples from X and Y
X - Y
returns difference of samples from X and Y
- X
returns the negation of a sample from X
sqrt(X)
returns square root of sample from X
[X, Y, ...]

return samples from X, Y etc in a list

  • rep(N,X)

returns N independent sample from X in a list (N must be a constant)

  • factorial(N,X) returns N independent sample from X in an N argument term \(X1,...,XN)
  • <any number> returns itself as a constant

    For example

    ?- sample(invgamma(1)*rep(8,discrete(dirichlet(rep(4,0.5)))),X).
    X = [3, 2, 3, 3, 3, 1, 2, 2] .

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 dps_dist(Arg1, Arg2, Arg3)