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

DynDiGraph.__init__([data, edge_removal])

Initialize a directed graph with interaction, name, graph attributes.

DynDiGraph.add_interaction(u, v[, t, e])

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

DynDiGraph.add_interactions_from(ebunch[, t, e])

Add all the interaction in ebunch at time t.

Iterating over nodes and edges

DynDiGraph.interactions([nbunch, t])

Return the list of interaction present in a given snapshot.

DynDiGraph.interactions_iter([nbunch, t])

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

DynDiGraph.in_interactions([nbunch, t])

Return the list of incoming interaction present in a given snapshot.

DynDiGraph.in_interactions_iter([nbunch, t])

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

DynDiGraph.out_interactions([nbunch, t])

Return the list of out interaction present in a given snapshot.

DynDiGraph.out_interactions_iter([nbunch, t])

Return an iterator over the out interactions present in a given snapshot.

DynDiGraph.neighbors(n[, t])

Return a list of successor nodes of n at time t (optional).

DynDiGraph.neighbors_iter(n[, t])

Return an iterator over successor nodes of n at time t (optional).

DynDiGraph.successors(n[, t])

Return a list of successor nodes of n at time t (optional).

DynDiGraph.successors_iter(n[, t])

Return an iterator over successor nodes of n at time t (optional).

DynDiGraph.predecessors(n[, t])

Return a list of predecessor nodes of n at time t (optional).

DynDiGraph.predecessors_iter(n[, t])

Return an iterator over predecessors nodes of n at time t (optional).

DynDiGraph.nodes([t, data])

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

DynDiGraph.nodes_iter([t, data])

Return an iterator over the nodes with respect to a given temporal snapshot.

Information about graph structure

DynDiGraph.has_interaction(u, v[, t])

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

DynDiGraph.has_successor(u, v[, t])

Return True if node u has successor v at time t (optional).

DynDiGraph.has_predecessor(u, v[, t])

Return True if node u has predecessor v at time t (optional).

DynDiGraph.number_of_interactions([u, v, t])

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

DynDiGraph.degree([nbunch, t])

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

DynDiGraph.degree_iter([nbunch, t])

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

DynDiGraph.in_degree([nbunch, t])

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

DynDiGraph.in_degree_iter([nbunch, t])

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

DynDiGraph.out_degree([nbunch, t])

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

DynDiGraph.out_degree_iter([nbunch, t])

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

DynDiGraph.size([t])

Return the number of edges at time t.

DynDiGraph.order()

Returns the number of nodes in the graph.

DynDiGraph.has_node(n[, t])

Return True if the graph, at time t, contains the node n.

DynDiGraph.number_of_nodes([t])

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

DynDiGraph.to_undirected([reciprocal])

Return an undirected representation of the dyndigraph.

DynDiGraph.update_node_attr(n, **data)

Updates the attributes of a specified node.

DynDiGraph.update_node_attr_from(nlist, **data)

Updates the attributes of a specified node.

Dynamic Representation: Access Snapshots and Interactions

DynDiGraph.stream_interactions()

Generate a temporal ordered stream of interactions.

DynDiGraph.time_slice(t_from[, t_to])

Return an new graph containing nodes and interactions present in [t_from, t_to].

DynDiGraph.temporal_snapshots_ids()

Return the ordered list of snapshot ids present in the dynamic graph.

DynDiGraph.interactions_per_snapshots([t])

Return the number of interactions within snapshot t.

DynDiGraph.inter_event_time_distribution([u, v])

Return the distribution of inter event time.

DynDiGraph.inter_in_event_time_distribution([u, v])

Return the distribution of inter event time for in interactions.

DynDiGraph.inter_out_event_time_distribution([u, v])

Return the distribution of inter event time for out interactions.