The OpenD Programming Language

SimplexVariable

Uniform distribution on a simplex.

Members

Aliases

Element
alias Element = T
opCall
void opCall(G* gen, T[] result)

Functions

opCall
void opCall(G gen, T[] result)

Manifest constants

isNdRandomVariable
enum isNdRandomVariable;

Return Value

X ~ 1 with X[i] >= 0 and X[0] + .. + X[$-1] = 1

Examples

import mir.math.common: fabs;
// mir.ndslice package is required for 'SimplexVariable', it can be found in 'mir-algorithm'
static if (is(typeof({ import mir.ndslice.slice; })))
{
    import mir.random.engine;
    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);
}
import mir.random.engine;
import mir.math.common: fabs;

// mir.ndslice package is required for 'SimplexVariable', it can be found in 'mir-algorithm'
static if (is(typeof({ import mir.ndslice.slice; })))
{
    import mir.ndslice.slice;

    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);
}

Meta