Published
Edited
Apr 13, 2021
2 forks
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
samples = {
if(reset) {
let samples = [p_init];
for(let iter = 1; iter < iterations; iter++) {
const proposal = [rnorm(samples[iter - 1][0], proposal_sd), rnorm(samples[iter - 1][1], proposal_sd)];
const ratio = Math.min(Math.exp(log_density(proposal) - log_density(samples[iter - 1])), 1);
const u = Math.random();
if(u < ratio) {
samples[iter] = proposal;
}
else {
samples[iter] = samples[iter - 1];
}
if(animate !== false) {
yield samples;
}
}
yield samples;
}
}
Insert cell
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