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

Adjust time_slice method to return sliced graph with correct interactions #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ypislon
Copy link

@ypislon ypislon commented Feb 18, 2024

Problem description

When using time_slice to create a time slice of a graph, the returned time slice contains wrong timestamps for the end of an interaction (which are always one unit to small) and the time slice does not take all interactions into account for directed graphs and reverses the direction of edges (see #135).

The terminology here was a bit confusing to me: when using time_slice(t_from=0, t_to=2), I expect the graph to include all snapshots from t=0 to and including t=2. When adding an interaction add_interaction(t=0, e=2), I expect the interaction to last from t=0 to t=1 and vanish at e=2. (I hope I interpret the terminology used by the library correctly).

The changes in this branch therefore add an additional time unit when creating the time slice to take this into account.

The changes also respect the direction of edges for directed graphs when checking for seen nodes and when creating a list of interactions.

This should fix #135.

Example

G = dn.DynDiGraph()
G.add_interaction(0,1, t=0, e=2)
G.add_interaction(1,2, t=0)
G.add_interaction(2,4, t=0)
G.add_interaction(0,4, t=1)
G.add_interaction(4,5, t=1)
G.add_interaction(5,6, t=1)
G.add_interaction(7,1, t=2)
G.add_interaction(1,2, t=2)
G.add_interaction(2,3, t=2)
H = G.time_slice(0)
I = G.time_slice(0, 2)

Previous behavior:

>>> G.interactions()
[(0, 1, {'t': [[0, 1]]}), (0, 4, {'t': [[1, 1]]}), (1, 2, {'t': [[0, 0], [2, 2]]}), (1, 7, {'t': [[2, 2]]}), (2, 4, {'t': [[0, 0]]}), (2, 3, {'t': [[2, 2]]}), (4, 5, {'t': [[1, 1]]}), (5, 6, {'t': [[1, 1]]})]
>>> H.interactions()
[(0, 1, {'t': [[0, -1]]})]
>>> I.interactions()
[(0, 1, {'t': [[0, 0]]}), (2, 4, {'t': [[0, -1]]})]

Behavior after changes:

>>> G.interactions()
[(0, 1, {'t': [[0, 1]]}), (0, 4, {'t': [[1, 1]]}), (1, 2, {'t': [[0, 0], [2, 2]]}), (1, 7, {'t': [[2, 2]]}), (2, 4, {'t': [[0, 0]]}), (2, 3, {'t': [[2, 2]]}), (4, 5, {'t': [[1, 1]]}), (5, 6, {'t': [[1, 1]]})]
>>> H.interactions()
[(0, 1, {'t': [[0, 0]]}), (1, 2, {'t': [[0, 0]]}), (2, 4, {'t': [[0, 0]]})]
>>> I.interactions()
[(0, 1, {'t': [[0, 1]]}), (0, 4, {'t': [[1, 1]]}), (1, 2, {'t': [[0, 0], [2, 2]]}), (1, 7, {'t': [[2, 2]]}), (4, 2, {'t': [[0, 0]]}), (4, 5, {'t': [[1, 1]]}), (2, 3, {'t': [[2, 2]]}), (5, 6, {'t': [[1, 1]]})]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with Dydigraph time_slice() + interactions()
1 participant