Public
Edited
May 23, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
var selectStep = 0;

if (!animationToggle) {
yield html`
<p style="color: darkred">Animation is not playing.</p>`;
}

while (animationToggle && selectStep < diffusionSetup.steps) {
selectStep += 2;
// selectStep %= diffusionSetup.steps;

yield plot(selectStep);
}

if (animationToggle) {
yield plot(diffusionSetup.steps - 1);
}
}
Insert cell
Insert cell
Insert cell
Insert cell
diffuse = {
const data = curve.filter((d) => d.type === "Curve"),
{ steps, beta } = diffusionSetup,
alpha = 1 - beta,
alphas = [];

for (let step = 0; step < steps; ++step) {
alphas.push(Math.pow(alpha, step));
}

const rnd = d3.randomNormal(),
dst = data.map(() => rnd());

const dataDiffusion = [];

var alpha1, alpha2;

data.map((data, i) => {
for (let step = 0; step < steps; ++step) {
alpha1 = Math.sqrt(alphas[step]);
alpha2 = Math.sqrt(1 - alphas[step]);

dataDiffusion.push({
t: data.t,
step,
value: alpha1 * data.value + alpha2 * dst[i]
});
}
});

return { data, dst, dataDiffusion };
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
curve
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3")
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