Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/graph output #25

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meritrank_core"
version = "0.8.2"
version = "0.8.3"
edition = "2021"
description = "MeritRank algorithm library"
license = "MIT"
Expand Down
9 changes: 5 additions & 4 deletions core/src/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ impl MeritRank {
}

pub fn get_node_score(&self, ego: NodeId, target: NodeId) -> Result<Weight, MeritRankError> {
let counter = self.pos_hits.get(&ego)
let ego_positive_hits = self.pos_hits.get(&ego)
.ok_or(MeritRankError::NodeIsNotCalculated)?;

let hits = counter.get_count(&target);
let target_hits = ego_positive_hits.get_count(&target);

//if ASSERT && hits > 0.0 && !self.graph.is_connecting(ego, target) { return Err(MeritRankError::NoPathExists); }

let default_counter = Counter::default();

let ego_neg_hits = self.neg_hits.get(&ego).unwrap_or(&default_counter);
let hits_penalized: Weight = hits as Weight - ego_neg_hits.get_count(&target) as Weight;
Ok(hits_penalized / counter.total_count() as Weight)
let total_hits = ego_positive_hits.total_count() + ego_neg_hits.total_count();
let hits_penalized: Weight = target_hits as Weight - ego_neg_hits.get_count(&target) as Weight;
Ok(hits_penalized / total_hits as Weight)
}

pub fn get_ranks(&self, ego: NodeId, limit: Option<usize>) -> Result<Vec<(NodeId, Weight)>, MeritRankError> {
Expand Down
2 changes: 1 addition & 1 deletion service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meritrank_service"
version = "0.2.24"
version = "0.2.25"
edition = "2021"

[features]
Expand Down
2 changes: 1 addition & 1 deletion service/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ impl AugMultiGraph {
self.node_info_from_id(src_id).name.clone(),
self.node_info_from_id(dst_id).name.clone(),
weight,
self.fetch_user_score_reversed(context, src_id, dst_id)
self.fetch_user_score_reversed(context, ego_id, dst_id)
)})
.collect()
}
Expand Down
7 changes: 3 additions & 4 deletions service/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,8 +1611,8 @@ fn scores_reversed() {
"U3" => {
assert!(x.2 > -0.1);
assert!(x.2 < 0.3);
assert!(x.3 >= -1.0);
assert!(x.3 < -0.6);
assert!(x.3 > -0.3);
assert!(x.3 < 0.0);
},

_ => assert!(false),
Expand Down Expand Up @@ -2049,8 +2049,7 @@ fn graph_reversed() {
if x.1 == "U1" {
assert!(x.2 > 0.5);
assert!(x.2 < 0.6);
assert!(x.3 > 0.15);
assert!(x.3 < 0.35);
assert!(x.3 > 0.4);
}

if x.1 == "U3" {
Expand Down