@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
112 lines • 3.03 kB
TypeScript
import type { Graph } from "../../core/graph.js";
import type { CommunityResult } from "../../types/index.js";
/**
* Optimized Louvain community detection algorithm with early pruning and threshold cycling
*
* Key optimizations:
* - Leaf node pruning: Skip nodes with degree 1
* - Importance ordering: Process high-impact nodes first
* - Threshold cycling: Adaptive convergence thresholds
* - Early termination: Stop when changes become insignificant
*
* Expected speedup: 2-5x on large graphs with many leaf nodes
*/
export interface OptimizedLouvainOptions {
/**
* Resolution parameter (default: 1.0)
*/
resolution?: number;
/**
* Maximum iterations per level (default: 100)
*/
maxIterations?: number;
/**
* Convergence tolerance (default: 1e-6)
*/
tolerance?: number;
/**
* Enable leaf node pruning (default: true)
*/
pruneLeaves?: boolean;
/**
* Enable importance-based node ordering (default: true)
*/
importanceOrdering?: boolean;
/**
* Base pruning threshold (default: 0.01)
*/
pruningThreshold?: number;
/**
* Enable adaptive threshold cycling (default: true)
*/
thresholdCycling?: boolean;
}
interface PruningStats {
leafNodesPruned: number;
lowDegreeNodesPruned: number;
stableNodesPruned: number;
}
export declare class OptimizedLouvain {
private graph;
private communities;
private communityWeights;
private nodeWeights;
private nodeDegrees;
private totalWeight;
private pruningStats;
constructor(graph: Graph);
/**
* Run optimized Louvain algorithm
*/
detectCommunities(options?: OptimizedLouvainOptions): CommunityResult;
/**
* Initialize data structures
*/
private initialize;
/**
* Get nodes ordered by importance (degree * log(weight))
*/
private getNodesInImportanceOrder;
/**
* Perform local moving phase with optimizations
*/
private performLocalMoving;
/**
* Check if node is a leaf (degree 1)
*/
private isLeafNode;
/**
* Get adaptive threshold that decreases with iterations
*/
private getAdaptiveThreshold;
/**
* Calculate modularity gain from moving a node to a community
*/
private calculateModularityGain;
/**
* Remove node from community (for gain calculation)
*/
private removeNodeFromCommunity;
/**
* Add node to community
*/
private addNodeToCommunity;
/**
* Get neighboring communities of a node
*/
private getNeighborCommunities;
/**
* Calculate total modularity
*/
private calculateModularity;
/**
* Get pruning statistics
*/
getPruningStats(): PruningStats;
}
/**
* Optimized Louvain algorithm with automatic optimization selection
*/
export declare function louvainOptimized(graph: Graph, options?: OptimizedLouvainOptions): CommunityResult;
export {};
//# sourceMappingURL=louvain-optimized.d.ts.map