@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
36 lines • 1.42 kB
TypeScript
import type { Graph } from "../core/graph.js";
import type { NodeId } from "../types/index.js";
/**
* Spectral Clustering implementation
*
* Uses eigenvalues and eigenvectors of the graph Laplacian matrix to perform clustering.
* Particularly effective for finding non-convex clusters and communities in graphs.
*
* Time complexity: O(V³) for eigendecomposition
* Space complexity: O(V²)
*/
export interface SpectralClusteringOptions {
k: number;
laplacianType?: "unnormalized" | "normalized" | "randomWalk";
maxIterations?: number;
tolerance?: number;
}
export interface SpectralClusteringResult {
communities: NodeId[][];
clusterAssignments: Map<NodeId, number>;
eigenvalues?: number[];
eigenvectors?: number[][];
}
/**
* Perform spectral clustering on a graph
*
* @warning This implementation uses simplified power iteration for eigenvector
* computation with approximate eigenvalues. For production use cases requiring
* precise clustering, consider using a proper linear algebra library like ml-matrix.
*
* The approximate eigenvalues (0.1, 0.2 for second and third eigenvectors) work
* well for most graph structures but may produce suboptimal results for graphs
* with unusual spectral properties.
*/
export declare function spectralClustering(graph: Graph, options: SpectralClusteringOptions): SpectralClusteringResult;
//# sourceMappingURL=spectral.d.ts.map