Skip to content

Commit

Permalink
event based temporal SEIR algorithm (#1415)
Browse files Browse the repository at this point in the history
* event based temporal SEIR algorithm

* fix the event queue so it is actually a min heap and return algorithm result

* add proper test

* add python interface

* improve the repr for AlgorithmResult

* more repr cleanup

* get rid of the Options in AlgorithmResult by only returning vertices that actually have results

* basic python test

* add python docs

* fix the docs ignores

* this should not be a doc comment

* bring back the AlgorithmResult docs hack

* fix formatting and actually include in docs

* no doctests for python!

* bring back missing import
  • Loading branch information
ljeub-pometry authored Dec 15, 2023
1 parent 8bf5d49 commit 736d208
Show file tree
Hide file tree
Showing 37 changed files with 945 additions and 403 deletions.
12 changes: 4 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ massif.*
**/.env/
comparison-benchmark/python/data/*
.vscode
docs/source/_rustdoc/*
docs/nx.html
docs/graph.html
docs/build/*
.DS_Store
docs/logs/*
.python-version
.ipynb_checkpoints
docs/source/_rustdoc/*
docs/build/*
docs/logs/*
_autosummary
examples/docker/lotr/lotr
examples/py/enron/emails.csv
examples/py/enron/lib/
docs/source/_rustdoc/
docs/logs/
/docs/lib/
/docs/build/
docs/source/
docs/nx.html
docs/graph.html
.env

# Byte-compiled / optimized / DLL files
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/source/reference/algorithms/dynamics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dynamics
********

.. autofunction:: raphtory.algorithms.temporal_SEIR
1 change: 1 addition & 0 deletions docs/source/reference/algorithms/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Algorithms
centrality
community_detection
cores
dynamics
metrics
motifs
pathing
3 changes: 1 addition & 2 deletions python/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ use raphtory_core::{
},
vectors::{embeddings::openai_embedding, EmbeddingFunction},
};
use raphtory_graphql::{url_decode_graph, url_encode_graph, RaphtoryServer};
use raphtory_graphql::{url_encode_graph, RaphtoryServer};
use reqwest::Client;
use serde_json::{json, Map, Number, Value};
use std::{
collections::HashMap,
future::Future,
path::PathBuf,
thread,
thread::{sleep, JoinHandle},
Expand Down
1 change: 1 addition & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn raphtory(py: Python<'_>, m: &PyModule) -> PyResult<()> {
hits,
balance,
label_propagation,
temporal_SEIR,
);
m.add_submodule(algorithm_module)?;

Expand Down
19 changes: 18 additions & 1 deletion python/tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ def test_single_source_shortest_path():
assert res_one.get_all_with_names() == {
"1": ["1"],
"2": ["1", "2"],
"3": None,
"4": ["1", "4"],
}
assert (
Expand Down Expand Up @@ -461,3 +460,21 @@ def test_label_propagation_algorithm():
assert len(result) == len(expected)
for group in expected:
assert group in result


def test_temporal_SEIR():
g = Graph()
g.add_edge(1, 1, 2)
g.add_edge(2, 2, 3)
g.add_edge(3, 3, 4)
g.add_edge(4, 4, 5)
# Should be seeded with 2 vertices
res = algorithms.temporal_SEIR(g, 2, 1.0, 0, rng_seed=1)
seeded = [v for v in res.get_all_values() if v.infected == 0]
assert len(seeded) == 2

res = algorithms.temporal_SEIR(g, [1], 1.0, 0, rng_seed=1).sort_by_value(reverse=False)
for i, (n, v) in enumerate(res):
assert n == g.node(i+1)
assert v.infected == i

1 change: 1 addition & 0 deletions raphtory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ quickcheck_macros = "1"
tempfile = "3.2"
tokio = { version = "1.27.0", features = ["full"]} # for vector testing
dotenv = "0.15.0" # for vector testing
streaming-stats = "0.2"

[features]
default = []
Expand Down
Loading

0 comments on commit 736d208

Please sign in to comment.