Public
Edited
May 29
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
graphFromEdges = (edges) => {
const g = new graphology.Graph();

for (const [from, to] of edges) {
g.mergeNode(from);
g.mergeNode(to);
g.addEdge(from, to);
}

return g;
}
Insert cell
Insert cell
results = {
const ITERATIONS = 100;

const acc = [];

for (const dataset of datasets) {
for (const nodes of sampleSizes) {
let foundNeighbor = 0;

for (let i = 0; i < ITERATIONS; ++i) {
const sample = _.sampleSize(dataset.graph.nodes(), nodes);

if (hasNeighbors(dataset.graph, sample)) {
foundNeighbor++;
}
}

acc.push({ dataset, nodes, probability: foundNeighbor / ITERATIONS });
}
}

return acc;
}
Insert cell
// horrifying code
cleared50At = Object.entries(
_.mapValues(
_.groupBy(
results.filter((d) => d.probability > 0.5),
(d) => d.dataset.name
),
(d) => d[0].nodes
)
).map(([name, nodes]) => ({
dataset: datasets.find((d) => d.name === name),
nodes
}))
Insert cell
function hasNeighbors(graph, nodes) {
for (let i = 0; i < nodes.length; ++i) {
for (let j = i + 1; j < nodes.length; ++j) {
if (graph.areNeighbors(nodes[i], nodes[j])) {
return true;
}
}
}

return false;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
deezerEuropeEdges = deezer_europe_edges.map(({ node_1, node_2 }) => [
node_1,
node_2
])
Insert cell
Insert cell
lastfm_asia_edges.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
twitchEnEdges = musae_engb_edges.map(({ from, to }) => [from, to])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function* accumulate(g) {
const xs = [];

for await (const v of g) {
xs.push(v);
yield xs;
}
}
Insert cell
Insert cell
Insert cell
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