Bipartite and Multipartite Networks
A bipartite graph has two node sets and allows edges only across sets. Many datasets are naturally two-mode—people and events, users and items, authors and papers. A multipartite graph extends the idea to more sets, but NetworkX uses ordinary graph classes and relies on the analyst to preserve and validate the mode attribute.
Prerequisites
Complete community detection. This lesson returns to event identity instead of accepting a one-mode projection as raw data.
Learning goals
- Build and validate a person–event incidence graph from the ticket-52 fixture.
- Explain weighted one-mode projection as shared-event counting.
- Preserve event roles, direction, time, and repeated-event identity until a question justifies projection.
- Recognize when hypergraph or multipartite semantics are a better fit.
Analysis contract
- Graph type: an undirected bipartite incidence graph with seven person nodes and ten valid event nodes; a source or target is incident to its event, and Eli's self-event creates one simple incidence edge.
- Normalization: the weighted person projection reports the count of shared event neighbors; no division by person or event degree is applied.
- Disconnected case: Gia is an isolated person and projects to an isolate; components stay separate unless an observed event connects their modes.
- Interpretation limit: projected weight is co-incidence evidence, not directed interaction strength, similarity, affiliation, or causality.
Preserve modes before projecting
The incidence graph makes event identity explicit. Two Ada-to-Ben events become two event nodes rather than one aggregated edge. Each non-self event has two incidence edges; Eli's self-event has one because a simple graph cannot store duplicate person–event incidence.
Projection connects two people when they share an event neighbor. It necessarily loses whether each person was source or target, the event timestamp, and the interaction type unless those are carried into a richer downstream representation. Project only when the loss matches the question. For three or more node types, record a controlled mode label and validate allowed cross-mode relations rather than assuming a built-in multipartite class will enforce them.
Worked example
import csv
from pathlib import Path
import networkx as nx
from networkx.algorithms import bipartite
fixture = Path("tests/fixtures/graph-data-science")
with (fixture / "interaction-nodes.csv").open(encoding="utf-8") as handle:
people = [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"]
incidence = nx.Graph()
incidence.add_nodes_from(people, bipartite=0)
events = []
for row in rows:
event = f"event:{row['relationship_id']}"
events.append(event)
incidence.add_node(event, bipartite=1)
source, target = row["source"], row["target"]
source_roles = ["source", "target"] if source == target else ["source"]
incidence.add_edge(source, event, roles=source_roles)
if target != source:
incidence.add_edge(target, event, roles=["target"])
projection = bipartite.weighted_projected_graph(incidence, people)
print(
f"bipartite={bipartite.is_bipartite(incidence)} people={len(people)} "
f"events={len(events)} incidence_edges={incidence.number_of_edges()}"
)
print(
f"ada_ben_shared_events={projection['ada']['ben']['weight']} "
f"dia_eli_shared_events={projection['dia']['eli']['weight']}"
)
print("projection_loses=direction,roles,time")
Expected output:
bipartite=True people=7 events=10 incidence_edges=19
ada_ben_shared_events=2 dia_eli_shared_events=2
projection_loses=direction,roles,time
The projection's value 2 has a precise meaning: two shared event nodes. It is not the sum of the original relationship weights.
Limitations
- NetworkX's
bipartitenode convention is not automatically enforced; validation is required. - High-degree event nodes can create dense projection cliques and dominate shared-neighbor counts.
- A one-mode projection can erase roles, direction, time, edge attributes, and uncertainty.
- A missing event or endpoint changes both incidence degree and every projection derived from it.
Practice
Produce a source-role-only projection and compare it with the incidence projection. State which relationships disappear and why the new graph answers a narrower question.
Next steps
Continue to assortativity and mixing patterns to summarize who connects to whom without mistaking composition for preference.
Primary sources
Checked 2026-10-18: NetworkX, bipartite algorithms; NetworkX, weighted_projected_graph; S. P. Borgatti and M. G. Everett, Network analysis of 2-mode data.