Temporal Networks

Classes to define temporal networks and run stochastic simulations on them.

class epipack.temporal_networks.TemporalNetwork(N, edge_lists, t, tmax, weighted=False, directed=False, loop_network=True)[source]

Bases: object

A simple temporal network class.

Parameters
  • N (int) -- Static number of nodes in the network.

  • t (list) -- An increasingly ordered list of times.

  • tmax (float) -- The time at which the recording of network changes has concluded (the final time of the temporal network).

  • edge_lists (list) --

    A list of lists of tuples. Each entry i of this list represents an edge list. Each entry j of an edge list is a tuple of format

    ( source, target, weight )
    

    if weighted=True, or

    ( source, target )
    

    otherwise. source and target are supposed to be of unsigned integer type in range [0,N).

  • weighted (bool, default = False) -- Whether or not edge_lists contain edge tuples with weights

  • directed (bool, default = False) -- Whether or not edge tuples will be considered to be directed.

  • loop_network (bool, default = True) -- If True, the temporal network will be looped indefinitely when iterated.

Example

>>> edges = [ [ (0,1) ], [ (0,1), (0,2) ], [] ]
>>> temporal_network = TemporalNetwork(3,[0,0.5,0.6],1.0,edges)
>>> for edge_list, t, next_t in temporal_network:
...     if t >= 3:
...         break
...     print(t, next_t, edge_list)
...
0 0.5 [(0, 1, 1.0)]
0.5 0.6 [(0, 1, 1.0), (0, 2, 1.0)]
0.6 1.0 []
1.0 1.5 [(0, 1, 1.0)]
1.5 1.6 [(0, 1, 1.0), (0, 2, 1.0)]
1.6 2.0 []
2.0 2.5 [(0, 1, 1.0)]
2.5 2.6 [(0, 1, 1.0), (0, 2, 1.0)]
2.6 3.0 []
N

Total and constant number of nodes in the system.

Type

int

t

An increasingly ordered list of times.

Type

list

tmax

The time at which recording of edge changes has concluded (the final time of the temporal network).

Type

float

edge_lists

A list of lists of tuples. Each entry i of this list represents an edge list. Each entry j of an edge list is a tuple of format

( source, target, weight )

if weighted=True, or

( source, target )

otherwise. source and target are supposed to be of unsigned integer type in range [0,N).

Type

list

weighted

Whether or not edge_lists contain edge tuples with weights

Type

bool

directed

Whether or not edge uples will be considered to be directed.

Type

bool

loop_network

If True, the temporal network will be looped indefinitely when iterated.

Type

bool

classmethod from_tacoma(edge_lists, loop_network=True)[source]

Initiate from a tacoma.edge_lists instance

mean_out_degree()[source]

Obtain the temporally averaged mean out-degree

t0()[source]

Obtain the initial time

class epipack.temporal_networks.TemporalNetworkSimulation(temporal_network, stochastic_epi_model)[source]

Bases: object

Simulation of a StochasticEpiModel on a temporal network.

Parameters

Example

>>> model = StochasticEpiModel(["S","I","R"],3)\
>>>             .set_link_transmission_processes([
>>>                     ("I", "S", 1.0, "I", "I"),
>>>                 ])\
>>>             .set_node_transition_processes([
>>>                     ("I", 2.0, "R"),
>>>                 ])\
>>>             .set_node_statuses([1,0,0])
>>> temporal_network = TemporalNetwork(3,edges,[0,0.5,1.2],1.5)
>>> sim = TemporalNetworkSimulation(temporal_network, model)
>>> sim.simulate(tmax=100)
[ 0.          0.38740794  0.8210494   3.60987397  9.46213129 12.14301704] {'S': array([2., 1., 0., 0., 0., 0.]), 'I': array([1., 2., 3., 2., 1., 0.]), 'R': array([0., 0., 0., 1., 2., 3.])}
temporal_network

A temporal network object.

Type

TemporalNetwork

model

An instance of StochasticEpiModel, initialized with processes and initial conditions.

Type

epipack.stochastic_epi_models.StochasticEpiModel

reset(node_status=None)[source]

Reset the model

simulate(tmax, return_compartments=None, max_unsuccessful=None, sample_only_on_network_updates=False)[source]

Simulate a StochasticEpiModel on a temporal network.

Parameters
  • tmax (float) -- maximum length of the simulation

  • return_compartments (list of compartments, default = None:) -- The compartments for which to return time series. If None, all compartments will be returned.

  • max_unsuccessful (int, default = None) -- The number of unsuccessful events after which the true total event rate will be evaluated (it might happen that a network becomes effectively disconnected while nodes are still associated with a maximum event rate). If None, this number will be set equal to the number of nodes.

  • sample_only_on_network_updates (funtion, default = None) -- A function that's called when a sample is taken

Returns

  • t (numpy.ndarray) -- times at which compartment counts have been sampled

  • result (dict) -- Dictionary mapping a compartment to a time series of its count.