Skip to main content

Motifs, Triads, and Local Structure

A triad is an induced subgraph on three nodes. A directed triadic census assigns every three-node set to one of 16 isomorphism classes. A motif claim goes further: a pattern must be unusually frequent relative to an explicit null ensemble, so raw census counts alone are not motif evidence.

Prerequisites​

Complete assortativity and mixing patterns. Recall that direction and the null model are part of the statistic, not presentation details.

Learning goals​

  • Compute a directed triadic census after declared simplification.
  • Distinguish a directed cycle triad from an undirected triangle.
  • Relate node triangle counts to global transitivity without equating them.
  • Require a null model and observation sensitivity before using the word motif.

Analysis contract​

  • Graph type: a directed unweighted simple graph; parallel events are collapsed and the self-loop is removed because the 16 triad classes concern edges among distinct nodes.
  • Normalization: the census reports raw counts over all (73)=35\binom{7}{3}=35 node triples; undirected transitivity is closed triplets divided by all connected triplets.
  • Disconnected case: triples containing isolates remain in the census, often as 003 or one-edge types; nodes with fewer than two neighbors have zero triangles under NetworkX's convention.
  • Interpretation limit: a frequent triad is local structural evidence, not a statistically enriched motif, functional mechanism, social process, or causality.

Directed and undirected questions​

The 030C class is a three-edge directed cycle. Converting the graph to undirected form discards direction and answers a different closure question. Node triangle counts count each undirected triangle at each of its three nodes, while transitivity weights nodes with many connected neighbor pairs more heavily than the average local clustering coefficient would.

A motif analysis must compare observed counts with graphs drawn from a justified null model and report variation across draws. Preserving only node count and edge count differs from preserving in- and out-degree sequences, timestamps, or group mixing. No null ensemble is generated here, so the result is correctly called a census.

Worked example​

import csv
from pathlib import Path

import networkx as nx

fixture = Path("tests/fixtures/graph-data-science")
with (fixture / "interaction-nodes.csv").open(encoding="utf-8") as handle:
node_ids = [row["node_id"] for row in csv.DictReader(handle)]
with (fixture / "interaction-relationships.csv").open(encoding="utf-8") as handle:
rows = [row for row in csv.DictReader(handle) if row["record_status"] == "valid"]

directed = nx.DiGraph()
directed.add_nodes_from(node_ids)
directed.add_edges_from(
(row["source"], row["target"])
for row in rows
if row["source"] != row["target"]
)
census = {kind: count for kind, count in nx.triadic_census(directed).items() if count}
undirected = directed.to_undirected()
triangles = nx.triangles(undirected)
ordered_triangles = {node: triangles[node] for node in node_ids}
print(f"nonzero_triads={census}")
print(f"directed_cycles_030C={census['030C']} undirected_transitivity={nx.transitivity(undirected):.3f}")
print(f"triangles={ordered_triangles}")

Expected output:

nonzero_triads={'003': 9, '012': 15, '102': 4, '021D': 2, '021U': 1, '021C': 1, '111D': 1, '030C': 2}
directed_cycles_030C=2 undirected_transitivity=0.545
triangles={'ada': 2, 'ben': 2, 'cy': 1, 'dia': 0, 'eli': 0, 'fox': 1, 'gia': 0}

The two directed cycles and the undirected triangle counts describe different projections of the same valid events.

Limitations​

  • Collapsing event multiplicity and removing the self-loop changes local structure by design.
  • Census counts depend strongly on graph size and density; compare like with like.
  • Motif significance depends on a justified null model, enough draws, and multiple-comparison discipline.
  • One missing relationship can change many triads simultaneously, so observation-process sensitivity is essential.

Practice​

Classify the Ada–Ben–Cy triple by hand, then reverse only Cy-to-Ada and recompute its triad type. Explain why the undirected triangle survives while the directed class changes.

Next steps​

Continue to link prediction, where local-neighborhood patterns become candidate scores under a strict temporal cutoff.

Primary sources​

Checked 2026-10-18: NetworkX, triadic_census; NetworkX, clustering reference; R. Milo et al., Network motifs: simple building blocks of complex networks; V. Batagelj and A. Mrvar, A subquadratic triad census algorithm.