UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

83 lines 2.79 kB
import type { Graph } from "../core/graph.js"; import type { NodeId } from "../types/index.js"; /** * Configuration options for the GRSBM (Greedy Recursive Spectral Bisection) algorithm */ export interface GRSBMConfig { /** Maximum depth of recursive bisection */ maxDepth?: number; /** Minimum cluster size to continue splitting */ minClusterSize?: number; /** Number of eigenvectors to use for spectral embedding */ numEigenvectors?: number; /** Convergence tolerance for eigenvalue computation */ tolerance?: number; /** Maximum number of power iterations for eigenvalue computation */ maxIterations?: number; /** Random seed for reproducibility */ seed?: number; } /** * Represents a cluster in the hierarchical structure */ export interface GRSBMCluster { /** Unique identifier for this cluster */ id: string; /** Node IDs in this cluster */ members: Set<NodeId>; /** Left child cluster (if split) */ left?: GRSBMCluster; /** Right child cluster (if split) */ right?: GRSBMCluster; /** Modularity score of this cluster */ modularity: number; /** Depth in the hierarchy */ depth: number; /** Spectral embedding quality score */ spectralScore: number; } /** * Result of the GRSBM clustering algorithm */ export interface GRSBMResult { /** Root of the cluster hierarchy */ root: GRSBMCluster; /** Flat clustering at leaf level */ clusters: Map<NodeId, number>; /** Number of final clusters */ numClusters: number; /** Modularity scores for each level */ modularityScores: number[]; /** Explanation of the clustering structure */ explanation: ClusterExplanation[]; } /** * Explanation for a cluster split decision */ export interface ClusterExplanation { /** Cluster that was split */ clusterId: string; /** Reason for the split */ reason: string; /** Modularity improvement from the split */ modularityImprovement: number; /** Key nodes that influenced the split */ keyNodes: NodeId[]; /** Spectral embedding values */ spectralValues: number[]; } /** * GRSBM - Greedy Recursive Spectral Bisection with Modularity * * This algorithm performs hierarchical community detection using spectral * bisection guided by modularity optimization. It provides explainable * community structure by tracking the reasoning behind each split. * * Based on: "Explainable Community Detection via Hierarchical Spectral Clustering" (2024) * * @param graph - Input graph to cluster * @param config - Configuration options * @returns Hierarchical clustering result with explanations */ export declare function grsbm(graph: Graph, config?: GRSBMConfig): GRSBMResult; //# sourceMappingURL=grsbm.d.ts.map