Advanced maths

Maximum modularity community partition calculator

Find a vertex partition maximizing weighted Newman–Girvan modularity at a declared resolution.

Your numbers

Zero-based labels 0 through n−1; all declared vertices remain included.
One row: u v positive-weight.
Finite nonnegative value from 0 through 100.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Find a vertex partition maximizing weighted Newman–Girvan modularity at a declared resolution.

THE FORMULAQ=Σ_C [L_C/m − γ(k_C/(2m))²], with m=sum of undirected edge weights.

A worked example

The default two triangles joined by one bridge have total edge weight seven. Splitting into the two triangles gives Q=6/7−1/2=5/14 at resolution one.

Good to know

Undirected simple graph on 1–10 vertices with at least one edge; all weights strictly positive and at most 10^6. Resolution 0–100. Exact set-partition enumeration with floating-point scores; one maximizing partition, no unique-community or statistical-significance claim.

Optimize a community partition score

Modularity compares the edge weight inside communities with a degree-based baseline. A partition scores well when it places more weight within groups than that baseline predicts. The calculator examines every vertex partition of the bounded graph and returns one whose weighted Newman–Girvan score is largest at the chosen resolution.

Every vertex belongs to exactly one community, including isolated vertices. Communities need not be cliques and need not correspond to graph-theoretic modules with identical outside neighborhoods. The objective is a numerical comparison of internal weight against expected weight, not a test that every pair within a community is connected.

Two triangles beat the single community012345Internal weight 6 of 7; degree fractions ½ and ½Q = 6/7 − 1/4 − 1/4 = 5/14
Scroll across to see the full diagram.
The bridge is external to the two communities, while each triangle contributes its internal weight.

Compare this with the Graph modular decomposition calculator with strong modules. Find communities maximizing Newman–Girvan modularity;graph modules require identical external neighborhoods and are not modularity communities.

Set positive weights and resolution

Each edge row contains two zero-based endpoints and a positive weight. The graph may be disconnected but must contain at least one edge, because modularity divides by total edge weight. Loops, duplicate unordered pairs, zero or negative edge weights and nonfinite values are rejected by this model.

The resolution parameter gamma ranges from zero to one hundred. Increasing it increases the penalty for large community degree totals and can favor smaller groups. Keep gamma fixed when comparing partitions of the same graph; a numerical score at a different resolution represents a different objective and is not directly the same benchmark.

Compute the two triangle example

The default graph has two triangles and one bridge joining them. Every edge has weight one, so total edge weight is seven. If each triangle is its own community, six of the seven edges are internal. Each triangle’s sum of weighted degrees is seven because its bridge endpoint contributes the cross-community connection.

At resolution one, each degree fraction is seven divided by fourteen, or one half. The score is therefore six sevenths minus two times one quarter, giving five fourteenths. This transparent calculation verifies the displayed partition score independently of the exhaustive search that establishes its optimality among all partitions.

Enumerate unlabeled partitions once

A community assignment is encoded by a restricted-growth label sequence. The first vertex starts in community zero. Each later vertex may join an existing community or start the next unused label, so permutations of community names are not counted as different partitions of the same vertex set.

At a completed assignment, the program calculates each community’s internal weight and total weighted degree, then evaluates the modularity formula. The ten-vertex limit keeps the number of set partitions finite and manageable. This is direct exhaustive optimization, unlike a greedy merging method that may stop at a locally favorable partition.

Read the weight normalization correctly

Total edge weight m counts each undirected input edge once. Weighted degrees count each incident edge at each endpoint, so the degree sum across the graph is two m. Within a community, L counts internal edge weight once, while its degree total also includes edges leaving the community.

Those conventions explain the two different denominators in the score. Dividing internal weight by two m would halve its contribution incorrectly. A useful check is that placing every vertex in one community gives score one minus gamma; at gamma one the single-community partition therefore has score zero.

Avoid overinterpreting community labels

The returned groups maximize this objective for the exact entered graph, but they do not establish real-world categories or statistically significant communities. Modularity can have several tied or nearly tied partitions. The order and numerical names of communities carry no meaning, and vertex relabeling can choose a different representative optimum.

A graph module is defined by identical adjacency toward outside vertices, which is unrelated to the modularity baseline. Similarly, a clique partition requires complete within-group adjacency. A modularity community can contain missing edges and unequal outside neighborhoods. Use those different calculators only when their structural definition matches the question you intend to ask.

Explore resolution and numerical sensitivity

At gamma zero the penalty disappears and putting every edge inside one community reaches score one. At larger resolution, splitting may become worthwhile because it reduces squared community degree fractions. Comparing a few explicit gamma values can show which parts of the partition are stable and which depend on that modeling choice.

Scores use floating-point arithmetic, so very close candidate totals should be interpreted with the precision of their input weights. Uniformly scaling all edge weights leaves the normalized score unchanged. This invariance provides another useful audit check, while changing only selected weights can alter both the maximizing partition and the modularity value.

A few questions, answered

Is a modularity community necessarily a clique?

No. Missing within-community edges are allowed.

Can the graph have no edges?

No. The score divides by total edge weight, so at least one positive-weight edge is required.

What does resolution control?

It scales the squared community-degree penalty and changes the objective.

Are community labels unique?

No. Community names are arbitrary, and several maximizing partitions can tie.

Find your calculator

Start typing to explore the library.