population

population

Defines functions for making contact edge lists, e.g. for custom layers.

These are not used by cv.Sim, which creates its networks with Starsim (see network.py). They return a dict of p1 and p2 arrays that can be used to make a layer, e.g. cv.Layer(**cv.make_random_contacts(pop_size, 10), label='random'). They use Covasim’s global random number generator, so call cv.set_seed() first for reproducible edges.

Functions

Name Description
make_hybrid_contacts Create “hybrid” contacts – microstructured contacts for households and
make_microstructured_contacts Create microstructured contacts – i.e. for households.
make_random_contacts Make random static contacts for a single layer as an edgelist.

make_hybrid_contacts

population.make_hybrid_contacts(
    pop_size,
    ages,
    contacts,
    school_ages=None,
    work_ages=None,
)

Create “hybrid” contacts – microstructured contacts for households and random contacts for schools and workplaces, both of which have extremely basic age structure. A combination of both make_random_contacts() and make_microstructured_contacts().

make_microstructured_contacts

population.make_microstructured_contacts(pop_size, cluster_size, mapping=None)

Create microstructured contacts – i.e. for households.

Parameters

Name Type Description Default
pop_size int total number of people required
cluster_size int the average size of each cluster (Poisson-sampled) required
mapping array optionally map the generated indices onto new indices None

New in version 3.1.1: optimized updated arguments.

make_random_contacts

population.make_random_contacts(
    pop_size,
    n,
    overshoot=1.2,
    dispersion=None,
    mapping=None,
)

Make random static contacts for a single layer as an edgelist.

Parameters

Name Type Description Default
pop_size (int) number of agents to create contacts between (N) required
n (int) the average number of contacts per person for this layer required
overshoot (float) to avoid needing to take multiple Poisson draws required
dispersion (float) if not None, use a negative binomial distribution with this dispersion parameter instead of Poisson to make the contacts required
mapping (array) optionally map the generated indices onto new indices required

Returns

Name Type Description
Dictionary of two arrays defining UIDs of the edgelist (sources and targets)

New in 3.1.1: optimized and updated arguments.