Skip to content

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

Open
ypislon wants to merge 1 commit into
GiulioRossetti:masterfrom
ypislon:fix_time_slices
Open

ypislon wants to merge 1 commit into
GiulioRossetti:masterfrom
ypislon:fix_time_slices

Conversation

@ypislon

@ypislon ypislon commented Feb 18, 2024 •

Copy link
Copy Markdown

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]]})]

@KyleQuarles

Copy link
Copy Markdown

Can you explain in more detail how this branch addresses the problem of switched edge directions? Why did the old code have that bug? I also have that problem, but your examples mainly address the problem of time values. Would be nice if Rossetti could chime in too.

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()

2 participants