Public
Edited
Aug 9, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let plt1, plt2;

plt1 = Plot.plot({
width: 600,
x: { nice: true },
y: { nice: true, domain: [-1, option.quantizations] },
grid: true,
color: { legend: true, scheme: "Tableau10" },
marks: [
Plot.dot(means, {
x: "raw",
y: "quantization",
fill: (d) => "Quantization of Linear values",
opacity: 0.5
}),
Plot.line(means, {
x: "raw",
y: "raw",
stroke: (d) => "Linear values",
strokeWidth: 3
}),
Plot.line(means, {
x: "raw",
y: "mean",
stroke: (d) => "Mean of Quanti Linear values and Noise",
strokeWidth: 5,
opacity: 0.6
}),
Plot.dot(means, {
x: "raw",
y: (d) => d.mean - d.raw,
fill: "gray",
opacity: 0.5
}),
Plot.dot(means, {
x: "raw",
y: (d) => d.mean - d.quantization,
fill: "gray",
opacity: 0.5
})
]
});

plt2 = Plot.plot({
width: 600,
x: { nice: true },
y: { nice: true, domain: [-1, 1] },
grid: true,
color: { legend: true, scheme: "Tableau10" },
marks: [
Plot.dot(means, {
x: "raw",
y: (d) => d.mean - d.raw,
fill: (d) => "Error between Mean Quanti and Linera values"
}),
Plot.dot(means, {
x: "raw",
y: (d) => d.mean - d.quantization,
fill: (d) => "Error between Mean Quanti and Quanti"
})
]
});

return htl.html`
<div style="display:flex">
${plt1}
${plt2}
</div>
`;
}
Insert cell
means = {
let uniques = [...new Set(data.map((d) => d.raw))],
filtered,
means = [];

uniques.map((raw) => {
(filtered = data.filter((d) => d.raw === raw)),
means.push({
raw,
mean: d3.mean(filtered, (d) => d.noisedQuantization),
quantization: filtered[0].quantization
});
});

return means;
}
Insert cell
means
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data = {
let data = [],
raw,
quantization,
noised,
noisedQuantization,
mu = 0,
{ sigma } = option,
scaleLinear = d3
.scaleLinear()
.domain([0, option.samples])
.range([0, option.quantizations]),
rndNormal = d3.randomNormal(mu, sigma);

for (let i = 0; i < scaleLinear.domain()[1]; ++i) {
raw = scaleLinear(i);
quantization = parseInt(raw + 0.5);
for (let j = 0; j < option.repeats; ++j) {
noised = raw + rndNormal();
noisedQuantization = parseInt(noised + 0.5);
data.push({ raw, quantization, noised, noisedQuantization });
}
}

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

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