Public
Edited
Jul 31, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
_data = ({
nodes: [
{ name: "👑", category: "👑", value: heads_chance },
{ name: "🦘", category: "🦘", value: tails_chance },

{ name: "👑👑", category: "👑" },
{ name: "👑🦘", category: "🦘" },
{ name: "🦘👑", category: "👑" },
{ name: "🦘🦘", category: "🦘" }
],
links: [
{ source: "👑", target: "👑👑", value: heads_chance * heads_chance },
{ source: "👑", target: "👑🦘", value: heads_chance * tails_chance },
{ source: "🦘", target: "🦘👑", value: tails_chance * heads_chance },
{ source: "🦘", target: "🦘🦘", value: tails_chance * tails_chance }
]
})
Insert cell
data = {
const seed = [
{ name: "👑", category: "👑", value: heads_chance },
{ name: "🦘", category: "🦘", value: tails_chance }
];

const nodes = _.cloneDeep(seed);
const links = [];

// for each flip (starting with the flip #2)
for (let flip_i = 2; flip_i <= num_flips; flip_i++) {
// for each source (previous flip)
const num_sources = 2 ** (flip_i - 1);
for (let source_i = 0; source_i < num_sources; source_i++) {
// for each option (heads or tails)
for (let seed_i = 0; seed_i < seed.length; seed_i++) {
// const source = nodes[flip_i - 2][source_i];
// const target = _.cloneDeep(seed[seed_i]);
// target.chance *= source.chance;
// const match = nodes.find(
// (n) => n.category == target.category && n.chance == target.chance
// );
// if (match == undefined) {
// nodes.push(target);
// } else {
// match.chance *= 2;
// }
// links.push({
// source: formatNodeName(source),
// target: formatNodeName(target),
// value: Math.round(10 ** 2 * target.chance) / 10 ** 2
// });
}
}
}

return {
nodes,
links
};
}
Insert cell
formatNodeName = ({ category, chance }) =>
`${category} ${Math.round(chance * 100)}%`
Insert cell
Insert cell
Insert cell
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