synthpops.people.utils module

Default values and mathematical utilities

find_contacts[source]

Numba for Layer.find_contacts()

A set is returned here rather than a sorted array so that custom tracing interventions can efficiently add extra people. For a version with sorting by default, see Layer.find_contacts(). Indices must be an int64 array since this is what’s returned by true() etc. functions by default.

choose[source]

Choose a subset of items (e.g., people) without replacement.

Parameters:
  • max_n (int) – the total number of items
  • n (int) – the number of items to choose

Example:

choices = cv.choose(5, 2) # choose 2 out of 5 people with equal probability (without repeats)
choose_r[source]

Choose a subset of items (e.g., people), with replacement.

Parameters:
  • max_n (int) – the total number of items
  • n (int) – the number of items to choose

Example:

choices = cv.choose_r(5, 10) # choose 10 out of 5 people with equal probability (with repeats)
n_multinomial(probs, n)[source]

An array of multinomial trials.

Parameters:
  • probs (array) – probability of each outcome, which usually should sum to 1
  • n (int) – number of trials
Returns:

Array of integer outcomes

Example:

outcomes = cv.multinomial(np.ones(6)/6.0, 50)+1 # Return 50 die-rolls
poisson[source]

A Poisson trial.

Parameters:rate (float) – the rate of the Poisson process

Example:

outcome = cv.poisson(100) # Single Poisson trial with mean 100
n_poisson[source]

An array of Poisson trials.

Parameters:
  • rate (float) – the rate of the Poisson process (mean)
  • n (int) – number of trials

Example:

outcomes = cv.n_poisson(100, 20) # 20 Poisson trials with mean 100
n_neg_binomial(rate, dispersion, n, step=1)[source]

An array of negative binomial trials. See cv.sample() for more explanation.

Parameters:
  • rate (float) – the rate of the process (mean, same as Poisson)
  • dispersion (float) – dispersion parameter; lower is more dispersion, i.e. 0 = infinite, ∞ = Poisson
  • n (int) – number of trials
  • step (float) – the step size to use if non-integer outputs are desired

Example:

outcomes = cv.n_neg_binomial(100, 1, 50) # 50 negative binomial trials with mean 100 and dispersion roughly equal to mean (large-mean limit)
outcomes = cv.n_neg_binomial(1, 100, 20) # 20 negative binomial trials with mean 1 and dispersion still roughly equal to mean (approximately Poisson)