Public
Edited
Apr 18, 2023
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
random_noise = Array(N).fill(0).map(() => rnorm(0, 1))
Insert cell
training_randomness = Array(N).fill(0).map(() => Math.random())
Insert cell
random_x = Array(N).fill(0).map(() => rnorm(0, 1))
Insert cell
alpha = 0.8
Insert cell
R_alpha = {
const M = setup.data.filter((d) => d.training == false).length;
const R = setup.data.filter((d) => d.training == false).map((d) => d.R).sort();
const k = Math.ceil((alpha) * (M - 1));
return R[k];
}
Insert cell
intervals = {
const N_pred = 1e2;
const xmin = -3;
const xmax = 3;
const xs = Array(N_pred).fill(0).map((_, index) => xmin + (xmax - xmin) / (N_pred - 1) * index);

return xs.map((x) => ({ x: x, lower: setup.fit.predict(x)[1] - R_alpha, upper: setup.fit.predict(x)[1] + R_alpha }));
}
Insert cell
// slightly modified, from https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve
function rnorm(mean, sd) {
let u = 0, v = 0;
while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
while(v === 0) v = Math.random();
return (Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v ) * sd) + mean;
}
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