Public
Edited
1 star
Insert cell
Insert cell
{
let plt,
data = poisonComputation.dist.filter(
(d) => d.k < poisonComputation.lambda * 2
);

plt = Plot.plot({
x: { nice: true },
y: { nice: true },
color: { legend: true },
grid: true,
marks: [
Plot.dot(data, { x: "k", y: "p", fill: "p", tip: true }),
Plot.dot(data, { x: "k", y: "accu", fill: "p", tip: true }),
Plot.ruleX([poisonComputation.lambda]),
Plot.ruleX([data.find((d) => d.accu > 1 - 0.05).k]),
Plot.ruleX([data.findLast((d) => d.accu < 0.05).k])
]
});

return plt;
}
Insert cell
poisonComputation = {
const { total: M } = fact,
lambda = M * rho,
expNegLambda = Math.exp(-lambda),
dist = [];

let a = 1;

for (let k = 1; k < M; ++k) {
a *= lambda / k;
dist.push({ k, p: a * expNegLambda });
}

dist.map((d, i) =>
Object.assign(d, { accu: d3.sum(dist.slice(0, i), (d) => d.p) })
);

return { lambda, expNegLambda, dist, sum: d3.sum(dist, (d) => d.p) };
}
Insert cell
M = fact.total
Insert cell
rho = fact.born / fact.total
Insert cell
fact = {
return {
unit: 100000,
total: 14000, // x 100 thousands
born: 90 // x 100 thousands
};
}
Insert cell
d3 = require("d3")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more