pub fn pagerank(
graph: &SqliteGraph,
damping: f64,
iterations: usize,
) -> Result<Vec<(i64, f64)>, SqliteGraphError>Expand description
Computes PageRank scores for all nodes in the graph.
PageRank measures node importance based on link structure. Nodes with many incoming links from important nodes receive higher scores. Originally developed by Google for ranking web pages.
§Arguments
graph- The graph to analyzedamping- Damping factor (typically 0.85), representing probability of continuing random walkiterations- Number of power iteration iterations (20-50 recommended, fixed not convergence-based)
§Returns
Vector of (node_id, score) tuples sorted by score descending. Scores sum to approximately 1.0.
§Complexity
Time: O(k * |E|) where k = iterations Space: O(|V|) for score storage
§Algorithm Details
Uses power iteration method (fixed iteration count for determinism):
- Initialize all nodes with equal score (1.0 / node_count)
- For each iteration:
- new_score = (1-d)/n + d * sum(incoming_scores / outgoing_count)
- Handle dangling nodes (no outgoing edges) by redistributing their score equally
- Sort results by score descending
§References
- Page, L., Brin, S., Motwani, R., & Winograd, T. (1999). “The PageRank Citation Ranking: Bringing Order to the Web.”
§Example
use sqlitegraph::{SqliteGraph, algo::pagerank};
let graph = SqliteGraph::open_in_memory()?;
// ... add nodes and edges ...
let scores = pagerank(&graph, 0.85, 20)?;