import { Graph } from '../graph/graph'; import { Community } from '../types/clustering-types'; import { Edge, Node } from '../types/graph'; /** * Calculate modularity (Q) for a graph partitioned into communities. * * Newman-Girvan formula: * Q = 1/(2m) * Σ[A_ij - (k_i * k_j)/(2m)] * δ(c_i, c_j) * * Where: * - m = total number of edges * - A_ij = 1 if edge exists between i and j, 0 otherwise * - k_i = degree of node i * - k_j = degree of node j * - δ(c_i, c_j) = 1 if nodes i and j are in the same community, 0 otherwise * * Range: [-0.5, 1.0] * - Higher values indicate stronger community structure * - Q > 0.3 typically indicates significant community structure * - Q < 0 indicates worse than random partitioning * @template N - Node type * @template E - Edge type * @param graph - Input graph * @param communities - Community assignments * @returns Modularity score in range [-0.5, 1.0] * @example * ```typescript * const graph = new Graph(false); * // ... build graph ... * const communities: Community[] = [...]; * const Q = calculateModularity(graph, communities); * console.log(`Modularity: ${Q.toFixed(3)}`); // e.g., "Modularity: 0.427" * ``` */ export declare const calculateModularity: (graph: Graph, communities: Community[]) => number; /** * Calculate modularity contribution for a single community. * * Used for incremental modularity updates during optimization. * @template N - Node type * @template E - Edge type * @param graph - Input graph * @param community - Community to evaluate * @param totalEdges - Total number of edges in graph * @returns Modularity contribution of this community * @example * ```typescript * const m = graph.getEdgeCount(); * const contribution = calculateCommunityModularity(graph, community, m); * ``` */ export declare const calculateCommunityModularity: (graph: Graph, community: Community, totalEdges: number) => number; /** * Calculate modularity delta for moving a node between communities. * * Used by Louvain and Leiden algorithms for greedy optimization. * * ΔQ = [Σin + k_i_in] / (2m) - [(Σtot + k_i)² / (2m)²] - [Σin / (2m) - (Σtot / (2m))² - (k_i / (2m))²] * @param k_i - Degree of node being moved * @param k_index * @param k_i_in - Sum of edge weights from node to nodes in target community * @param k_index_in * @param sigma_tot - Sum of degrees of nodes in target community * @param sigma_in - Sum of edge weights between nodes in target community * @param m - Total number of edges in graph * @returns Change in modularity (positive means improvement) * @example * ```typescript * const deltaQ = calculateModularityDelta(5, 3, 20, 15, 100); * if (deltaQ > 0) { * // Moving node improves modularity * } * ``` */ export declare const calculateModularityDelta: (k_index: number, k_index_in: number, sigma_tot: number, sigma_in: number, m: number) => number; //# sourceMappingURL=modularity.d.ts.map