UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

91 lines 2.85 kB
import type { Graph } from "../../core/graph.js"; import type { NodeId } from "../../types/index.js"; /** * PageRank algorithm implementation * * Measures the importance of nodes in a directed graph based on the * structure of incoming links. Originally designed for ranking web pages. */ /** * PageRank algorithm options */ export interface PageRankOptions { /** * Damping factor (probability of following a link) (default: 0.85) */ dampingFactor?: number; /** * Maximum number of iterations (default: 100) */ maxIterations?: number; /** * Convergence tolerance (default: 1e-6) */ tolerance?: number; /** * Initial PageRank values for nodes (default: uniform distribution) */ initialRanks?: Map<NodeId, number>; /** * Personalization vector for Personalized PageRank (default: null) */ personalization?: Map<NodeId, number>; /** * Weight attribute for weighted PageRank (default: null = unweighted) */ weight?: string; /** * Use delta-based optimization for faster convergence. * Defaults to true for graphs with >100 nodes, false for smaller graphs. * Set explicitly to override automatic heuristic. */ useDelta?: boolean; } /** * PageRank algorithm result */ export interface PageRankResult { /** * PageRank scores for each node */ ranks: Record<string, number>; /** * Number of iterations until convergence */ iterations: number; /** * Whether the algorithm converged */ converged: boolean; } /** * Calculate PageRank for all nodes in the graph * * Uses delta-based optimization by default for improved performance on larger graphs. * Automatically falls back to standard algorithm for very small graphs. * * The delta-based approach provides significant speedup for: * - Incremental updates after graph modifications * - Graphs with localized changes * - Early convergence detection per vertex * * For initial computation on small-medium graphs, standard algorithm may be faster * due to lower overhead. */ export declare function pageRank(graph: Graph, options?: PageRankOptions): PageRankResult; /** * Calculate Personalized PageRank for a specific set of source nodes */ export declare function personalizedPageRank(graph: Graph, personalNodes: NodeId[], options?: Omit<PageRankOptions, "personalization">): PageRankResult; /** * Calculate PageRank centrality (normalized PageRank scores) */ export declare function pageRankCentrality(graph: Graph, options?: PageRankOptions): Record<string, number>; /** * Get the top-k nodes by PageRank score */ export declare function topPageRankNodes(graph: Graph, k: number, options?: PageRankOptions): { node: NodeId; rank: number; }[]; //# sourceMappingURL=pagerank.d.ts.map