synthpops.sampling module¶
Sample distributions, either from real world data or from uniform distributions.
-
synthpops.sampling.
set_seed
(seed=None)¶ Reset the random seed – complicated because of Numba.
-
synthpops.sampling.
fast_choice
(weights)¶ Choose an option – quickly – from the provided weights. Weights do not need to be normalized.
Reimplementation of random.choices(), removing everything inessential.
Example
fast_choice([0.1,0.2,0.3,0.2,0.1]) # might return 2
-
synthpops.sampling.
sample_single_dict
(distr_keys, distr_vals)¶ Sample from a distribution.
- Parameters
distr (dict or np.ndarray) – distribution
- Returns
A single sampled value from a distribution.
-
synthpops.sampling.
sample_single_arr
(distr)¶ Sample from a distribution.
- Parameters
distr (dict or np.ndarray) – distribution
- Returns
A single sampled value from a distribution.
-
synthpops.sampling.
resample_age
(age_dist_vals, age)¶ Resample age from single year age distribution.
- Parameters
single_year_age_distr (arr) – age distribution, ordered by age
age (int) – age as an integer
- Returns
Resampled age as an integer.
-
synthpops.sampling.
sample_from_range
(distr, min_val, max_val)¶ Sample from a distribution from min_val to max_val, inclusive.
- Parameters
distr (dict) – distribution with integer keys
min_val (int) – minimum of the range to sample from
max_val (int) – maximum of the range to sample from
- Returns
A sampled number from the range min_val to max_val in the distribution distr.