Directed Dynamic Graphs¶
Overview¶
- class dynetx.DynDiGraph(data=None, edge_removal=True, **attr)¶
Base class for directed dynamic graphs.
DynDiGraph hold directed interactions. Self loops are allowed.
Nodes can be arbitrary (hashable) Python objects with optional key/value attributes.
Interactions are represented as links between nodes.
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 interactions removal or not.
See Also¶
DynGraph
Examples¶
Create an empty graph structure (a “null graph”) with no nodes and no interactions.
>>> import dynetx as dn >>> G = dn.DynDiGraph()
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.DynDiGraph() >>> H.add_nodes_from([0,1,2,3,4,5,6,7,8,9]) >>> 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 directed 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. |
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 the list of incoming interaction present in a given snapshot. |
|
Return an iterator over the in interactions present in a given snapshot. |
|
Return the list of out interaction present in a given snapshot. |
|
Return an iterator over the out interactions present in a given snapshot. |
|
Return a list of successor nodes of n at time t (optional). |
|
Return an iterator over successor nodes of n at time t (optional). |
|
Return a list of successor nodes of n at time t (optional). |
|
Return an iterator over successor nodes of n at time t (optional). |
|
Return a list of predecessor nodes of n at time t (optional). |
|
Return an iterator over predecessors nodes of n at time t (optional). |
|
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 True if node u has successor v at time t (optional). |
|
Return True if node u has predecessor v at time t (optional). |
|
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 in degree of a node or nodes at time t. |
|
Return an iterator for (node, in_degree) at time t. |
|
Return the out degree of a node or nodes at time t. |
|
Return an iterator for (node, out_degree) at time t. |
|
Return the number of edges at time t. |
Returns the number of nodes in the graph. |
|
|
Return True if the graph, at time t, contains the node n. |
Return the number of nodes in the t snapshot of a dynamic graph. |
|
|
Return an undirected representation of the dyndigraph. |
|
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. |
|
Return the distribution of inter event time for in interactions. |
|
Return the distribution of inter event time for out interactions. |