-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow precomputed flow for state networks
- Loading branch information
1 parent
b1b750e
commit ab7c5b5
Showing
13 changed files
with
263 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# A multilayer network using explicit format | ||
# Figure 3 | ||
*Vertices 5 | ||
# node_id name | ||
1 "i" | ||
2 "j" | ||
3 "k" | ||
4 "l" | ||
5 "m" | ||
*Multilayer | ||
# layer_id node_id layer_id node_id weight | ||
# intra | ||
1 1 1 4 0.8 | ||
1 4 1 1 1 | ||
1 1 1 5 0.8 | ||
1 5 1 1 1 | ||
1 4 1 5 1 | ||
1 5 1 4 1 | ||
2 1 2 2 0.8 | ||
2 2 2 1 1 | ||
2 1 2 3 0.8 | ||
2 3 2 1 1 | ||
2 2 2 3 1 | ||
2 3 2 2 1 | ||
# inter | ||
1 1 2 2 0.2 | ||
1 1 2 3 0.2 | ||
2 1 1 4 0.2 | ||
2 1 1 5 0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# A network in state format | ||
# Figure 6 | ||
*Vertices 5 | ||
#node_id name | ||
1 "i" | ||
2 "j" | ||
3 "k" | ||
4 "l" | ||
5 "m" | ||
*States | ||
#state_id node_id name | ||
1 1 "α~_i" | ||
2 2 "β~_j" | ||
3 3 "γ~_k" | ||
4 1 "δ~_i" | ||
5 4 "ε~_l" | ||
6 5 "ζ~_m" | ||
*Links | ||
#source target weight | ||
1 2 0.8 | ||
1 3 0.8 | ||
1 5 0.2 | ||
1 6 0.2 | ||
2 1 1 | ||
2 3 1 | ||
3 1 1 | ||
3 2 1 | ||
4 5 0.8 | ||
4 6 0.8 | ||
4 2 0.2 | ||
4 3 0.2 | ||
5 4 1 | ||
5 6 1 | ||
6 4 1 | ||
6 5 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# A network in state format | ||
# Figure 6 | ||
*Vertices 5 | ||
#node_id name | ||
1 "i" 0.4 | ||
2 "j" 0.15 | ||
3 "k" 0.15 | ||
4 "l" 0.15 | ||
5 "m" 0.15 | ||
*States | ||
#state_id node_id name | ||
1 1 "α~_i" 0.1 | ||
2 2 "β~_j" 0.1 | ||
3 3 "γ~_k" 0.3 | ||
4 1 "δ~_i" 0.3 | ||
5 4 "ε~_l" 0.1 | ||
6 5 "ζ~_m" 0.1 | ||
*Links | ||
#source target weight | ||
1 2 0.08 | ||
1 3 0.08 | ||
1 5 0.02 | ||
1 6 0.02 | ||
2 1 0.1 | ||
2 3 0.1 | ||
3 1 0.1 | ||
3 2 0.1 | ||
4 5 0.08 | ||
4 6 0.08 | ||
4 2 0.02 | ||
4 3 0.02 | ||
5 4 0.1 | ||
5 6 0.1 | ||
6 4 0.1 | ||
6 5 0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# v2.7.0 | ||
# ./Infomap --silent --flow-model precomputed | ||
# State network as physical network | ||
*Vertices | ||
#id name flow | ||
1 "1" 0.1 | ||
2 "2" 0.1 | ||
3 "3" 0.3 | ||
4 "4" 0.3 | ||
5 "5" 0.1 | ||
6 "6" 0.1 | ||
*Arcs | ||
#source target flow | ||
1 2 0.08 | ||
1 3 0.08 | ||
1 5 0.02 | ||
1 6 0.02 | ||
2 1 0.1 | ||
2 3 0.1 | ||
3 1 0.1 | ||
3 2 0.1 | ||
4 2 0.02 | ||
4 3 0.02 | ||
4 5 0.08 | ||
4 6 0.08 | ||
5 4 0.1 | ||
5 6 0.1 | ||
6 4 0.1 | ||
6 5 0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*Vertices | ||
1 "A" 0.1 | ||
2 "B" 0.2 | ||
3 "C" 0.3 | ||
4 "D" 0.2 | ||
5 "E" 0.1 | ||
6 "F" 0.1 | ||
*Edges | ||
1 2 0.1 | ||
1 3 0.2 | ||
2 3 0.3 | ||
3 4 0.1 | ||
4 5 0.1 | ||
4 6 0.1 | ||
5 6 0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# v2.7.0 | ||
# ./Infomap --silent --flow-model precomputed | ||
*Vertices | ||
#id name flow | ||
1 "A" 0.1 | ||
2 "B" 0.2 | ||
3 "C" 0.3 | ||
4 "D" 0.2 | ||
5 "E" 0.1 | ||
6 "F" 0.1 | ||
*Arcs | ||
#source target flow | ||
1 2 0.1 | ||
1 3 0.2 | ||
2 3 0.3 | ||
3 4 0.1 | ||
4 5 0.1 | ||
4 6 0.1 | ||
5 6 0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from infomap import Infomap | ||
import re | ||
from pathlib import Path | ||
import filecmp | ||
import pytest | ||
|
||
|
||
def test_precomputed_requirements(): | ||
im = Infomap(silent=True, flow_model="precomputed") | ||
im.read_file("examples/networks/twotriangles.net") | ||
with pytest.raises(RuntimeError, match=re.escape("Missing node flow in input data. Should be passed as a third field under a *Vertices section.")): | ||
im.run() | ||
|
||
|
||
def test_precomputed_states_requirements(): | ||
im = Infomap(silent=True, flow_model="precomputed") | ||
im.read_file("examples/networks/states.net") | ||
with pytest.raises(RuntimeError, match=re.escape("Missing node flow in input data. Should be passed as a third field under a *States section.")): | ||
im.run() | ||
|
||
|
||
def test_precomputed_from_file(): | ||
im = Infomap(silent=True, flow_model="precomputed") | ||
im.read_file("test/data/twotriangles_flow.net") | ||
im.run() | ||
output_path = Path("test/data/output/twotriangles_flow_output.net") | ||
output_path.parent.mkdir(exist_ok=True) | ||
im.write_pajek(str(output_path), flow=True) | ||
assert (filecmp.cmp(output_path, "test/data/twotriangles_flow_output.net")) | ||
|
||
|
||
def test_precomputed_states_from_file(): | ||
im = Infomap(silent=True, flow_model="precomputed") | ||
im.read_file("test/data/states_flow.net") | ||
im.run() | ||
output_path = Path("test/data/output/states_flow_output.net") | ||
output_path.parent.mkdir(exist_ok=True) | ||
im.write_pajek(str(output_path), flow=True) | ||
assert (filecmp.cmp(output_path, "test/data/states_flow_output.net")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.