Public
Edited
Jul 24, 2020
Importers
3 stars
Insert cell
Insert cell
Insert cell
pachinko(randomGamma(k, 1))
Insert cell
Insert cell
Insert cell
function randomGamma(k, theta) {
if (k === 1) {
return d3r.randomExponential(1 / theta);
}
var U = d3r.randomUniform(),
N = d3r.randomNormal(),
d = (k < 1 ? k + 1 : k) - 1 / 3,
c = 1 / (3 * Math.sqrt(d)),
multiplier = k < 1 ? () => Math.pow(U(), 1 / k) : () => 1;
return function() {
do {
do {
var x = N(),
v = 1 + c * x;
} while (v <= 0);
v *= v * v;
var u = 1 - U();
} while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
return d * v * multiplier() * theta;
};
}
Insert cell
Insert cell
pachinko(randomBeta(alpha, beta), [0, 1])
Insert cell
Insert cell
Insert cell
function randomBeta(alpha, beta) {
const X = randomGamma(alpha, 1);
const Y = randomGamma(beta, 1);
var x;
return function() {
x = X();
return x / (x + Y());
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more