Published
Edited
Nov 17, 2018
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gaussianKernel = {
// Adapted from https://github.com/ghewgill/picomath/blob/master/javascript/erf.js
function erf(x) {
// constants
const a1 = 0.254829592;
const a2 = -0.284496736;
const a3 = 1.421413741;
const a4 = -1.453152027;
const a5 = 1.061405429;
const p = 0.3275911;

// A&S formula 7.1.26
const t = 1.0 / (1.0 + p * Math.abs(x));
const y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-x * x);

return Math.sign(x) * y;
}

function def_int_gaussian(x, mu, sigma) {
return 0.5 * erf((x - mu) / (Math.SQRT2 * sigma));
}

return function gaussian_kernel(kernel_size = 5, sigma = 1, mu = 0, step = 1) {
const end = 0.5 * kernel_size;
const start = -end;
const coeff = [];
let sum = 0;
let x = start;
let last_int = def_int_gaussian(x, mu, sigma);
let acc = 0;
while (x < end) {
x += step;
const new_int = def_int_gaussian(x, mu, sigma)
let c = new_int - last_int;
coeff.push(c);
sum += c;
last_int = new_int;
}

//normalize
sum = 1/sum;
for (let i = 0; i < coeff.length; i++) {
coeff[i] *= sum;
}
return coeff;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
import {chart as barChart3D} with {data, width, height, color, scale, showText} from '@jobleonard/importable-3d-bar-chart-port'
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