Undirected Dynamic Graphs¶
Overview¶
 class dynetx.DynGraph(data=None, edge_removal=True, **attr)¶
Base class for undirected dynamic graphs.
A DynGraph stores nodes and timestamped interaction.
DynGraph hold undirected interaction. Self loops are allowed.
Nodes can be arbitrary (hashable) Python objects with optional key/value attributes.
Parameters¶
 datainput graph
Data to initialize graph. If data=None (default) an empty graph is created. The data can be an interaction list, or any NetworkX graph object.
 attrkeyword arguments, optional (default= no attributes)
Attributes to add to graph as key=value pairs.
 edge_removalbool, optional (default=True)
Specify if the dynamic graph instance should allows edge removal or not.
See Also¶
DynDiGraph
Examples¶
Create an empty graph structure (a “null graph”) with no nodes and no interactions.
>>> import dynetx as dn >>> G = dn.DynGraph()
G can be grown in several ways.
Nodes:
Add one node at a time:
>>> G.add_node(1)
Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph).
>>> G.add_nodes_from([2,3]) >>> G.add_nodes_from(range(100,110)) >>> H=dn.DynGraph() >>> H.add_path([0,1,2,3,4,5,6,7,8,9], t=0) >>> G.add_nodes_from(H)
In addition to strings and integers any hashable Python object (except None) can represent a node.
>>> G.add_node(H)
Edges:
G can also be grown by adding interaction and specifying their timestamp.
Add one interaction,
>>> G.add_interaction(1, 2, t=0)
a list of interaction
>>> G.add_interactions_from([(3, 2), (1,3)], t=1)
If some interaction connect nodes not yet in the graph, the nodes are added automatically.
To traverse all interactions of a graph a time t use the interactions(t) method.
>>> G.interactions(t=1) [(3, 2), (1, 3)]
Adding and removing nodes and edges¶

Initialize a graph with interaction, name, graph attributes. 

Add an interaction between u and v at time t vanishing (optional) at time e. 

Add all the interaction in ebunch at time t. 

Add a star at time t. 

Add a path at time t. 

Add a cycle at time t. 
Iterating over nodes and edges¶

Return the list of interaction present in a given snapshot. 

Return an iterator over the interaction present in a given snapshot. 

Return a list of the nodes connected to the node n at time t. 

Return an iterator over all neighbors of node n at time t. 

Return a list of the nodes in the graph at a given snapshot. 

Return an iterator over the nodes with respect to a given temporal snapshot. 
Information about graph structure¶

Return True if the interaction (u,v) is in the graph at time t. 

Return the number of interaction between two nodes at time t. 

Return the degree of a node or nodes at time t. 

Return an iterator for (node, degree) at time t. 

Return the number of edges at time t. 

Return the number of nodes in the t snpashot of a dynamic graph. 

Return True if the graph, at time t, contains the node n. 
Return the number of nodes in the t snpashot of a dynamic graph. 


Return a directed representation of the graph. 

Updates the attributes of a specified node. 

Updates the attributes of a specified node. 
Dynamic Representation: Access Snapshots and Interactions¶
Generate a temporal ordered stream of interactions. 


Return an new graph containing nodes and interactions present in [t_from, t_to]. 
Return the ordered list of snapshot ids present in the dynamic graph. 

Return the number of interactions within snapshot t. 

Return the distribution of inter event time. 