# Function modularity

- modularity(
  nodeIds: readonly string[],
  edges: readonly WeightedEdge[],
  labels: Map<string, string>,
  ): number

  Newman's modularity Q for a weighted partition.

  `Q = (1 / 2m) Σ_{ij} [A_ij - k_i k_j / 2m] δ(c_i, c_j)`

  where `A_ij` is edge weight, `k_i` weighted degree, and `δ` the Kronecker indicator for same-community. Q ∈ `[-0.5, 1]`; values >0.3 indicate meaningful community structure.

  #### Parameters

  - nodeIds: readonly string[]

    Node universe.

  - edges: readonly WeightedEdge[]

    Weighted edges.

  - labels: Map<string, string>

    Community label per node (from labelPropagation).

  #### Returns number

  Modularity Q rounded to 4 decimal places (`0` when the graph is empty).

  - Defined in utils/graphAlgorithms.ts:411