Public
Edited
Feb 10, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
normal_distribution = (m, s) => (x) =>
Math.exp((-(x - m) * (x - m)) / (2 * s * s)) / (Math.sqrt(2 * Math.PI) * s)
Insert cell
binomial = (k, n, p) => choose(n, k) * Math.pow(p, k) * Math.pow(1 - p, n - k)
Insert cell
function choose(n, k) {
if (k > n / 2) return choose(n, n - k);
let res = 1;

for (let i = 1; i <= k; i++) {
res *= (n + 1 - i) / i;
}

return res;
}
Insert cell
fac = (function () {
// from https://stackoverflow.com/questions/3959211/fast-factorial-function-in-javascript
var f = [];
return function factorial(n) {
if (n == 0 || n == 1) return 1;
if (f[n] > 0) return f[n];
return (f[n] = factorial(n - 1) * n);
};
})()
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