dynetworkx.ImpulseGraph.to_snapshots

ImpulseGraph.to_snapshots(number_of_snapshots, multigraph=False, edge_data=False, edge_timestamp_data=False, node_data=False, return_length=False)

Return a list of networkx Graph or MultiGraph objects as snapshots of the impulse graph in consecutive order.

Parameters:
  • number_of_snapshots (integer) – Number of snapshots to divide the interval graph into. Must be bigger than 1.
  • multigraph (bool, optional (default= False)) – If True, a networkx MultiGraph will be returned. If False, networkx Graph.
  • edge_data (bool, optional (default= False)) – If True, edges will keep their attributes.
  • edge_timestamp_data (bool, optional (default= False)) – If True, each edge’s attribute will also include its timestamp data. If edge_data= True and there already exist edge attributes named timestamp it will be overwritten.
  • node_data (bool, optional (default= False)) – if True, each node’s attributes will be included.
  • return_length (bool, optional (default= False)) – If true, the length of snapshots will be returned as the second argument.

See also

to_subgraph()
subgraph based on an interval

Notes

In order to create snapshots, timestamp of edges of the impulse graph must be numbers.

If multigraph= False, and edge_data=True or edge_timestamp_data=True, in case there are multiple edges, only one will show with one of the edge’s attributes.

Examples

Snapshots of NetworkX Graph

>>> G = dnx.ImpulseGraph()
>>> G.add_edges_from([(1, 2, 10), (2, 4, 11), (6, 4, 19), (2, 4, 15)])
>>> S, l = G.to_snapshots(2, edge_timestamp_data=True, return_length=True)
>>> S
[<networkx.classes.graph.Graph object at 0x100000>, <networkx.classes.graph.Graph object at 0x150d00>]
>>> l
4.5
>>> for g in S:
>>> ... g.edges(data=True))
[(1, 2, {'timestamp': 10}), (2, 4, {'timestamp': 11})]
[(2, 4, {'timestamp': 15}), (4, 6, {'timestamp': 19})]

Snapshots of NetworkX MultiGraph

>>> S, l = G.to_snapshots(3, multigraph=True, edge_timestamp_data=True, return_length=True)
>>> S
[<networkx.classes.multigraph.MultiGraph object at 0x1060d40b8>, <networkx.classes.multigraph.MultiGraph object at 0x151020c9e8>, <networkx.classes.multigraph.MultiGraph object at 0x151021d390>]
>>> l
3.0
>>> for g in S:
>>> ... g.edges(data=True))
[(1, 2, {'timestamp': 10}), (2, 4, {'timestamp': 11})]
[(2, 4, {'timestamp': 15})]
[(6, 4, {'timestamp': 19})]