Implementing temporal networks in Python

 Created: 28 Jul 2014  Modified: 23 Jul 2020   BibTeX Entry   RIS Citation  Print

Overview

The goal here is to prototype a smooth and efficient way of evolving a NetworkX graph object, given a more compact specification of a “interval” temporal network, as discussed in Temporal Networks in SeriationCT.

In the following, I assume either that a compact configuration, or a random network generating process (NGP), produces a sequence of numpy matrices which are indexed by a time coordinate. The task, then, is to examine differences in the sequence of matrices, and produce corresponding changes to a NetworkX graph object, without simply destroying and reformulating the graph object.

The latter requirement is important because each vertex in the graph object will also be a container, holding a subpopulation of agents which are engaged in social learning. Vertices will thus represent demes of individuals, and our observable samples in the seriationct model will be derived as time-averaged samples of traits from each vertex.

Prototyping

For simplicity, I start with the complete graph \(C4\) on four vertices, with one link having a link weight

At step 2, we imagine that two links are lost, indicated by their weight going to zero in the adjacency matrix.

We can tell which edges change by looking at the nonzero elements of the upper triangular portion of the difference of the two matrices:

changed_edges reports those elements which are different between the two matrices, in the upper triangular portion of the matrix. We are mainly interested in off-diagonal elements at the moment. The data structure is a tuple composed of two lists, the row and then the column coordinates. This unusual structure is the reason for the use of zip in the enumeration below.

Weight changes to existing edges are simply the difference between the two matrix elements, already reflected in the changed matrix entry, and we can detect edges that go away entirely by a weight change which complete offsets the t1 weight at t2. If an edge goes away, we remove it. If the weight changes, we alter the weight property for the edge

References Cited