forked from Refefer/cloverleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsr.rs
43 lines (31 loc) · 952 Bytes
/
lsr.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern crate hashbrown;
use rayon::prelude::*;
use crate::graph::CDFGraph;
use crate::algos::pagerank::PageRank;
use crate::embeddings::EmbeddingStore;
static EPS: f32 = 1e-8;
pub struct LSR {
pub passes: usize
}
impl LSR {
pub fn compute(
&self,
graph: &impl CDFGraph,
degrees: &EmbeddingStore,
indicator: bool
) -> Vec<f32> {
// Find the page rank of the tournament graph
let page_rank = PageRank::new(self.passes, 1f32, EPS);
let mut scores = page_rank.compute(graph, indicator);
// Get the log norm of the scores
let mean = scores.par_iter_mut().enumerate().map(|(node_id, s)| {
*s = (*s / degrees.get_embedding(node_id)[0]).ln();
*s
}).sum::<f32>() / scores.len() as f32;
// Center the scores
scores.par_iter_mut().for_each(|s| {
*s -= mean;
});
scores
}
}