Skip to content

ADescribe · describe.network

Network description (size, degrees, clustering, centrality)

Who is connected to whom — how big and dense is the network, how clustered, and which nodes are central?

Describes a network given as an edge list (one row per edge, with the two ends in two columns), with an optional node table for labels and attributes. Reports size and density, the degree distribution, separate parts, reciprocity for directed networks, clustering (transitivity and the average local clustering), degree assortativity, distances (average and diameter), and per-node centrality: degree, betweenness, closeness, eigenvector and PageRank. The app checks the edge list first (missing ends, self-loops, repeated edges, isolated nodes, ids missing from the node table), draws the network as a map and an adjacency matrix, and saves a node table you can keep as a dataset.

Experimental Python and R agree to 6 decimals Seeded Also called network analysis, graph statistics, social network analysis…

A real result

Example “Blocks defaults”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Network description (size, degrees, clustering, centrality)Recorded · Python and R agreeRecorded 2026-11-25 · 243 values compared
R

A undirected network of 36 nodes and 98 edges (density 0.156); 1 part(s), the largest with 36 nodes.

Nodes
36
Edges
98
Density
0.1556
Separate parts
1
Transitivity
0.2073
Degree assortativity
−0.1870

Plots

Network mapWho is connected to whom, which groups hang together and which nodes sit at the center?
View data
FromPartNodeDegreeToWeightxy
0part 1p01552.3000.2119−0.2408
0part 1p02661.960−0.1900−0.6998
0part 1p039111.130−0.1845−0.4055
0part 1p045150.5200−0.4254−0.4638
0part 1p054321.040−0.1812−1
1part 1p06721.8200.0352−0.5426
1part 1p07331.6100.1284−0.7370
1part 1p08542.390−0.2899−0.5076
1part 1p09451.920−0.3873−0.7101
1part 1p10690.8100−0.2812−0.7735
1part 1p112110.6900−0.0229−0.7698
2part 1p12850.9800−0.0552−0.3536
2part 1p13661.8800.05550.8281
2part 1p14281.1100.58210.9136
2part 1p15791.6400.04460.6711
2part 1p167101.5700.06720.2631
2part 1p174211.100−0.21580.7160
2part 1p182330.69000.23460.9191
2part 1p195350.7600−0.18140.5104
3part 1p20770.82000.26840.5586
3part 1p21880.5300−0.02260.4294
3part 1p22491.820−0.30910.2217
3part 1p237291.5100.08620.5238
4part 1p24561.6100.35930.7552
4part 1p25780.7500−0.2040−0.0692
4part 1p26492.3000.10020.1600
5part 1p27470.52000.3560−0.2187
5part 1p28791.9600.02840.0103
5part 1p296262.180−0.1032−0.1302
5part 1p308312.300−0.12580.0778
7part 1p31691.1200.18350.0367
7part 1p324111.4300.0758−0.2869
7part 1p336241.2800.22970.2908
8part 1p347112.3800.1095−0.0263
10part 1p354111.6300.35880.0270
11part 1p365151.990−0.33560.0227
11———282.330——
11———301.150——
12———161.980——
12———171.480——
12———181.950——
12———191.160——
12———220.8900——
12———230.7400——
13———192.450——
13———231.780——
14———152.260——
14———160.8700——
14———181.010——
14———192.470——
14———202.440——
14———222.250——
14———230.6500——
15———182.200——
15———191.450——
15———201.030——
15———222.050——
16———211.770——
16———221.150——
17———201.990——

First 60 of 98 rows.

Degree distributionDo a few nodes hold most of the ties (a heavy tail), or are degrees much alike?
View data
Degree kDegreeShare of nodes with degree ≥ k
2Degree1
3Degree0.9167
4Degree0.8889
5Degree0.6667
6Degree0.5000
7Degree0.3333
8Degree0.1111
9Degree0.0278
Adjacency matrixWhich nodes link to which, and do groups form blocks of dense ties?
View data
ColumnPartNodeOrderRowWeight
5part 1p01202.300
6part 1p021101.960
11part 1p032001.130
15part 1p042900.5200
32part 1p05501.040
2part 1p061411.820
3part 1p071511.610
4part 1p081912.390
5part 1p092211.920
9part 1p102410.8100
11part 1p112710.6900
5part 1p123320.9800
6part 1p13121.880
8part 1p14921.110
9part 1p151221.640
10part 1p162821.570
21part 1p173021.100
33part 1p183220.6900
35part 1p19020.7600
7part 1p20330.8200
8part 1p21730.5300
9part 1p221831.820
29part 1p232331.510
6part 1p243541.610
8part 1p25440.7500
9part 1p26842.300
7part 1p271650.5200
9part 1p282151.960
26part 1p292552.180
31part 1p302652.300
9part 1p313171.120
11part 1p323471.430
24part 1p33671.280
11part 1p341082.380
11part 1p3513101.630
15part 1p3617111.990
28———112.330
30———111.150
16———121.980
17———121.480
18———121.950
19———121.160
22———120.8900
23———120.7400
19———132.450
23———131.780
15———142.260
16———140.8700
18———141.010
19———142.470
20———142.440
22———142.250
23———140.6500
18———152.200
19———151.450
20———151.030
22———152.050
21———161.770
22———161.150
20———171.990

First 60 of 98 rows.

Most central nodes (by PageRank)

NodeDegreePageRankEigenvectorClusteringBetweennessCloseness
p3080.04310.23910.10710.09360.4930
p1280.04250.18730.07140.10910.4930
p2180.04180.33880.25000.08250.4667
p0670.03960.14360.19050.05030.4430
p0390.03950.12230.08330.14340.5000
p1570.03780.31610.38100.02260.4321
p2570.03720.26180.23810.04610.4667
p2870.03660.16780.14290.04650.4545
p1670.03620.29640.33330.08020.4861
p2070.03410.21360.28570.08190.4430
p2370.03280.27310.28570.04600.4430
p1060.03260.10610.46670.01960.4023
p0260.03120.10900.33330.02600.4217
p2960.03010.19250.26670.02090.4605
p3470.02970.16500.14290.09580.4930
p1360.02940.13450.13330.02570.3763
p3650.02810.22920.30000.03180.4861
p1950.02760.19390.10000.03700.4375
p0540.02510.06930.16670.00470.3271
p2740.02510.09790.16670.01470.4118
p0150.02440.10140.10000.05720.4605
p3360.02430.13860.13330.06840.4861
p3160.02400.12260.20000.04870.4667
p3240.02370.13820.16670.01040.4321
p0450.02230.08980.20000.02770.3977

Network checks

CheckCount
Edge rows101
Edge rows left out (missing source, target or weight)1
Self-loops1
Repeated edges merged1
Isolated nodes0
Separate parts1
  • 1 of 101 rows were left out because a value was missing.
  • 1 edge(s) join a node to itself; measures on the simple network leave them out.
  • 1 edge(s) repeat a pair listed earlier; the simple network merges them and adds their weights.
Python

A undirected network of 36 nodes and 98 edges (density 0.156); 1 part(s), the largest with 36 nodes.

Nodes
36
Edges
98
Density
0.1556
Separate parts
1
Transitivity
0.2073
Degree assortativity
−0.1870

To keep this page light, the plots are shown once, under the R tab.

Most central nodes (by PageRank)

NodeDegreePageRankEigenvectorClusteringBetweennessCloseness
p3080.04310.23910.10710.09360.4930
p1280.04250.18730.07140.10910.4930
p2180.04180.33880.25000.08250.4667
p0670.03960.14360.19050.05030.4430
p0390.03950.12230.08330.14340.5000
p1570.03780.31610.38100.02260.4321
p2570.03720.26180.23810.04610.4667
p2870.03660.16780.14290.04650.4545
p1670.03620.29640.33330.08020.4861
p2070.03410.21360.28570.08190.4430
p2370.03280.27310.28570.04600.4430
p1060.03260.10610.46670.01960.4023
p0260.03120.10900.33330.02600.4217
p2960.03010.19250.26670.02090.4605
p3470.02970.16500.14290.09580.4930
p1360.02940.13450.13330.02570.3763
p3650.02810.22920.30000.03180.4861
p1950.02760.19390.10000.03700.4375
p0540.02510.06930.16670.00470.3271
p2740.02510.09790.16670.01470.4118
p0150.02440.10140.10000.05720.4605
p3360.02430.13860.13330.06840.4861
p3160.02400.12260.20000.04870.4667
p3240.02370.13820.16670.01040.4321
p0450.02230.08980.20000.02770.3977

Network checks

CheckCount
Edge rows101
Edge rows left out (missing source, target or weight)1
Self-loops1
Repeated edges merged1
Isolated nodes0
Separate parts1
  • 1 of 101 rows were left out because a value was missing.
  • 1 edge(s) join a node to itself; measures on the simple network leave them out.
  • 1 edge(s) repeat a pair listed earlier; the simple network merges them and adds their weights.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Worked examples in the app

  • Blocks defaultsgraph_blocks_edges · source: from · target: to · weight: strength
  • Blocks node tablegraph_blocks_edges · source: from · target: to · weight: strength
  • Blocks unweightedgraph_blocks_edges · source: from · target: to · weight: strength
  • Directed followsgraph_directed · source: follower · target: followed
  • Karate clubgraph_karate · source: member_a · target: member_b · weight: contexts
  • Karate unweightedgraph_karate · source: member_a · target: member_b
  • Distances skippedgraph_karate · source: member_a · target: member_b
  • Degenerate all nagraph_blocks_edges · source: from · target: to · weight: strength

In the guides

Where it sits in the decision guides

  • Type: structured (tabular), unstructured (text, images, audio, video), time series / sequential, graph / relational · DS & ML Decision Guide · Key data characteristics — what influences method choice
  • Structure: independent, hierarchical / grouped, temporal / spatial, networked · DS & ML Decision Guide · Key data characteristics — what influences method choice
  • EDA (correlation, distributions) · DS & ML Decision Guide · Describe — summarize and visualize

What you need

Source (from)categorical / numeric · 1 column
The node at one end of each edge: a name or id. For directed networks, where the edge starts.
Target (to)categorical / numeric · 1 column
The node at the other end. For directed networks, where the edge points.
Edge weightnumeric · 0–1 column
Optional strength of each tie (calls, trades, co-authored papers). Repeated edges add their weights.

Choices you make

options

Directed edgesdefault off

On when each edge points from source to target (follows, citations, payments); off for mutual ties.

Node tabledefault —

Optional dataset with one row per node: its id, a label to color by and attributes, saved with the results.

statistics

Use weightsdefault on

Strength, eigenvector centrality and PageRank use the edge weights. Distances always count steps.

PageRank dampingdefault 0.85

Chance a random walker follows an edge rather than jumping anywhere; 0.85 is the usual choice.

Advanced

Largest network for distancesdefault 5000

Betweenness, closeness and distances need one search per node; above this many nodes they are skipped.

Checks and remedies

CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.

  • Every tie is listedNot checked from data: state why it holds

    Missing edges look like absent ties; a sampled or partly observed network understates degrees and clustering.

  • One kind of tieNot checked from data: state why it holds

    All edges mean the same relation (friendship, trade); mixing kinds blurs every measure.

What it reports

n_nodes
How many distinct ids appear in the edge list or the node table.
n_edges
Distinct pairs of different nodes in the simple network (a directed network counts A→B and B→A separately).
n_edge_rows
Usable rows of the edge list: rows with both ends (and a weight, when one is bound), before merging repeats.
density
Edges present as a share of all possible pairs: m / (n(n−1)/2), or m / (n(n−1)) when directed.
mean_degree
How many other nodes a node is tied to; when directed, in-degree counts ties received and out-degree ties sent.
median_degree
How many other nodes a node is tied to; when directed, in-degree counts ties received and out-degree ties sent.
max_degree
How many other nodes a node is tied to; when directed, in-degree counts ties received and out-degree ties sent.
max_in_degree
How many other nodes a node is tied to; when directed, in-degree counts ties received and out-degree ties sent.
max_out_degree
How many other nodes a node is tied to; when directed, in-degree counts ties received and out-degree ties sent.
reciprocity
Share of directed edges whose reverse edge is also present: how often a tie is returned.
components
Groups of nodes linked by some path, ignoring direction; nodes in different parts can't reach each other.
largest_component
Groups of nodes linked by some path, ignoring direction; nodes in different parts can't reach each other.
largest_share
Groups of nodes linked by some path, ignoring direction; nodes in different parts can't reach each other.
isolates
A node with no edge to any other node, usually from the node table or with only a self-loop.
self_loops
An edge from a node to itself; counted in the checks and left out of the measures.
duplicate_edges
A row naming a pair listed earlier (either way round when undirected); merged into one edge, weights added.
triangles
Sets of three nodes all tied to each other; the building block of clustering. Direction is ignored.
transitivity
Share of connected triples (A–B–C) that close into a triangle: how often a friend of a friend is a friend.
avg_clustering
For one node, the share of its neighbor pairs that are tied; the average over all nodes counts nodes below two neighbors as 0.
assortativity
Correlation between the degrees at the two ends of each edge: positive when hubs link to hubs, negative when hubs link to small nodes.
degree_centralization
How far the network is from a star: summed gaps to the top degree over the most a star could have, from 0 (even) to 1.
avg_path_length
Mean number of steps on a shortest path, over all pairs that can reach each other.
diameter
The longest shortest path, in steps, between any two nodes that can reach each other.
max_betweenness
Share of shortest paths between other pairs that pass through a node (0 to 1): high for brokers between groups.
max_closeness
How near a node is to the others: reachable nodes over summed distances, scaled down when it reaches only part of the network.
max_eigenvector
A node is central when its neighbors are central: the leading eigenvector of the adjacency matrix, scaled to length 1.
max_pagerank
Share of time a random walker spends at a node, following edges or jumping anywhere; sums to 1 over all nodes.

Per group, level or term: degree[<node>], in_degree[<node>], out_degree[<node>], clustering[<node>], betweenness[<node>], closeness[<node>], eigenvector[<node>], pagerank[<node>]

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-8). Python uses numpy, pandas, codesplash; R uses jsonlite, nanoparquet, codesplashr.

Default traps between the two languages

  • Counts, degrees, clustering, distances and betweenness are exact in both engines (same breadth-first searches over the host's node order); eigenvector centrality and PageRank are power iterations to the same stopping rule, so they agree to rounding.
  • The network map's coordinates (seeded Fruchterman–Reingold from the shared Wichmann–Hill stream) are drawn, not compared: summation order can move them in the last digits.
Python

The exact script CodeSplash ran for example “Blocks defaults” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Network description (size, degrees, clustering, centrality)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.network 1.0.0 · spec ef897a2feb3141bd
# Dataset: graph_blocks_edges (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np

import codesplash as cs
from codesplash import graph as cg
from codesplash.graph import describe as gd
from codesplash.graph import layout as gl

# %% Network
# The app read the edge list once and wrote the network next to this run (graph/ in the output folder):
# nodes in a fixed order, the edges, and the simple network (self-loops left out, repeated edges merged with
# their weights added). Python and R read the same files, so both describe the same network.
out_dir = "target/academy-parity/run-8142/describe.network/blocks_defaults/out-python"
g = cg.read(out_dir)
warnings = list(g.warnings)
weighted = True and g.weighted
damping = 0.85
max_path_nodes = int(5000)
seed = 42
MAP_NODES = 2000  # largest network drawn as a map
MATRIX_NODES = 300  # largest network drawn as a matrix
PER_NODE = 200  # per-node values go into the result for networks up to this size
if weighted:
    bad = int((g.edges["w"].to_numpy(dtype=float) <= 0).sum())
    if bad:
        cs.cs_error("CS_E_INVALID_VALUES", column="strength", requirement="positive for weighted measures (or turn off Use weights)", count=bad)
n = g.n
m = len(g.si)
meta = g.meta

# %% Measures
# Degrees, density, reciprocity, clustering and assortativity, then one breadth-first search per node for
# betweenness, closeness and distances (Brandes 2001), then eigenvector centrality and PageRank by power
# iteration. Definitions follow networkx; the twins are codesplash.graph.describe and codesplashr.
deg = gd.degrees(g)
cl = gd.clustering(g)
pa = gd.paths(g, max_path_nodes)
ev = gd.eigenvector(g, weighted)
pr = gd.pagerank(g, damping, weighted)
comp = gd.components(g)
if not ev["converged"]:
    warnings.append(cs.cs_warning("CS_W_NO_CONVERGENCE", what="Eigenvector centrality"))
if not pr["converged"]:
    warnings.append(cs.cs_warning("CS_W_NO_CONVERGENCE", what="PageRank"))
if pa is None:
    warnings.append(f"Betweenness, closeness and distances were skipped: the network has more than {max_path_nodes} nodes.")


def nn(x):
    """A finite number, or None."""
    x = float(x)
    return x if np.isfinite(x) else None


degree = deg["degree"]
centralization = None
if not g.directed and n > 2:
    centralization = float((degree.max() - degree).sum()) / ((n - 1) * (n - 2))
values = {
    "n_nodes": n,
    "n_edges": m,
    "n_edge_rows": int(meta["n_edges"]),
    "density": nn(gd.density(g)),
    "mean_degree": float(degree.mean()),
    "median_degree": float(np.median(degree)),
    "max_degree": int(degree.max()),
    "max_in_degree": int(deg["in_degree"].max()) if g.directed else None,
    "max_out_degree": int(deg["out_degree"].max()) if g.directed else None,
    "reciprocity": nn(gd.reciprocity(g)) if g.directed else None,
    "components": int(meta["components"]),
    "largest_component": int(meta["largest_component"]),
    "largest_share": int(meta["largest_component"]) / n,
    "isolates": int(meta["isolates"]),
    "self_loops": int(meta["self_loops"]),
    "duplicate_edges": int(meta["duplicate_edges"]),
    "triangles": cl["triangles"],
    "transitivity": cl["transitivity"],
    "avg_clustering": cl["average"],
    "assortativity": nn(gd.assortativity(g)),
    "degree_centralization": centralization,
    "avg_path_length": nn(pa["avg_path_length"]) if pa else None,
    "diameter": nn(pa["diameter"]) if pa else None,
    "max_betweenness": float(pa["betweenness"].max()) if pa else None,
    "max_closeness": float(pa["closeness"].max()) if pa else None,
    "max_eigenvector": float(ev["x"].max()),
    "max_pagerank": float(pr["x"].max()),
}
if n <= PER_NODE:
    for k, node in enumerate(g.node_id):
        values[f"degree[{node}]"] = int(degree[k])
        if g.directed:
            values[f"in_degree[{node}]"] = int(deg["in_degree"][k])
            values[f"out_degree[{node}]"] = int(deg["out_degree"][k])
        values[f"clustering[{node}]"] = float(cl["local"][k])
        if pa:
            values[f"betweenness[{node}]"] = float(pa["betweenness"][k])
            values[f"closeness[{node}]"] = float(pa["closeness"][k])
        values[f"eigenvector[{node}]"] = float(ev["x"][k])
        values[f"pagerank[{node}]"] = float(pr["x"][k])

# %% Node table
# One row per node (node_id first); the app can save it as a dataset ("Save node table as dataset").
label = g.nodes[g.label].astype(object).where(g.nodes[g.label].notna(), None).tolist() if g.label else None
xy = gl.fruchterman_reingold(g, seed) if n <= MAP_NODES else None
cols = {}
if label is not None:
    cols[g.label] = label
cols["component"] = comp + 1
cols["degree"] = degree
if g.directed:
    cols["in_degree"] = deg["in_degree"]
    cols["out_degree"] = deg["out_degree"]
if g.weighted:
    if g.directed:
        cols["in_strength"] = deg["in_strength"]
        cols["out_strength"] = deg["out_strength"]
    else:
        cols["strength"] = deg["strength"]
cols["clustering"] = cl["local"]
if pa:
    cols["betweenness"] = pa["betweenness"]
    cols["closeness"] = pa["closeness"]
cols["eigenvector"] = ev["x"]
cols["pagerank"] = pr["x"]
if xy is not None:
    cols["map_x"], cols["map_y"] = xy
artifact = cg.write_nodes(out_dir, g, cols)

# %% Tables
order = np.lexsort((np.arange(n), -pr["x"]))[:25]
node_cols = [{"key": "node", "label": "Node"}]
if label is not None:
    node_cols.append({"key": "label", "label": g.label})
node_cols += [{"key": "degree", "label": "Degree", "type": "integer"}, {"key": "pagerank", "label": "PageRank", "type": "number"},
              {"key": "eigenvector", "label": "Eigenvector", "type": "number"}, {"key": "clustering", "label": "Clustering", "type": "number"}]
if pa:
    node_cols += [{"key": "betweenness", "label": "Betweenness", "type": "number"}, {"key": "closeness", "label": "Closeness", "type": "number"}]
rows = []
for k in order.tolist():
    r = {"node": g.node_id[k], "degree": int(degree[k]), "pagerank": float(pr["x"][k]), "eigenvector": float(ev["x"][k]), "clustering": float(cl["local"][k])}
    if label is not None:
        r["label"] = None if label[k] is None else str(label[k])
    if pa:
        r["betweenness"] = float(pa["betweenness"][k])
        r["closeness"] = float(pa["closeness"][k])
    rows.append(r)
checks = [
    ("Edge rows", int(meta["input_rows"])),
    ("Edge rows left out (missing source, target or weight)", int(meta["dropped_rows"])),
    ("Self-loops", int(meta["self_loops"])),
    ("Repeated edges merged", int(meta["duplicate_edges"])),
    ("Isolated nodes", int(meta["isolates"])),
    ("Separate parts", int(meta["components"])),
]
nt = meta.get("node_table")
if nt:
    checks += [("Node table rows", int(nt["rows"])), ("Node table rows left out", int(nt["dropped_rows"])),
               ("Nodes not in the node table", int(nt["missing_ids"])), ("Node table nodes with no edges", int(nt["extra_ids"]))]
tables = [
    {"key": "top_nodes", "title": "Most central nodes (by PageRank)", "columns": node_cols, "rows": rows},
    {"key": "checks", "title": "Network checks", "columns": [{"key": "check", "label": "Check"}, {"key": "count", "label": "Count", "type": "integer"}],
     "rows": [{"check": c, "count": k} for c, k in checks]},
]

# %% Charts
def padded(values, rows):
    """Node and edge columns share one chart table: shorter columns end in empty cells."""
    vals = list(values.tolist() if hasattr(values, "tolist") else values)
    return vals + [None] * (rows - len(vals))


group = [("(missing)" if v is None else str(v)) for v in label] if label is not None else [f"part {c + 1}" for c in comp]
group_title = g.label if label is not None else "Part"
charts = []
if xy is not None:
    show = min(m, 20000)
    rows_map = max(n, show)
    charts.append(cs.chart("map", "network-graph", "Network map", {
        "x": cs.col("x", padded(xy[0], rows_map), "numeric"),
        "y": cs.col("y", padded(xy[1], rows_map), "numeric"),
        "node": cs.col("Node", padded(g.node_id, rows_map), "categorical"),
        "size": cs.col("Degree", padded(degree, rows_map), "numeric"),
        "group": cs.col(group_title, padded(group, rows_map), "categorical"),
        "from": cs.col("From", padded(g.si[:show], rows_map), "numeric"),
        "to": cs.col("To", padded(g.sj[:show], rows_map), "numeric"),
        "weight": cs.col("Weight", padded(g.sw[:show], rows_map), "numeric") if g.weighted else None,
    }, controls={"directed": g.directed}, note=None if show == m else f"{show} of {m} edges drawn."))
else:
    charts.append(cs.chart("map", "network-graph", "Network map", {}, note=f"The map is drawn for networks up to {MAP_NODES} nodes; this one has {n}."))
if g.directed:
    k_in, p_in = gd.degree_ccdf(deg["in_degree"])
    k_out, p_out = gd.degree_ccdf(deg["out_degree"])
    ks, ps, series = list(k_in) + list(k_out), list(p_in) + list(p_out), ["In-degree"] * len(k_in) + ["Out-degree"] * len(k_out)
    series_levels = ["In-degree", "Out-degree"]
else:
    k_all, p_all = gd.degree_ccdf(degree)
    ks, ps, series, series_levels = list(k_all), list(p_all), ["Degree"] * len(k_all), ["Degree"]
charts.append(cs.chart("degrees", "degree-ccdf", "Degree distribution", {
    "degree": cs.col("Degree k", ks, "numeric"),
    "share": cs.col("Share of nodes with degree ≥ k", ps, "numeric"),
    "series": cs.col("Degree", series, "categorical", series_levels),
}))
if n <= MATRIX_NODES:
    morder = sorted(range(n), key=lambda k: (group[k] == "(missing)", group[k], -int(degree[k]), k))
    rows_mx = max(n, m)
    charts.append(cs.chart("matrix", "adjacency-matrix", "Adjacency matrix", {
        "row": cs.col("Row", padded(g.si, rows_mx), "numeric"),
        "col": cs.col("Column", padded(g.sj, rows_mx), "numeric"),
        "value": cs.col("Weight" if g.weighted else "Edge", padded(g.sw, rows_mx), "numeric"),
        "node": cs.col("Node", padded(g.node_id, rows_mx), "categorical"),
        "group": cs.col(group_title, padded(group, rows_mx), "categorical"),
        "order": cs.col("Order", padded(morder, rows_mx), "numeric"),
    }, controls={"directed": g.directed}))

# %% Result
kind = "directed" if g.directed else "undirected"
dens = "undefined" if values["density"] is None else f"{values['density']:.3f}"
summary = f"A {kind} network of {n} nodes and {m} edges (density {dens}); {values['components']} part(s), the largest with {values['largest_component']} nodes."
cs.publish({
    "title": "Network description (size, degrees, clustering, centrality)",
    "engine": cs.engine_info("numpy", "pandas"),
    "n": n,
    "summary": summary,
    "statistics": [
        {"key": "n_nodes", "label": "Nodes", "value": n, "format": "integer"},
        {"key": "n_edges", "label": "Edges", "value": m, "format": "integer"},
        {"key": "density", "label": "Density", "value": values["density"]},
        {"key": "components", "label": "Separate parts", "value": values["components"], "format": "integer"},
        {"key": "transitivity", "label": "Transitivity", "value": values["transitivity"]},
        {"key": "assortativity", "label": "Degree assortativity", "value": values["assortativity"]},
    ],
    "tables": tables,
    "values": values,
    "charts": charts,
    "warnings": warnings,
    "artifacts": [artifact],
})
R

The exact script CodeSplash ran for example “Blocks defaults” · R version 4.5.1 (2025-06-13)

# Network description (size, degrees, clustering, centrality)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method describe.network 1.0.0 · spec ef897a2feb3141bd
# Dataset: graph_blocks_edges (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Network
# The app read the edge list once and wrote the network next to this run (graph/ in the output folder):
# nodes in a fixed order, the edges, and the simple network (self-loops left out, repeated edges merged with
# their weights added). Python and R read the same files, so both describe the same network.
out_dir <- "target/academy-parity/run-8142/describe.network/blocks_defaults/out-r"
g <- cs_graph_read(out_dir)
warnings <- g$warnings
weighted <- TRUE && isTRUE(g$weighted)
damping <- 0.85
max_path_nodes <- as.integer(5000)
seed <- 42
MAP_NODES <- 2000  # largest network drawn as a map
MATRIX_NODES <- 300  # largest network drawn as a matrix
PER_NODE <- 200  # per-node values go into the result for networks up to this size
if (weighted) {
  bad <- sum(as.numeric(g$edges[["w"]]) <= 0)
  if (bad > 0) cs_error("CS_E_INVALID_VALUES", column = "strength", requirement = "positive for weighted measures (or turn off Use weights)", count = bad)
}
n <- g$n
m <- length(g$si)
meta <- g$meta

# %% Measures
# Degrees, density, reciprocity, clustering and assortativity, then one breadth-first search per node for
# betweenness, closeness and distances (Brandes 2001), then eigenvector centrality and PageRank by power
# iteration. Definitions follow networkx; the twins are codesplashr R/graph_describe.R and codesplash.
deg <- cs_graph_degrees(g)
cl <- cs_graph_clustering(g)
pa <- cs_graph_paths(g, max_path_nodes)
ev <- cs_graph_eigenvector(g, weighted)
pr <- cs_graph_pagerank(g, damping, weighted)
comp <- cs_graph_components(g)
if (!ev$converged) warnings <- c(warnings, cs_warning("CS_W_NO_CONVERGENCE", what = "Eigenvector centrality"))
if (!pr$converged) warnings <- c(warnings, cs_warning("CS_W_NO_CONVERGENCE", what = "PageRank"))
if (is.null(pa)) {
  warnings <- c(warnings, sprintf("Betweenness, closeness and distances were skipped: the network has more than %d nodes.", max_path_nodes))
}

nn <- function(x) if (is.finite(x)) as.numeric(x) else NULL

degree <- deg$degree
centralization <- NULL
if (!isTRUE(g$directed) && n > 2) centralization <- sum(as.numeric(max(degree) - degree)) / ((n - 1) * (n - 2))
values <- list(
  n_nodes = n,
  n_edges = m,
  n_edge_rows = as.integer(meta$n_edges),
  density = nn(cs_graph_density(g)),
  mean_degree = mean(as.numeric(degree)),
  median_degree = stats::median(as.numeric(degree)),
  max_degree = max(degree),
  max_in_degree = if (isTRUE(g$directed)) max(deg$in_degree) else NULL,
  max_out_degree = if (isTRUE(g$directed)) max(deg$out_degree) else NULL,
  reciprocity = if (isTRUE(g$directed)) nn(cs_graph_reciprocity(g)) else NULL,
  components = as.integer(meta$components),
  largest_component = as.integer(meta$largest_component),
  largest_share = as.integer(meta$largest_component) / n,
  isolates = as.integer(meta$isolates),
  self_loops = as.integer(meta$self_loops),
  duplicate_edges = as.integer(meta$duplicate_edges),
  triangles = cl$triangles,
  transitivity = cl$transitivity,
  avg_clustering = cl$average,
  assortativity = nn(cs_graph_assortativity(g)),
  degree_centralization = centralization,
  avg_path_length = if (!is.null(pa)) nn(pa$avg_path_length) else NULL,
  diameter = if (!is.null(pa)) nn(pa$diameter) else NULL,
  max_betweenness = if (!is.null(pa)) max(pa$betweenness) else NULL,
  max_closeness = if (!is.null(pa)) max(pa$closeness) else NULL,
  max_eigenvector = max(ev$x),
  max_pagerank = max(pr$x)
)
if (n <= PER_NODE) {
  for (k in seq_len(n)) {
    node <- g$node_id[k]
    values[[sprintf("degree[%s]", node)]] <- degree[k]
    if (isTRUE(g$directed)) {
      values[[sprintf("in_degree[%s]", node)]] <- deg$in_degree[k]
      values[[sprintf("out_degree[%s]", node)]] <- deg$out_degree[k]
    }
    values[[sprintf("clustering[%s]", node)]] <- cl$local[k]
    if (!is.null(pa)) {
      values[[sprintf("betweenness[%s]", node)]] <- pa$betweenness[k]
      values[[sprintf("closeness[%s]", node)]] <- pa$closeness[k]
    }
    values[[sprintf("eigenvector[%s]", node)]] <- ev$x[k]
    values[[sprintf("pagerank[%s]", node)]] <- pr$x[k]
  }
}

# %% Node table
# One row per node (node_id first); the app can save it as a dataset ("Save node table as dataset").
label <- if (!is.null(g$label)) g$nodes[[g$label]] else NULL
xy <- if (n <= MAP_NODES) cs_graph_layout_fr(g, seed) else NULL
cols <- list()
if (!is.null(label)) cols[[g$label]] <- label
cols$component <- comp + 1L
cols$degree <- degree
if (isTRUE(g$directed)) {
  cols$in_degree <- deg$in_degree
  cols$out_degree <- deg$out_degree
}
if (isTRUE(g$weighted)) {
  if (isTRUE(g$directed)) {
    cols$in_strength <- deg$in_strength
    cols$out_strength <- deg$out_strength
  } else {
    cols$strength <- deg$strength
  }
}
cols$clustering <- cl$local
if (!is.null(pa)) {
  cols$betweenness <- pa$betweenness
  cols$closeness <- pa$closeness
}
cols$eigenvector <- ev$x
cols$pagerank <- pr$x
if (!is.null(xy)) {
  cols$map_x <- xy$x
  cols$map_y <- xy$y
}
artifact <- cs_graph_write_nodes(out_dir, g, cols)

# %% Tables
ord <- head(order(-pr$x, seq_len(n)), 25L)
node_cols <- list(list(key = "node", label = "Node"))
if (!is.null(label)) node_cols[[length(node_cols) + 1L]] <- list(key = "label", label = g$label)
node_cols <- c(node_cols, list(
  list(key = "degree", label = "Degree", type = "integer"), list(key = "pagerank", label = "PageRank", type = "number"),
  list(key = "eigenvector", label = "Eigenvector", type = "number"), list(key = "clustering", label = "Clustering", type = "number")
))
if (!is.null(pa)) {
  node_cols <- c(node_cols, list(list(key = "betweenness", label = "Betweenness", type = "number"), list(key = "closeness", label = "Closeness", type = "number")))
}
rows <- lapply(ord, function(k) {
  r <- list(node = g$node_id[k], degree = degree[k], pagerank = pr$x[k], eigenvector = ev$x[k], clustering = cl$local[k])
  if (!is.null(label)) r$label <- if (is.na(label[k])) NULL else as.character(label[k])
  if (!is.null(pa)) {
    r$betweenness <- pa$betweenness[k]
    r$closeness <- pa$closeness[k]
  }
  r
})
checks <- list(
  list("Edge rows", as.integer(meta$input_rows)),
  list("Edge rows left out (missing source, target or weight)", as.integer(meta$dropped_rows)),
  list("Self-loops", as.integer(meta$self_loops)),
  list("Repeated edges merged", as.integer(meta$duplicate_edges)),
  list("Isolated nodes", as.integer(meta$isolates)),
  list("Separate parts", as.integer(meta$components))
)
nt <- meta$node_table
if (!is.null(nt)) {
  checks <- c(checks, list(
    list("Node table rows", as.integer(nt$rows)), list("Node table rows left out", as.integer(nt$dropped_rows)),
    list("Nodes not in the node table", as.integer(nt$missing_ids)), list("Node table nodes with no edges", as.integer(nt$extra_ids))
  ))
}
tables <- list(
  list(key = "top_nodes", title = "Most central nodes (by PageRank)", columns = node_cols, rows = rows),
  list(key = "checks", title = "Network checks", columns = list(list(key = "check", label = "Check"), list(key = "count", label = "Count", type = "integer")),
       rows = lapply(checks, function(x) list(check = x[[1]], count = x[[2]])))
)

# %% Charts
# Node and edge columns share one chart table: shorter columns end in empty cells.
padded <- function(v, rows) c(v, rep(NA, rows - length(v)))
group <- if (!is.null(label)) ifelse(is.na(label), "(missing)", as.character(label)) else paste("part", comp + 1L)
group_title <- if (!is.null(label)) g$label else "Part"
charts <- list()
if (!is.null(xy)) {
  show <- min(m, 20000L)
  keep <- seq_len(show)
  rows_map <- max(n, show)
  charts[[length(charts) + 1L]] <- cs_chart("map", "network-graph", "Network map", list(
    x = cs_col("x", padded(xy$x, rows_map), "numeric"),
    y = cs_col("y", padded(xy$y, rows_map), "numeric"),
    node = cs_col("Node", padded(g$node_id, rows_map), "categorical"),
    size = cs_col("Degree", padded(degree, rows_map), "numeric"),
    group = cs_col(group_title, padded(group, rows_map), "categorical"),
    from = cs_col("From", padded(g$si[keep], rows_map), "numeric"),
    to = cs_col("To", padded(g$sj[keep], rows_map), "numeric"),
    weight = if (isTRUE(g$weighted)) cs_col("Weight", padded(g$sw[keep], rows_map), "numeric") else NULL
  ), controls = list(directed = isTRUE(g$directed)), note = if (show == m) NULL else sprintf("%d of %d edges drawn.", show, m))
} else {
  charts[[length(charts) + 1L]] <- cs_chart("map", "network-graph", "Network map", list(), note = sprintf("The map is drawn for networks up to %d nodes; this one has %d.", MAP_NODES, n))
}
if (isTRUE(g$directed)) {
  ci <- cs_graph_degree_ccdf(deg$in_degree)
  co <- cs_graph_degree_ccdf(deg$out_degree)
  ks <- c(ci$k, co$k)
  ps <- c(ci$p, co$p)
  series <- c(rep("In-degree", length(ci$k)), rep("Out-degree", length(co$k)))
  series_levels <- c("In-degree", "Out-degree")
} else {
  ca <- cs_graph_degree_ccdf(degree)
  ks <- ca$k
  ps <- ca$p
  series <- rep("Degree", length(ca$k))
  series_levels <- "Degree"
}
charts[[length(charts) + 1L]] <- cs_chart("degrees", "degree-ccdf", "Degree distribution", list(
  degree = cs_col("Degree k", ks, "numeric"),
  share = cs_col("Share of nodes with degree ≥ k", ps, "numeric"),
  series = cs_col("Degree", series, "categorical", levels = series_levels)
))
if (n <= MATRIX_NODES) {
  morder <- order(group == "(missing)", group, -degree, seq_len(n), method = "radix") - 1L
  rows_mx <- max(n, m)
  charts[[length(charts) + 1L]] <- cs_chart("matrix", "adjacency-matrix", "Adjacency matrix", list(
    row = cs_col("Row", padded(g$si, rows_mx), "numeric"),
    col = cs_col("Column", padded(g$sj, rows_mx), "numeric"),
    value = cs_col(if (isTRUE(g$weighted)) "Weight" else "Edge", padded(g$sw, rows_mx), "numeric"),
    node = cs_col("Node", padded(g$node_id, rows_mx), "categorical"),
    group = cs_col(group_title, padded(group, rows_mx), "categorical"),
    order = cs_col("Order", padded(morder, rows_mx), "numeric")
  ), controls = list(directed = isTRUE(g$directed)))
}

# %% Result
kind <- if (isTRUE(g$directed)) "directed" else "undirected"
dens <- if (is.null(values$density)) "undefined" else sprintf("%.3f", values$density)
summary <- sprintf("A %s network of %d nodes and %d edges (density %s); %d part(s), the largest with %d nodes.",
                   kind, n, m, dens, values$components, values$largest_component)
cs_publish(list(
  title = "Network description (size, degrees, clustering, centrality)",
  engine = cs_engine_info("jsonlite", "nanoparquet"),
  n = n,
  summary = summary,
  statistics = list(
    list(key = "n_nodes", label = "Nodes", value = n, format = "integer"),
    list(key = "n_edges", label = "Edges", value = m, format = "integer"),
    list(key = "density", label = "Density", value = values$density),
    list(key = "components", label = "Separate parts", value = values$components, format = "integer"),
    list(key = "transitivity", label = "Transitivity", value = values$transitivity),
    list(key = "assortativity", label = "Degree assortativity", value = values$assortativity)
  ),
  tables = tables,
  values = values,
  charts = charts,
  warnings = warnings,
  artifacts = list(artifact)
))

Sources

  • Wasserman S, Faust K (1994). Social Network Analysis: Methods and Applications. Cambridge University Press.
  • Newman MEJ (2010). Networks: An Introduction. Oxford University Press.
  • Brandes U (2001). A faster algorithm for betweenness centrality. Journal of Mathematical Sociology 25(2):163–177.
  • Newman MEJ (2002). Assortative mixing in networks. Physical Review Letters 89(20):208701.
  • Watts DJ, Strogatz SH (1998). Collective dynamics of 'small-world' networks. Nature 393:440–442.
  • Page L, Brin S, Motwani R, Winograd T (1999). The PageRank citation ranking: bringing order to the web. Stanford InfoLab technical report 1999-66.
  • Bonacich P (1987). Power and centrality: a family of measures. American Journal of Sociology 92(5):1170–1182.
  • Fruchterman TMJ, Reingold EM (1991). Graph drawing by force-directed placement. Software: Practice and Experience 21(11):1129–1164.
  • Zachary WW (1977). An information flow model for conflict and fission in small groups. Journal of Anthropological Research 33(4):452–473.

From the CodeSplash method registry · describe.network v1.0.0.