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:
  • data (input 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.
  • attr (keyword arguments, optional (default= no attributes)) – Attributes to add to graph as key=value pairs.
  • edge_removal (bool, 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.

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

DynGraph.__init__([data, edge_removal]) Initialize a graph with interaction, name, graph attributes.
DynGraph.add_interaction(u, v[, t, e]) Add an interaction between u and v at time t vanishing (optional) at time e.
DynGraph.add_interactions_from(ebunch[, t, e]) Add all the interaction in ebunch at time t.
DynGraph.add_star(nodes[, t]) Add a star at time t.
DynGraph.add_path(nodes[, t]) Add a path at time t.
DynGraph.add_cycle(nodes[, t]) Add a cycle at time t.

Iterating over nodes and edges

DynGraph.interactions([nbunch, t]) Return the list of interaction present in a given snapshot.
DynGraph.interactions_iter([nbunch, t]) Return an iterator over the interaction present in a given snapshot.
DynGraph.neighbors(n[, t]) Return a list of the nodes connected to the node n at time t.
DynGraph.neighbors_iter(n[, t]) Return an iterator over all neighbors of node n at time t.
DynGraph.nodes([t, data]) Return a list of the nodes in the graph at a given snapshot.
DynGraph.nodes_iter([t, data]) Return an iterator over the nodes with respect to a given temporal snapshot.

Information about graph structure

DynGraph.has_interaction(u, v[, t]) Return True if the interaction (u,v) is in the graph at time t.
DynGraph.number_of_interactions([u, v, t]) Return the number of interaction between two nodes at time t.
DynGraph.degree([nbunch, t]) Return the degree of a node or nodes at time t.
DynGraph.degree_iter([nbunch, t]) Return an iterator for (node, degree) at time t.
DynGraph.size([t]) Return the number of edges at time t.
DynGraph.order([t]) Return the number of nodes in the t snpashot of a dynamic graph.
DynGraph.has_node(n[, t]) Return True if the graph, at time t, contains the node n.
DynGraph.number_of_nodes([t]) Return the number of nodes in the t snpashot of a dynamic graph.
DynGraph.to_directed() Return a directed representation of the graph.

Dynamic Representation: Access Snapshots and Interactions

DynGraph.stream_interactions() Generate a temporal ordered stream of interactions.
DynGraph.time_slice(t_from[, t_to]) Return an new graph containing nodes and interactions present in [t_from, t_to].
DynGraph.temporal_snapshots_ids() Return the ordered list of snapshot ids present in the dynamic graph.
DynGraph.interactions_per_snapshots([t]) Return the number of interactions within snapshot t.
DynGraph.inter_event_time_distribution([u, v]) Return the distribution of inter event time.