Skip to content
Draft
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 examples/rust/src/bin/bench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ fn main() {
g
};
info!("Data loaded\nPageRanking");
page_rank(&graph, None, Some(25), Some(8), None, true, None);
page_rank(&graph, None, Some(25), Some(8), None, true, None, None);
info!("Done PR");
}
5 changes: 3 additions & 2 deletions examples/rust/src/bin/crypto/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ fn main() {

info!("Pagerank");
let now = Instant::now();
let _ = page_rank(&g, None, Some(20), None, None, true, None);
let _ = page_rank(&g, None, Some(20), None, None, true, None, None);
info!("Time taken: {} secs", now.elapsed().as_secs());

let now = Instant::now();

let _ = page_rank(&g, None, Some(20), None, None, true, None);
let _ = page_rank(&g, None, Some(20), None, None, true, None, None);
info!("Time taken: {} secs", now.elapsed().as_secs());

let now = Instant::now();
Expand All @@ -50,6 +50,7 @@ fn main() {
None,
true,
None,
None,
);
info!("Time taken: {} secs", now.elapsed().as_secs());

Expand Down
11 changes: 10 additions & 1 deletion examples/rust/src/bin/pokec/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ fn main() {

let now = Instant::now();

page_rank(&g, None, Some(100), None, Some(0.00000001), true, None);
page_rank(
&g,
None,
Some(100),
None,
Some(0.00000001),
true,
None,
None,
);

info!("PageRank took {} millis", now.elapsed().as_millis());

Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=1.8.3"]
requires = ["maturin>=1.8.1"]
build-backend = "maturin"

[project]
Expand Down
4 changes: 4 additions & 0 deletions python/python/raphtory/algorithms/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def pagerank(
use_l2_norm: bool = True,
damping_factor: float = 0.85,
weight: Optional[str] = None,
personalization: Optional[str] = None,
) -> OutputNodeState:
"""
Pagerank -- pagerank centrality value of the nodes in a graph
Expand All @@ -322,6 +323,9 @@ def pagerank(
use_l2_norm (bool): Flag for choosing the norm to use for convergence checks, True for l2 norm, False for l1 norm. Defaults to True.
damping_factor (float): The damping factor for the PageRank calculation. Defaults to 0.85.
weight (Optional[str]): Edge property key to use as weight. If None, all edges have weight 1.0.
personalization (Optional[str]): Node property key to use as personalization weight.
When provided, the random walk teleports to nodes proportionally to these node property values
instead of uniformly. Values are normalized to sum to 1. Defaults to None (uniform).

Returns:
OutputNodeState: NodeState mapping nodes to their pagerank score.
Expand Down
49 changes: 46 additions & 3 deletions python/tests/test_base_install/test_graphdb/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ def test_weighted_page_rank():
("3", 0.42311),
("4", 0.07837),
]:
assert abs(actual[node]["pagerank_score"] - expected) < 1e-5, (
f"node {node}: {actual[node]} != {expected}"
)
assert (
abs(actual[node]["pagerank_score"] - expected) < 1e-5
), f"node {node}: {actual[node]} != {expected}"


def test_weighted_page_rank_none_matches_unweighted():
Expand All @@ -391,6 +391,49 @@ def test_weighted_page_rank_none_matches_unweighted():
), f"node {node} differs"


def test_personalized_page_rank():
g = Graph()
edges = [(1, 2), (1, 4), (2, 3), (3, 1), (4, 1)]
for node, personalization in [(1, 1.0), (2, 0.0), (3, 0.0), (4, 0.0)]:
g.add_node(0, node, {"personalization": personalization})
for src, dst in edges:
g.add_edge(0, src, dst, {})

actual = algorithms.pagerank(g, iter_count=1000, personalization="personalization")
for node, expected in [
("1", 0.45223),
("2", 0.19220),
("3", 0.16337),
("4", 0.19220),
]:
assert (
abs(actual[node]['pagerank_score'] - expected) < 1e-5
), f"node {node}: {actual[node]} != {expected}"

g = Graph()
g.add_node(0, 1, {"personalization": 0.5})
g.add_node(0, 3, {"personalization": 0.5})
for src, dst in edges:
g.add_edge(0, src, dst, {})

actual = algorithms.pagerank(
g,
iter_count=1000,
max_diff=1e-10,
use_l2_norm=False,
personalization="personalization",
)
for node, expected in [
("1", 0.41832),
("2", 0.17778),
("3", 0.22612),
("4", 0.17778),
]:
assert (
abs(actual[node]['pagerank_score'] - expected) < 1e-5
), f"node {node}: {actual[node]} != {expected}"


def test_temporal_reachability():
g = gen_graph()

Expand Down
2 changes: 1 addition & 1 deletion raphtory-benchmark/benches/algobench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) {
&graph,
|b, graph| {
b.iter(|| {
let result = page_rank(graph, None, Some(100), None, None, true, None);
let result = page_rank(graph, None, Some(100), None, None, true, None, None);
black_box(result);
});
},
Expand Down
2 changes: 1 addition & 1 deletion raphtory-benchmark/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn main() {

// page rank with time
now = Instant::now();
let _page_rank = page_rank(&g, None, Some(1000), None, None, true, None);
let _page_rank = page_rank(&g, None, Some(1000), None, None, true, None, None);
info!("Page rank: {} seconds", now.elapsed().as_secs_f64());

// connected community_detection with time
Expand Down
1 change: 0 additions & 1 deletion raphtory-graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5614,4 +5614,3 @@ schema {
query: QueryRoot
mutation: MutRoot
}

1 change: 1 addition & 0 deletions raphtory-graphql/src/model/plugins/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn apply_pagerank<'b>(
tol,
true,
damping_factor,
None,
);
let result = binding
.into_iter()
Expand Down
42 changes: 31 additions & 11 deletions raphtory-tests/tests/algo_tests/centrality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn test_page_rank() {
("3".to_string(), 0.20916),
("4".to_string(), 0.20195),
]);
let results = page_rank(graph, None, Some(1000), Some(1), None, true, None)
let results = page_rank(graph, None, Some(1000), Some(1), None, true, None, None)
.to_hashmap(|value| value.score);
assert_eq_hashmaps_approx(&results, &expected, 1e-5);
});
Expand Down Expand Up @@ -207,7 +207,7 @@ fn motif_page_rank() {
("9".to_string(), 0.06186),
("5".to_string(), 0.19658),
]);
let results = page_rank(graph, None, Some(1000), Some(4), None, true, None)
let results = page_rank(graph, None, Some(1000), Some(4), None, true, None, None)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-5);
Expand All @@ -227,7 +227,7 @@ fn two_nodes_page_rank() {
test_storage!(&graph, |graph| {
let expected: HashMap<String, f64> =
HashMap::from([("1".to_string(), 0.5), ("2".to_string(), 0.5)]);
let results = page_rank(graph, None, Some(1000), Some(4), None, false, None)
let results = page_rank(graph, None, Some(1000), Some(4), None, false, None, None)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-3);
Expand All @@ -250,7 +250,7 @@ fn three_nodes_page_rank_one_dangling() {
("2".to_string(), 0.393),
("3".to_string(), 0.303),
]);
let results = page_rank(graph, None, Some(10), Some(4), None, false, None)
let results = page_rank(graph, None, Some(10), Some(4), None, false, None, None)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-3);
Expand Down Expand Up @@ -299,7 +299,7 @@ fn dangling_page_rank() {
("10".to_string(), 0.117),
("11".to_string(), 0.122),
]);
let results = page_rank(graph, None, Some(1000), Some(4), None, true, None)
let results = page_rank(graph, None, Some(1000), Some(4), None, true, None, None)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-3);
Expand Down Expand Up @@ -348,6 +348,7 @@ fn page_rank_non_uniform_weights() {
Some(1e-10),
true,
None,
None,
)
.to_hashmap(|value| value.score);

Expand Down Expand Up @@ -390,6 +391,7 @@ fn page_rank_dangling_weighted() {
Some(1e-10),
true,
None,
None,
)
.to_hashmap(|value| value.score);

Expand All @@ -408,10 +410,19 @@ fn page_rank_uniform_weights_match_unweighted() {
}

test_storage!(&graph, |graph| {
let expected = page_rank(graph, None, Some(1000), Some(1), None, true, None)
.to_hashmap(|value| value.score);
let results = page_rank(graph, Some("weight"), Some(1000), Some(1), None, true, None)
let expected = page_rank(graph, None, Some(1000), Some(1), None, true, None, None)
.to_hashmap(|value| value.score);
let results = page_rank(
graph,
Some("weight"),
Some(1000),
Some(1),
None,
true,
None,
None,
)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-5);
});
Expand All @@ -426,10 +437,19 @@ fn page_rank_missing_property_defaults_to_unweighted() {
}

test_storage!(&graph, |graph| {
let expected = page_rank(graph, None, Some(1000), Some(1), None, true, None)
.to_hashmap(|value| value.score);
let results = page_rank(graph, Some("weight"), Some(1000), Some(1), None, true, None)
let expected = page_rank(graph, None, Some(1000), Some(1), None, true, None, None)
.to_hashmap(|value| value.score);
let results = page_rank(
graph,
Some("weight"),
Some(1000),
Some(1),
None,
true,
None,
None,
)
.to_hashmap(|value| value.score);

assert_eq_hashmaps_approx(&results, &expected, 1e-5);
});
Expand Down
2 changes: 1 addition & 1 deletion raphtory-tests/tests/db_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ fn test_node_state_merge() {

let sg = graph.subgraph(1..200);
let degs = degree_centrality(&graph);
let pr = page_rank(&sg, None, None, None, None, false, None);
let pr = page_rank(&sg, None, None, None, None, false, None, None);

let m1 = pr.state.merge(
&degs.state,
Expand Down
Loading
Loading