@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
63 lines • 2.17 kB
TypeScript
import type { Graph } from "../core/graph.js";
import type { NodeId } from "../types/index.js";
/**
* Configuration options for the TeraHAC (Hierarchical Agglomerative Clustering) algorithm
*/
export interface TeraHACConfig {
/** Linkage criterion: 'single', 'complete', 'average', 'ward' */
linkage?: "single" | "complete" | "average" | "ward";
/** Number of clusters to stop at (optional) */
numClusters?: number;
/** Distance threshold to stop clustering */
distanceThreshold?: number;
/** Maximum number of nodes to process efficiently */
maxNodes?: number;
/** Use graph structure for distance calculation */
useGraphDistance?: boolean;
}
/**
* Represents a node in the dendrogram/cluster hierarchy
*/
export interface ClusterNode {
/** Unique identifier for this cluster */
id: string;
/** Node IDs in this cluster */
members: Set<NodeId>;
/** Left child cluster (if internal node) */
left?: ClusterNode;
/** Right child cluster (if internal node) */
right?: ClusterNode;
/** Distance at which this cluster was formed */
distance: number;
/** Size of the cluster */
size: number;
}
/**
* Result of the TeraHAC clustering algorithm
*/
export interface TeraHACResult {
/** Root of the dendrogram */
dendrogram: ClusterNode;
/** Flat clustering at specified level */
clusters: Map<NodeId, number>;
/** All merge distances in order */
distances: number[];
/** Number of clusters in final result */
numClusters: number;
}
/**
* TeraHAC - Hierarchical Agglomerative Clustering for Large Graphs
*
* This algorithm performs hierarchical clustering on graphs by iteratively
* merging the closest clusters. Optimized for scalability to handle large
* graphs efficiently.
*
* Based on: "Scaling Hierarchical Agglomerative Clustering to Trillion-Edge Graphs"
* Google Research 2024
*
* @param graph - Input graph to cluster
* @param config - Configuration options
* @returns Hierarchical clustering result
*/
export declare function teraHAC(graph: Graph, config?: TeraHACConfig): TeraHACResult;
//# sourceMappingURL=terahac.d.ts.map