Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.random.ndvariable

Multidimensional Random Variables

Generator name Description
SphereVariable Uniform distribution on a unit-sphere
SimplexVariable Uniform distribution on a standard-simplex
DirichletVariable Dirichlet random variable
MultivariateNormalVariable Multivariate_normal random variable
Authors:
Simon B├╝rger, Ilya Yaroshenko
struct SphereVariable(T) if (isFloatingPoint!T);

SphereVariable!T sphereVar(T = double)()
if (isFloatingPoint!T);

alias sphereVariable = sphereVar(T = double)() if (isFloatingPoint!T);
Uniform distribution on a sphere.
Returns:
X ~ 1 with X[0]^^2 + .. + X[$-1]^^2 = 1
Examples:
Generate random points on a circle
double[2] x;
sphereVar()(rne, x);
assert(fabs(x[0] * x[0] + x[1] * x[1] - 1) < 1e-10);
enum auto isRandomVariable;
void opCall(G)(ref scope G gen, scope T[] result);

void opCall(G)(scope G* gen, scope T[] result);
void opCall(G, SliceKind kind)(ref scope G gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);

void opCall(G, SliceKind kind)(scope G* gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);
struct SimplexVariable(T) if (isFloatingPoint!T);

SimplexVariable!T simplexVar(T = double)()
if (isFloatingPoint!T);

alias simplexVariable = simplexVar(T = double)() if (isFloatingPoint!T);
Uniform distribution on a simplex.
Returns:
X ~ 1 with X[i] >= 0 and X[0] + .. + X[$-1] = 1
Examples:
auto rv = simplexVar;
double[3] x;
rv(rne, x);
assert(x[0] >= 0 && x[1] >= 0 && x[2] >= 0);
assert(fabs(x[0] + x[1] + x[2] - 1) < 1e-10);
Examples:
Random* gen = threadLocalPtr!Random;
SimplexVariable!double rv;
double[3] x;
rv(gen, x);
assert(x[0] >= 0 && x[1] >= 0 && x[2] >= 0);
assert(fabs(x[0] + x[1] + x[2] - 1) < 1e-10);
enum auto isRandomVariable;
void opCall(G)(ref scope G gen, scope T[] result);

void opCall(G)(scope G* gen, scope T[] result);
void opCall(G, SliceKind kind)(ref scope G gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);

void opCall(G, SliceKind kind)(scope G* gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);
struct DirichletVariable(T) if (isFloatingPoint!T);

DirichletVariable!T dirichletVar(T)(in T[] alpha)
if (isFloatingPoint!T);

DirichletVariable!T dirichletVar(T)(Slice!(const(T)*) alpha)
if (isFloatingPoint!T);

alias dirichletVariable = dirichletVar(T)(in T[] alpha) if (isFloatingPoint!T);
Dirichlet distribution.
Examples:
auto rv = dirichletVar([1.0, 5.7, 0.3]);
double[3] x;
rv(rne, x);
assert(x[0] >= 0 && x[1] >= 0 && x[2] >= 0);
assert(fabs(x[0] + x[1] + x[2] - 1) < 1e-10);
Examples:
Random* gen = threadLocalPtr!Random;
auto rv = DirichletVariable!double([1.0, 5.7, 0.3]);
double[3] x;
rv(gen, x);
assert(x[0] >= 0 && x[1] >= 0 && x[2] >= 0);
assert(fabs(x[0] + x[1] + x[2] - 1) < 1e-10);
enum auto isRandomVariable;
Slice!(const(T)*) alpha;
this()(Slice!(const(T)*) alpha);

this()(const(T)[] alpha);
Parameters:
Slice!(const(T)*) alpha concentration parameters

Constraints: alpha[i] > 0

void opCall(G)(ref scope G gen, scope T[] result);

void opCall(G)(scope G* gen, scope T[] result);
void opCall(G, SliceKind kind, Iterator)(ref scope G gen, scope Slice!(Iterator, 1, kind) result)
if (isSaturatedRandomEngine!G);

void opCall(G, SliceKind kind, Iterator)(scope G* gen, scope Slice!(Iterator, 1, kind) result)
if (isSaturatedRandomEngine!G);
struct MultivariateNormalVariable(T) if (isFloatingPoint!T);

MultivariateNormalVariable!T multivariateNormalVar(T)(Slice!(const(T)*) mu, Slice!(T*, 2) sigma, bool chol = false)
if (isFloatingPoint!T);

MultivariateNormalVariable!T multivariateNormalVar(T)(Slice!(T*, 2) sigma, bool chol = false)
if (isFloatingPoint!T);

alias multivariateNormalVariable = multivariateNormalVar(T)(Slice!(const(T)*) mu, Slice!(T*, 2) sigma, bool chol = false) if (isFloatingPoint!T);
Multivariate normal distribution. Beta version (has not properly tested).
Examples:
auto mu = [10.0, 0.0].sliced;
auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2);
auto rv = multivariateNormalVar(mu, sigma);
double[2] x;
rv(rne, x[]);
Examples:
Random* gen = threadLocalPtr!Random;
auto mu = [10.0, 0.0].sliced;
auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2);
auto rv = multivariateNormalVar(mu, sigma);
double[2] x;
rv(gen, x[]);
enum auto isRandomVariable;
this()(Slice!(const(T)*) mu, Slice!(T*, 2) sigma, bool chol = false);

this()(Slice!(T*, 2) sigma, bool chol = false);
Constructor computes the Cholesky decomposition of sigma in place without memory allocation. Furthermore it is assumed to be a symmetric matrix, but only the lower/left half is actually accessed.
Parameters:
Slice!(const(T)*) mu mean vector (assumed zero if not supplied)
Slice!(T*, 2) sigma covariance matrix
bool chol optional flag indicating that sigma is already Cholesky decomposed

Constraints: sigma has to be positive-definite

void opCall(G)(ref scope G gen, scope T[] result);

void opCall(G)(scope G* gen, scope T[] result);
void opCall(G, SliceKind kind)(ref scope G gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);

void opCall(G, SliceKind kind)(scope G* gen, scope Slice!(T*, 1, kind) result)
if (isSaturatedRandomEngine!G);