Public
Edited
Apr 8
Insert cell
Insert cell
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

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