synthpops.base module¶
The module contains frequently-used functions that do not neatly fit into other areas of the code base.
-
synthpops.base.
norm_dic
(dic)¶ Normalize the dictionary
dic
.- Parameters
dic (dict) – A dictionary with numerical values.
- Returns
A normalized dictionary.
-
synthpops.base.
norm_age_group
(age_dic, age_min, age_max)¶ Create a normalized dictionary for the range
age_min
toage_max
, inclusive.- Parameters
age_dic (dict) – A dictionary with numerical values.
age_min (int) – The minimum value of the range for the dictionary.
age_max (int) – The maximum value of the range for the dictionary.
- Returns
A normalized dictionary for keys in the range
age_min
toage_max
, inclusive.
-
synthpops.base.
get_age_by_brackets_dic
(age_brackets)¶ Create a dictionary mapping age to the age bracket it falls in.
- Parameters
age_brackets (dict) – A dictionary mapping age bracket keys to age bracket range.
- Returns
A dictionary of age bracket by age.
Example
age_brackets = sp.get_census_age_brackets(sp.datadir,state_location='Washington',country_location='usa') age_by_brackets_dic = sp.get_age_by_brackets_dic(age_brackets)
-
synthpops.base.
get_aggregate_ages
(ages, age_by_brackets_dic)¶ Create a dictionary of the count of ages by age brackets.
- Parameters
ages (dict) – A dictionary of age count by single year.
age_by_brackets_dic (dict) – A dictionary mapping age to the age bracket range it falls within.
- Returns
A dictionary of aggregated age count for specified age brackets.
Example
aggregate_age_count = sp.get_aggregate_ages(age_count, age_by_brackets_dic) aggregate_matrix = symmetric_matrix.copy() aggregate_matrix = sp.get_aggregate_matrix(aggregate_matrix, age_by_brackets_dic)
-
synthpops.base.
get_aggregate_age_dict_conversion
(larger_aggregate_ages, larger_age_brackets, smaller_age_brackets, age_by_brackets_dic_larger, age_by_brackets_dic_smaller)¶ Convert the aggregate age count in
larger_aggregate_ages
from a larger number of age brackets to a smaller number of age brackets.- Parameters
larger_aggregate_ages (dict) – A dictionary of aggregated age count.
larger_age_brackets (dict) – A dictionary of age brackets.
smaller_age_brackets (dict) – A dictionary of fewer age brackets.
age_by_brackets_dic_larger (dict) – A dictionary mapping age to the larger number of age brackets.
age_by_brackets_dic_smaller (dict) – A dictionary mapping age to the smaller number of age brackets.
- Returns
A dictionary of the aggregated age count for the smaller number of age brackets.
-
synthpops.base.
get_aggregate_matrix
(M, age_by_brackets_dic)¶ Aggregate a symmetric matrix to fewer age brackets. Do not use for homogeneous mixing matrix.
- Parameters
M (np.ndarray) – A symmetric age contact matrix.
age_by_brackets_dic (dict) – A dictionary mapping age to the age bracket range it falls within.
- Returns
A symmetric contact matrix (
np.ndarray
) aggregated to age brackets.
Example
age_brackets = sp.get_census_age_brackets(sp.datadir,state_location='Washington',country_location='usa') age_by_brackets_dic = sp.get_age_by_brackets_dic(age_brackets) aggregate_age_count = sp.get_aggregate_ages(age_count, age_by_brackets_dic) aggregate_matrix = symmetric_matrix.copy() aggregate_matrix = sp.get_aggregate_matrix(aggregate_matrix, age_by_brackets_dic) asymmetric_matrix = sp.get_asymmetric_matrix(aggregate_matrix, aggregate_age_count)
-
synthpops.base.
get_asymmetric_matrix
(symmetric_matrix, aggregate_ages)¶ Get the contact matrix for the average individual in each age bracket.
- Parameters
symmetric_matrix (np.ndarray) – A symmetric age contact matrix.
aggregate_ages (dict) – A dictionary mapping single year ages to age brackets.
- Returns
A contact matrix (
np.ndarray
) whose elementsM_ij
describe the contact frequency for the average individual in age bracketi
with all possible contacts in age bracketj
.
Example
age_brackets = sp.get_census_age_brackets(sp.datadir,state_location='Washington',country_location='usa') age_by_brackets_dic = sp.get_age_by_brackets_dic(age_brackets) aggregate_age_count = sp.get_aggregate_ages(age_count, age_by_brackets_dic) aggregate_matrix = symmetric_matrix.copy() aggregate_matrix = sp.get_aggregate_matrix(aggregate_matrix, age_by_brackets_dic) asymmetric_matrix = sp.get_asymmetric_matrix(aggregate_matrix, aggregate_age_count)
-
synthpops.base.
get_symmetric_community_matrix
(ages)¶ Get a symmetric homogeneous matrix.
- Parameters
ages (dict) – A dictionary with the count of each single year age.
- Returns
A symmetric homogeneous matrix for age count in ages.
-
synthpops.base.
combine_matrices
(matrix_dic, weights_dic, num_agebrackets)¶ Combine different contact matrices into a single contact matrix.
- Parameters
matrix_dic (dict) – A dictionary of different contact matrices by setting.
weights_dic (dict) – A dictionary of weights for each setting.
num_agebrackets (int) – The number of age brackets for the different matrices.
- Returns
A contact matrix (
np.ndarray
) that is a linear combination of setting specific matrices given weights for each setting.
-
synthpops.base.
get_ids_by_age_dic
(age_by_id_dic)¶ Get lists of IDs that map to each age.
- Parameters
age_by_id_dic (dict) – A dictionary with the age of each individual by their ID.
- Returns
A dictionary listing IDs for each age from a dictionary that maps ID to age.
-
synthpops.base.
get_uids_by_age_dic
(popdict)¶ Get lists of UIDs that map to each age.
- Parameters
popdict (sc.dict) – A dictionary mapping an individual’s ID to a dictionary with their age and other attributes.
- Returns
A dictionary listing UIDs for each age.