Public
Edited
Feb 2
Insert cell
Insert cell
Insert cell
function normFunc({n, amplitude = 1, sigma = 1}) {
const norm = multivariateNormal(
Array(n).fill(0),
math.matrix(kernelFunction(n, amplitude, sigma))
);
return norm;
}
Insert cell
normFunc({ n: 50, sigma: 10 }).sample(20)
Insert cell
function kernelFunction(n, amplitude = 1, sigma = 1) {
// returns a covariance matrix with a radial distance
// parameters:
// amplitude: default 1 - basically changes the scale of the whole graph
// sigma: default 1 - controls the spread of the distance func. eg. higher sigma will
// result in higher covariance between more distant points
{
const matrix = new Array();
for (let i = 0; i < n; ++i) {
matrix[i] = new Array(n);
for (let j = 0; j < n; ++j) {
// Radial basis function
matrix[i][j] = amplitude * Math.exp(-Math.pow((i - j) / sigma, 2));
}
}
return matrix;
}
}
Insert cell
Insert cell
mvnf({ n: 4 }).sample(3)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
math = require("mathjs@7")
Insert cell
import { multivariateNormal } from "@sw1227/multivariate-normal-distribution"
Insert cell
import { multivariateNormal as mvn } from "@josephsmann/multivariate-normal-distribution2"
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