@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
74 lines • 2.15 kB
TypeScript
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;
}
/**
* 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
*/
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