Build the normalized per-node seed distribution for Personalized PageRank. Returns `None` (→ standard uniform PageRank) when no personalization vector is supplied, or when none of its seed nodes exist in the graph / all seed weights are non-positive — falling back to uniform rather than emitting an all-zero ranking. Negative weights are clamped to 0.0. The returned vector is indexed by CSR node o
(csr: &CsrIndex, params: &AlgoParams, n: usize)
| 124 | /// all-zero ranking. Negative weights are clamped to 0.0. The returned vector |
| 125 | /// is indexed by CSR node ordinal and sums to 1.0. |
| 126 | fn build_personalization(csr: &CsrIndex, params: &AlgoParams, n: usize) -> Option<Vec<f64>> { |
| 127 | let seeds = params.personalization_vector()?; |
| 128 | let mut p = vec![0.0f64; n]; |
| 129 | let mut sum = 0.0; |
| 130 | for (i, slot) in p.iter_mut().enumerate() { |
| 131 | if let Some(&w) = seeds.get(csr.node_name_raw(i as u32)) { |
| 132 | let w = w.max(0.0); |
| 133 | *slot = w; |
| 134 | sum += w; |
| 135 | } |
| 136 | } |
| 137 | if sum <= 0.0 { |
| 138 | return None; |
| 139 | } |
| 140 | for v in &mut p { |
| 141 | *v /= sum; |
| 142 | } |
| 143 | Some(p) |
| 144 | } |
| 145 | |
| 146 | #[cfg(test)] |
| 147 | mod tests { |
no test coverage detected