Louvain method 2026-10-20
The Louvain method is a greedy multilevel community detection algorithm maximizing network modularity. It alternates positive-gain single-vertex moves with contraction of communities into weighted vertices. Different vertex orders can produce different local optima; a result is not a certificate of globally maximum modularity.[ref]
Network modularity 2026-10-20
Network modularity measures excess within-community edge weight relative to a network null model based on degrees of vertices. For an undirected unweighted graph, its standard form is . A single community containing every vertex has ; a partition with more internal connectivity than expected can have positive .
Network null model 2026-10-20
A network null model specifies the reference network ensemble or expected connectivity against which a pattern is measured. For standard network modularity, expected edge weight is . The reference is part of the scientific model: choosing a different reference can change what counts as excess structure.
For an undirected graph with adjacency matrix , degrees of vertices and edges, network modularity is
Each undirected edge contributes twice to the double sum, explaining the denominator . Include the terms with : even though the observed graph has no self-loops, the null-model contribution on the diagonal is part of this definition.
An independent implementation forms the modularity matrix and sums its within-community blocks. Initializing the best value to negative infinity also handles a candidate collection whose scores are all negative:
def modularity(adjacency,communities):
    a=np.asarray(adjacency);degrees=a.sum(axis=1);twom=degrees.sum()
    if twom==0:raise ValueError('positive edge count required')
    B=a-np.outer(degrees,degrees)/twom
    return sum(B[np.ix_(group,group)].sum() for group in communities)/twom

best_score = -np.inf
best_partition = None
for candidate in community_partitions:
    value = modularity(adjacency_matrix, candidate)
    if value > best_score:
        best_score, best_partition = value, candidate
print(best_partition, best_score)
The best partition is , with . There are seven edges, and each selected community has three internal edges and total degree seven, so independently
The supplied candidates include the optimum, but do not exhaust even the balanced two-community set partitions: there are of those, rather than six. To substantiate a best partition among all community counts, the following short recursion enumerates all 203 unlabeled set partitions of the six vertices:
def partitions(items):
    if not items:
        yield [];return
    first,*rest=items
    for part in partitions(rest):
        yield [[first]]+[g.copy() for g in part]
        for j in range(len(part)):
            new=[g.copy() for g in part];new[j]=[first]+new[j];yield new

candidates = list(partitions(list(range(len(adjacency_matrix)))))
best_partition = max(candidates, key=lambda p: modularity(adjacency_matrix, p))
print(len(candidates), best_partition, modularity(adjacency_matrix, best_partition))
This exhaustive calculation returns the same two triangles and the same network modularity. Enumerating every set partition becomes impractical rapidly as the number of vertices increases, but is small enough here to verify the global optimum.
The Louvain method approximately maximizes network modularity. Start with each vertex in its own community. Repeatedly visit each vertex, evaluate moving it into each neighbouring community, and accept the move with the greatest positive modularity gain. When no such local move improves the score, contract each community into a new weighted vertex, summing inter-community edge weights and retaining internal edges as self-loops. Repeat local optimization and contraction until no further gain is obtained, then map the communities back to the original vertices.[ref]
For an undirected unweighted graph with edges, degrees of vertices and community labels , the objective is
The term subtracts the expected connectivity in a degree-based network null model. If all vertices are put in one community, the observed and expected total weights cancel, so . A partition with excess internal connectivity can have , and merging away that structure reduces the score. The modularity objective and positive-gain rule prevent arbitrary merging merely to increase cluster size. They do not forbid a single community in every possible network: if there is no better modular partition, one community may be an appropriate result. The method is a greedy heuristic, so it does not guarantee the global maximum of .
network resilience depends on which function must persist, which disturbances are applied and how the network responds over time. Local interaction motifs, global architecture and physical operating constraints can protect different properties, often with tradeoffs. A graph that remains connected is not necessarily a functioning regulatory system, and a system that changes its output during a stimulus has not necessarily failed.
It helps to distinguish network robustness, meaning persistence of a specified property under perturbation, from network resilience, which also considers recovery after a disturbance. Relevant performance measures include the maintained output, transient deviation, recovery time, surviving connected component, transport capacity and cost. Disturbances can be brief or persistent, small or destructive, random or targeted, independent or correlated. Consequently, resilience is not one scalar attribute that can be read off a degree distribution.
At the local scale, negative feedback can oppose fluctuations, while network redundancy can provide an alternative route when one component fails. A feed-forward loop can filter stimuli by duration, and positive feedback can stabilize a switched state through bistability. These roles are conditional: a switch that remembers a transient signal can be useful in a developmental decision but undesirable in a homeostatic controller. feedback delay or excessive gain can destabilize a corrective loop; redundancy does little against a disturbance shared by every supposedly independent backup. One must analyze the signs, strengths, kinetics and operating ranges of the interactions, not just count motifs.
Bacterial chemotaxis supplies a concrete cellular example. In Escherichia coli, an attractant change affects receptor-associated kinase activity and hence downstream phosphorylation controlling swimming behavior. Slower receptor methylation and demethylation provide a feedback memory of the stimulus. In an appropriate operating range, the output responds transiently but approximately returns to its earlier level even while the new stimulus persists: robust perfect adaptation. This preserves sensitivity to subsequent changes rather than holding the entire molecular state fixed. The control interpretation identifies conditions under which adaptation does not require precise tuning of every reaction constant.[ref]
The essential logic can be isolated without pretending to reproduce every reaction. If is the output and an internal controller state, suppose
Whenever the closed system reaches a stable steady state with an unsaturated integrator, forces . The controller accumulates the error, so a constant disturbance need not leave a persistent output offset. This is integral action. The equation demonstrates the mechanism, not an unconditional guarantee: the surrounding feedback must be stable, the required control action must be attainable, and the effective set point must remain meaningful under the parameter changes considered.
The example also clarifies what is and is not robust. Returning kinase activity to a set point does not imply an unchanged response time, noise level or swimming trajectory. Strong or sustained stimuli can exhaust the receptor's modification range; deleting an essential feedback component can remove adaptation; correlated changes in controller parameters can shift its set point. Cellular resilience therefore combines biochemical organization with finite resource and timescale constraints. A useful experiment measures the response and recovery after stimuli of different amplitudes, while independently perturbing feedback components, rather than inferring perfect adaptation from one endpoint measurement.
At the global scale, several architectural features matter. Alternative paths and disjoint routes reduce dependence on one component. network modularity can confine damage, although inter-module bridges may then become critical bottlenecks. Short paths improve communication but may also permit rapid spread of a disturbance. Highly connected hubs can support efficient coordination while concentrating vulnerability. Directed links, edge weights and capacities change which routes are usable; a path in an unweighted undirected projection need not carry a signal or the required load in the real system.
The Internet illustrates these distinctions for a real-world network. Nodes can represent routers or autonomous systems, with edges representing different kinds of connectivity; conclusions should state the chosen resolution. In a heterogeneous network, random deletion is likely to hit one of many low-degree nodes, whereas targeted deletion of high-degree nodes can disrupt a large fraction of the remaining paths. The classic attack-tolerance study demonstrated this contrast in model networks and mapped communication networks.[ref] Its lesson is a vulnerability conditional on the topology and attack rule, not that every network with an apparent power-law tail is invulnerable to arbitrary failures.
Actual Internet resilience also uses routing protocols, spare capacity, replicated services and operational recovery. Those are dynamical and engineering mechanisms additional to the static graph. Removing a node may reroute traffic through surviving links and overload them; failures can then cascade even while many topological paths remain. Conversely, route recomputation may restore service after an initially severe disruption. cascading failure therefore requires a load and dependency model, while geographically correlated failures require an account of shared physical infrastructure. Maintaining connectivity, throughput and low latency are different objectives.
The cellular and communication examples share a design principle but not a single universal architecture. A local controller can reject a persistent input error; a global alternative route can bypass a failed connection. Neither guarantees protection against every perturbation, and both incur costs in energy, components or spare capacity. A sound comparison specifies the disturbance ensemble, the measured function, the recovery interval and the intervention used to test the mechanism. Resilience is produced by matched topology and dynamics, and protection against one class of stimulus can create vulnerability to another.