Contact matrix

Classes and methods to compute contact matrix of a meta-population. The contact matrix \(C_{ij}\) denotes the average number of contacts made per day by an individual in class \(i\) with an individual in class \(j\). Clearly, the total number of contacts between group \(i\) to group \(j\) must equal the total number of contacts from group \(j\) to group \(i\), and thus, for populations of fixed size the contact matrices obey the reciprocity relation \(N_{i}C_{ij}=N_{j}C_{ji}\). Here \(N_i\) is the population in group \(i\).

Contact Matrix Function

Generates contact matrix for given interventions

class pyross.contactMatrix.ContactMatrixFunction

Generates a time dependent contact matrix

For prefactors \(a_{W1}, a_{W2}, a_{S1}, a_{S2}, a_{O1}, a_{O2}\) that multiply the contact matrices CW, CS, and CO. the final contact matrix is computed as

\[CM_{ij} = CH_{ij} + (a_{W1})_i CW_{ij} (a_{W2})_j + (a_{S1})_i CW_{ij} (a_{S2})_j + (a_{O1})_i CO_{ij} (a_{O2})_j\]

For all the intervention functions, if a prefactor is passed as scalar, it is set to be an M (=no. of metapopulation groups) dimensional vector with all entries equal to the scalar.

Parameters:
  • CH (2d np.array) – Contact matrix at home
  • CW (2d np.array) – Contact matrix at work
  • CS (2d np.array) – Contact matrix at school
  • CO (2d np.array) – Contact matrix at other locations
constant_contactMatrix()

Constant contact matrix

Parameters:
  • aW (float or array of size M, optional) – Fraction of work contact per receiver of infection. Default is 1.
  • aS (float or array of size M, optional) – Fraction of school contact per receiver of infection. Default is 1.
  • aO (float or array of size M, optional) – Fraction of other contact per receiver of infection. Default is 1.
  • aW2 (float or array of size M or None, optional) – Fraction of work contact per giver of infection. If set to None, aW2 = aW.
  • aS2 (float or array of size M or None, optional) – Fraction of school contact per giver of infection. If set to None, aS2 = aS.
  • aO2 (float or array of size M or None, optional) – Fraction of other contact per giver of infection. If set to None, aO2 = aO.
Returns:

contactMatrix – A function that takes t as an argument and outputs the contact matrix

Return type:

callable

get_individual_contactMatrices()

Returns the internal CH, CW, CS and CO

intervention_custom_temporal()

Custom temporal interventions

Parameters:
  • intervention_func (callable) – The calling signature is intervention_func(t, **kwargs), where t is time and kwargs are other keyword arguments for the function. The function must return (aW, aS, aO), where aW, aS and aO must be of shape (2, M)
  • kwargs (dict) – Keyword arguments for the function.
Returns:

contactMatrix – A function that takes t as an argument and outputs the contact matrix.

Return type:

callable

Examples

An example for an custom temporal intervetion that allows for some anticipation and reaction time

>>> def fun(t, M, width=1, loc=0) # using keyword arguments for parameters of the intervention
>>>     a = (1-np.tanh((t-loc)/width))/2
>>>     a_full = np.full((2, M), a)
>>>     return a_full, a_full, a_full
>>>
>>> contactMatrix = generator.intervention_custom_temporal(fun, width=5, loc=10)
interventions_temporal()

Temporal interventions

Parameters:
  • time (np.array) – Ordered array with temporal boundaries between the different interventions.
  • interventions (np.array) – Ordered matrix with prefactors aW, aS, aO such that aW1=aW2=aW during the different time intervals. Note that len(interventions) = len(times) + 1
Returns:

contactMatrix – A function that takes t as an argument and outputs the contact matrix

Return type:

callable

interventions_threshold()

Temporal interventions

Parameters:
  • threshold (np.array) – Ordered array with temporal boundaries between the different interventions.
  • interventions (np.array) – Array of shape [K+1,3, ..] with prefactors during different phases of intervention The current state of the intervention is defined by the largest integer “index” such that state[j] >= thresholds[index,j] for all j.
Returns:

contactMatrix – A function that takes t as an argument and outputs the contact matrix

Return type:

callable

Spatial Contact Matrix

Approximates the spatial contact matrix given the locations, populations and areas of the geographical regions and the overall age structured contact matrix.

class pyross.contactMatrix.SpatialContactMatrix

A class for generating a spatial compartmental model with commute data

Let \(\mu, \nu\) denote spatial index and i, j denote age group index.

\[C^{\mu\nu}_{ij} = \frac{1}{N^\mu_i} \widetilde{C}^{\mu \nu}_{ij}\]
Parameters:
  • b (float) – Parameter b in the above equation
  • populations (np.array(n_loc, M)) – Populations of regions by age groups. Here n_loc is the number of regions and M is the number of age groups.
  • areas (np.array(n_loc)) – Areas of the geographical regions.
  • commutes (np.array(n_loc, n_loc, M)) – Each entry commute[mu, nu, i] needs to be the number of people of age group i commuting from \(\mu\) to \(\nu\). Entries with \(\mu = \nu\) are ignored.
contactMatrix.characterise_transient()

The maximal eigenvalue (spectral abcissa), initial groth rate (numerical abcissa), the Kreiss constant (minimum bound of transient) and time of transient growth

Parameters:
  • A (an MxM matrix) –
  • tol (Used to find a first estimate of the pseudospectrum) –
  • theta (normalizing factor found in Townley et al 2007, default 0) –
  • ord (default 2, order of matrix norm) –
Returns:

  • [spectral abcissa, numerical abcissa, Kreiss constant,
  • duration of transient, henrici’s departure from normalcy]