Public
Edited
May 12, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
form
Insert cell
Insert cell
Insert cell
Plot.plot({
round: true,
color: { legend: true },
title: "xy error Dist",
// y: { type: "log" },
// x: { type: "symlog" },
marks: [
Plot.lineY(
mulSamples,
Plot.binX(
{ y: "count", filter: null },
{ x: "de", thresholds: 100, stroke: "blue", cumulative: false }
)
),
Plot.ruleY([0])
// Plot.ruleX([form.alpha]),
// Plot.ruleX([form.beta])
]
})
Insert cell
Insert cell
Insert cell
randNorm = d3.randomNormal(0, quant.s)
Insert cell
sampleRandGen = d3.randomNormal(0, (form.alpha - form.beta) / 2)
Insert cell
Insert cell
x = d3.ticks(form.beta, form.alpha, form.N)
// x = d3.range(form.beta, form.alpha, form.dx)
Insert cell
class IntQuant {
constructor(b, alpha, beta) {
this.b = b;
this.alpha = alpha;
this.beta = beta;
this.int_low = -Math.pow(2, b - 1);
this.int_high = Math.pow(2, b - 1) - 1;
this.s = (this.int_high - this.int_low) / (this.alpha - this.beta);
this.z = Math.round(this.beta * this.s) - this.int_low;
}

quantize(x) {
const q = x * this.s - this.z;
return Math.min(Math.max(Math.round(q), this.int_low), this.int_high);
// return Math.round(q);
}

dequantize(q) {
const x = (q + this.z) / this.s;
return x;
}
}
Insert cell
quant = new IntQuant(form.b, form.alpha, form.beta)
// quant = new IntQuant(2, 4, -4)
Insert cell
quant.quantize(-1)
Insert cell
data = x
.map((d) => {
return { x: d, q: quant.quantize(d) };
})
.map((d) => Object.assign(d, { dq: quant.dequantize(d.q) }))
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