Skip to main content

personalized_pagerank

Function personalized_pagerank 

Source
pub fn personalized_pagerank(
    graph: &Graph,
    reset: &[f64],
    damping: f64,
) -> IgraphResult<Vec<f64>>
Expand description

Personalized PageRank scores via power iteration.

reset: the personalization vector. Must have length vcount() and contain non-negative values that sum to a positive number (they are internally normalized to sum to 1). Vertices with higher reset weight attract more rank during teleportation.

damping: the damping factor (probability of following edges vs. teleporting). Must be in (0, 1). Use 0.85 for standard behavior.

Returns a Vec<f64> summing approximately to 1.

Counterpart of igraph_personalized_pagerank(_, IGRAPH_PAGERANK_ALGO_POWER, _, _, vss_all(), directed, damping, reset, weights=NULL, _)

§Errors

  • InvalidArgument if reset length does not match vcount().
  • InvalidArgument if reset contains negative values.
  • InvalidArgument if reset sums to zero.
  • InvalidArgument if damping is not in (0, 1).

§Examples

use rust_igraph::{Graph, personalized_pagerank};

// 4-cycle: bias teleportation toward vertex 1.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 0).unwrap();
// Reset only on vertex 1 — it gets the highest PR.
let reset = vec![0.0, 1.0, 0.0, 0.0];
let pr = personalized_pagerank(&g, &reset, 0.85).unwrap();
assert!(pr[1] > pr[0]);
assert!(pr[1] > pr[2]);
assert!(pr[1] > pr[3]);

// Uniform reset: all vertices equal on a symmetric graph.
let uniform = vec![0.25, 0.25, 0.25, 0.25];
let pr_uniform = personalized_pagerank(&g, &uniform, 0.85).unwrap();
let sum: f64 = pr_uniform.iter().sum();
assert!((sum - 1.0).abs() < 1e-9);