The OpenD Programming Language

dirichletVar

Dirichlet distribution.

dirichletVar
(
T
)
(
in T[] alpha
)

Examples

import mir.random.engine;
import mir.math.common: fabs;

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);
import mir.random.engine;
import mir.math.common: fabs;

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

Meta