Flu Core API Reference
Docstrings and references for flu_core
module.
base_path = clt.utils.PROJECT_ROOT / 'flu_instances' / 'texas_input_files'
module-attribute
AbsoluteHumidity
Bases: Schedule
Source code in CLT_BaseModel/flu_core/flu_components.py
__init__(init_val: Optional[np.ndarray | float] = None, timeseries_df: pd.DataFrame = None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_val
|
Optional[ndarray | float]
|
starting value(s) at the beginning of the simulation |
None
|
timeseries_df
|
Optional[pd.DataFrame] = None
|
must have columns "date" and "absolute_humidity" --
"date" entries must correspond to consecutive calendar days
and must either be strings with |
None
|
Source code in CLT_BaseModel/flu_core/flu_components.py
AsympToRecovered
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "IA" to "R" compartment. The functional form is the same across subpopulations.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
BetaReduce
Bases: DynamicVal
"Toy" function representing staged-alert policy that reduces transmission by 50% when more than 5% of the total population is infected. Note: the numbers are completely made up :) The "permanent_lockdown" toggle is to avoid "bang-bang" behavior where the staged-alert policy gets triggered one day and then is off the next, and then is on the day after, and so on... but as the name suggests, it IS permanent. TODO: replace with realistic function.
Source code in CLT_BaseModel/flu_core/flu_components.py
DailyVaccines
Bases: Schedule
Source code in CLT_BaseModel/flu_core/flu_components.py
__init__(init_val: Optional[np.ndarray | float] = None, timeseries_df: pd.DataFrame = None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init_val
|
Optional[ndarray | float]
|
starting value(s) at the beginning of the simulation |
None
|
timeseries_df
|
Optional[pd.DataFrame] = None
|
must have "date" and "daily_vaccines" -- "date" entries must
correspond to consecutive calendar days and must either
be strings with |
None
|
Source code in CLT_BaseModel/flu_core/flu_components.py
ExposedToAsymp
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "E" to "IA" compartment. The functional form is the same across subpopulations.
Each ExposedToAsymp instance forms a TransitionVariableGroup with a corresponding ExposedToPresymp instance (these two transition variables are jointly distributed).
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
ExposedToPresymp
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "E" to "IP" compartment. The functional form is the same across subpopulations.
Each ExposedToPresymp instance forms a TransitionVariableGroup with a corresponding ExposedToAsymp instance (these two transition variables are jointly distributed).
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
FluContactMatrix
Bases: Schedule
Flu contact matrix.
Attributes:
Name | Type | Description |
---|---|---|
timeseries_df |
DataFrame
|
must have columns "date", "is_school_day", and "is_work_day"
-- "date" entries must correspond to consecutive calendar
days and must either be strings with |
See parent class docstring for other attributes.
Source code in CLT_BaseModel/flu_core/flu_components.py
FluFullMetapopParamsTensors
dataclass
Bases: FluTravelParamsTensors
Data container for tensors for FluMetapopModel
-- used to store arrays that
contain data across all subpopulations (collected from parameters
on each location/subpopulation model, as well as from the
metapopulation's associated FluMixingParams
instance).
Note that in contrast to FluTravelParamsTensors
,
ALL fields in FluSubpopParams
are included --
this is for running the simulation via torch.
Attributes:
Name | Type | Description |
---|---|---|
num_locations |
(Tensor, 0 - dimensional)
|
number of locations (subpopulations) in the metapopulation model and therefore the travel model. |
travel_proportions |
Tensor
|
L x L array, where L is the number of locations or subpopulations, where element i,j corresponds to the proportion of the population in location i who travels to location j (on average). |
See FluSubpopParams
docstring for other attributes.
Other fields are analogous except they are size (L, A, R)
tensors or size 0 tensors.
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluFullMetapopScheduleTensors
dataclass
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluFullMetapopStateTensors
dataclass
Bases: FluTravelStateTensors
Data container for tensors for FluMetapopModel
-- used to store arrays that
contain data across all subpopulations (collected from each
location/subpopulation model). In contrast to FluTravelStateTensors
,
ALL fields in FluSubpopState
are included -- this is
for running the simulation via torch.
Attributes:
Name | Type | Description |
---|---|---|
flu_contact_matrix |
torch.Tensor of nonnegative integers
|
contact matrix for location-age-risk groups -- the
lth element holds current_val of |
init_vals |
dict
|
dictionary of torch.Tensor instances, where keys correspond to "IP", "IS", "IA", and "H", and values correspond to their initial values for location-age-risk groups. |
See FluSubpopState
and FluTravelStateTensors
for other
attributes -- other attributes here correspond to
FluSubpopState
, but are size (L, A, R) tensors for
location-age-risk or size 0 tensors.
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluMetapopModel
Bases: MetapopModel
, ABC
MetapopModel-derived class specific to flu model.
Source code in CLT_BaseModel/flu_core/flu_components.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
|
apply_inter_subpop_updates() -> None
Update the FluTravelStateTensors
according to the simulation state
and compute the total mixing exposure, which includes across-subpopulation
mixing/travel. Update the total_mixing_exposure
attribute on each
subpopulation's SusceptibleToExposed
instance accordingly, so each
of these transition variables can compute its transition rate.
See apply_inter_subpop_updates
on MetapopModel
base class
for logic of how/when this is called in the simulation.
Source code in CLT_BaseModel/flu_core/flu_components.py
compute_total_pop_LAR_tensor() -> torch.tensor
For each subpopulation, sum initial values of population in each compartment for age-risk groups. Store all information as tensor and return tensor.
Returns:
torch.tensor of size (L, A, R): Total population (across all compartments) for location-age-risk (l, a, r).
Source code in CLT_BaseModel/flu_core/flu_components.py
get_flu_torch_inputs() -> dict
Prepares and returns metapopulation simulation data in tensor format
that can be directly used for torch
implementation.
Returns:
Name | Type | Description |
---|---|---|
d |
dict
|
Has keys "state_tensors", "params_tensors", "schedule_tensors",
and "precomputed". Corresponds to |
Source code in CLT_BaseModel/flu_core/flu_components.py
modify_mixing_params(updates_dict: dict)
This method lets users safely modify flu mixing parameters;
the metapopulation-wide tensors are updated automatically afterward.
FluMixingParams
is a frozen dataclass to avoid users
naively changing parameter values and getting undesirable results --
thus, FluMixingParams
cannot be updated directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
updates_dict
|
dict
|
Dictionary specifying values to update in a
|
required |
Source code in CLT_BaseModel/flu_core/flu_components.py
modify_subpop_params(subpop_name: str, updates_dict: dict)
This method lets users safely modify a single subpopulation parameters field; the metapopulation-wide tensors are updated automatically afterward.
In a FluMetapopModel
, subpopulation parameters are combined into
(L, A, R) tensors across L subpopulations.FluSubpopParams
is a frozen
dataclass to avoid users naively changing parameter values and getting
undesirable results -- thus, FluSubpopParams
on a subpopulation
model cannot be updated directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subpop_name
|
str
|
Value must match the |
required |
updates_dict
|
dict
|
Dictionary specifying values to update in a
|
required |
Source code in CLT_BaseModel/flu_core/flu_components.py
setup_full_metapop_schedule_tensors()
Creates FluFullMetapopScheduleTensors
instance and assigns to
_full_metapop_schedule_tensors
attribute.
For the metapopulation model's L locations/subpopulations, for each day, each value-related column in each schedule is either a float or array of size (A, R) for age-risk groups.
We aggregate and reformat this schedule information and put it
into a FluFullMetapopScheduleTensors
instance, where fields
correspond to a schedule value, and values are lists of tensors of
size (L, A, R). The ith element of each list corresponds to the
ith simulation day.
Source code in CLT_BaseModel/flu_core/flu_components.py
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
|
update_full_metapop_params_tensors() -> None
Update _full_metapop_params_tensors
attribute in-place.
FluFullMetapopParamsTensors
has fields corresponding
to all parameters in the simulation. Converts subpopulation-specific
parameters to tensors of size (L, A, R) for location-age-risk
(except for a few exceptions that have different dimensions).
Source code in CLT_BaseModel/flu_core/flu_components.py
update_full_metapop_state_tensors() -> None
Update _full_metapop_state_tensors
attribute in-place.
FluFullMetapopStateTensors
has fields corresponding
to all state variables in the simulation.
Converts subpopulation-specific state to
tensors of size (L, A, R) for location-age-risk
(except for a few exceptions that have different dimensions).
Source code in CLT_BaseModel/flu_core/flu_components.py
update_params_tensors(target: FluTravelParamsTensors) -> FluTravelParamsTensors
Update target
in-place. Converts subpopulation-specific
parameters to tensors of size (L, A, R) for location-age-risk,
except for num_locations
and travel_proportions
, which
have size 1 and (L, L) respectively.
Source code in CLT_BaseModel/flu_core/flu_components.py
update_state_tensors(target: FluTravelStateTensors) -> None
Update target
instance in-place with current simulation
values. Each field of target
corresponds to a field in
FluSubpopState
, and contains either a tensor of size
(L, A, R) or a tensor of size (L), where (l, a, r) refers to
location-age-risk.
Source code in CLT_BaseModel/flu_core/flu_components.py
update_travel_params_tensors() -> None
Update travel_params_tensors
attribute in-place.
FluTravelParamsTensors
only has fields corresponding
to parameters relevant for the travel model.
Converts subpopulation-specific parameters to
tensors of size (L, A, R) for location-age-risk
(except for a few exceptions that have different dimensions).
Source code in CLT_BaseModel/flu_core/flu_components.py
update_travel_state_tensors() -> None
Update travel_state_tensors
attribute in-place.
FluTravelStateTensors
only has fields corresponding
to state variables relevant for the travel model.
Converts subpopulation-specific state to
tensors of size (L, A, R) for location-age-risk
(except for a few exceptions that have different dimensions).
Source code in CLT_BaseModel/flu_core/flu_components.py
FluMetapopModelError
FluMixingParams
dataclass
Contains parameters corresponding to inter-subpopulation (metapopulation model) specifications: the number of subpopulations included, and the travel proportions between them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_locations
|
int
|
Number of locations (subpopulations) in the metapopulation model. |
required |
travel_proportions
|
np.ndarray of shape (A, R
|
L x L array of floats in [0,1], where L is the number of locations (subpopulations), and the i-jth element is the proportion of people in subpopulation i that travel to subpopulation j. |
required |
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluPrecomputedTensors
Stores precomputed quantities that are repeatedly used, for computational efficiency.
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluSubpopModel
Bases: SubpopModel
Class for creating ImmunoSEIRS flu model with predetermined fixed
structure -- initial values and epidemiological structure are
populated by user-specified JSON
files.
Key method create_transmission_model returns a SubpopModel
instance with S-E-I-H-R-D compartments and M
and MV epi metrics.
The update structure is as follows
- S <- S + R_to_S - S_to_E
- E <- E + S_to_E - E_to_IP - E_to_IA
- IA <- IA + E_to_IA - IA_to_R
- IP <- IP + E_to_IP - IP_to_IS
- IS <- IS + IP_to_IS - IS_to_R - IS_to_H
- H <- H + IS_to_H - H_to_R - H_to_D
- R <- R + IS_to_R + H_to_R - R_to_S
- D <- D + H_to_D
The following are TransitionVariable instances
- R_to_S is a RecoveredToSusceptible instance
- S_to_E is a SusceptibleToExposed instance
- IP_to_IS is a PresympToSymp instance
- IS_to_H is a SympToHosp instance
- IS_to_R is a SympToRecovered instance
- H_to_R is a HospToRecovered instance
- H_to_D is a HospToDead instance
There are three TransitionVariableGroups
- E_out (handles E_to_IP and E_to_IA)
- IS_out (handles IS_to_H and IS_to_R)
- H_out (handles H_to_R and H_to_D)
The following are EpiMetric instances
- M is a InfInducedImmunity instance
- MV is a VaxInducedImmunity instance
Transition rates and update formulas are specified in corresponding classes.
See parent class SubpopModel
's docstring for additional attributes.
Source code in CLT_BaseModel/flu_core/flu_components.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
|
__init__(state: FluSubpopState, params: FluSubpopParams, simulation_settings: FluSubpopSchedules, RNG: np.random.Generator, schedules_spec: FluSubpopSchedules, name: str)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
FluSubpopState
|
holds current simulation state information, such as current values of epidemiological compartments and epi metrics. |
required |
params
|
FluSubpopParams
|
holds epidemiological parameter values. |
required |
simulation_settings
|
SimulationSettings
|
holds simulation settings. |
required |
RNG
|
Generator
|
numpy random generator object used to obtain random numbers. |
required |
schedules_spec
|
FluSubpopSchedules
|
holds dataframes that specify |
required |
name
|
str
|
unique name of MetapopModel instance. |
required |
Source code in CLT_BaseModel/flu_core/flu_components.py
create_dynamic_vals() -> sc.objdict[str, clt.DynamicVal]
Create all DynamicVal
instances, save in sc.objdict
, and return objdict
Source code in CLT_BaseModel/flu_core/flu_components.py
create_epi_metrics() -> sc.objdict[str, clt.EpiMetric]
Create all epi metric described in docstring (2 state
variables total), save in sc.objdict
, and return objdict
Source code in CLT_BaseModel/flu_core/flu_components.py
create_schedules() -> sc.objdict[str, clt.Schedule]
Create all Schedule
instances, save in sc.objdict
, and return objdict
Source code in CLT_BaseModel/flu_core/flu_components.py
create_transition_variable_groups() -> sc.objdict[str, clt.TransitionVariableGroup]
Create all transition variable groups described in docstring (2 transition
variable groups total), save in sc.objdict
, return objdict
Source code in CLT_BaseModel/flu_core/flu_components.py
create_transition_variables() -> sc.objdict[str, clt.TransitionVariable]
Create all TransitionVariable
instances,
save in sc.objdict
, and return objdict
Source code in CLT_BaseModel/flu_core/flu_components.py
modify_subpop_params(updates_dict: dict)
This method lets users safely modify a single subpopulation
parameters field; if this subpop model is associated with
a metapop model, the metapopulation-wide tensors are updated
automatically afterward. See also modify_subpop_params
method on
FluMetapopModel
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
updates_dict
|
dict
|
Dictionary specifying values to update in a
|
required |
Source code in CLT_BaseModel/flu_core/flu_components.py
FluSubpopModelError
FluSubpopParams
dataclass
Bases: SubpopParams
Data container for pre-specified and fixed epidemiological
parameters in FluSubpopModel
.
Each field of datatype np.ndarray must be A x R, where A is the number of age groups and R is the number of risk groups. Note: this means all arrays should be 2D. See FluSubpopState docstring for important formatting note on 2D arrays.
Note: the user does not have to specify total_pop_age_risk
--
this is automatically computed when a FluSubpopModel
is
instantiated. This is to ensure that the total population
(summed across all compartments) actually equals total_pop_age_risk
--
and the user doesn't change one without updating the other.
Attributes:
Name | Type | Description |
---|---|---|
num_age_groups |
positive int
|
number of age groups. |
num_risk_groups |
positive int
|
number of risk groups. |
beta_baseline |
positive float
|
transmission rate. |
total_pop_age_risk |
np.ndarray of positive ints
|
total number in population, summed across all age-risk groups. |
humidity_impact |
positive float
|
coefficient that determines how much absolute humidity affects beta_baseline. |
inf_induced_saturation |
np.ndarray of positive floats
|
constant(s) modeling saturation of antibody production of infected individuals. |
inf_induced_immune_wane |
positive float
|
rate at which infection-induced immunity against infection wanes. |
vax_induced_saturation |
np.ndarray of positive floats
|
constant(s) modeling saturation of antibody production of vaccinated individuals. |
vax_induced_immune_wane |
positive float
|
rate at which vaccine-induced immunity against infection wanes. |
inf_induced_inf_risk_reduce |
positive float
|
reduction in risk of getting infected after getting infected |
inf_induced_hosp_risk_reduce |
positive float
|
reduction in risk of hospitalization after getting infected |
inf_induced_death_risk_reduce |
positive float
|
reduction in risk of death after getting infected |
vax_induced_inf_risk_reduce |
positive float
|
reduction in risk of getting infected after getting vaccinated |
vax_induced_hosp_risk_reduce |
positive float
|
reduction in risk of hospitalization after getting vaccinated |
vax_induced_death_risk_reduce |
positive float
|
reduction in risk of death after getting vaccinated |
R_to_S_rate |
positive float
|
rate at which people in R move to S. |
E_to_I_rate |
positive float
|
rate at which people in E move to I (both IP and IA, infected pre-symptomatic and infected asymptomatic) |
IP_to_IS_rate |
positive float
|
rate a which people in IP (infected pre-symptomatic) move to IS (infected symptomatic) |
IS_to_R_rate |
positive float
|
rate at which people in IS (infected symptomatic) move to R. |
IA_to_R_rate |
positive float
|
rate at which people in IA (infected asymptomatic) move to R |
IS_to_H_rate |
positive float
|
rate at which people in IS (infected symptomatic) move to H. |
H_to_R_rate |
positive float
|
rate at which people in H move to R. |
H_to_D_rate |
positive float
|
rate at which people in H move to D. |
E_to_IA_prop |
np.ndarray of positive floats in [0,1]
|
proportion exposed who are asymptomatic based on age-risk groups. |
IS_to_H_adjusted_prop |
np.ndarray of positive floats in [0,1]
|
rate-adjusted proportion infected who are hospitalized based on age-risk groups. |
H_to_D_adjusted_prop |
np.ndarray of positive floats in [0,1]
|
rate-adjusted proportion hospitalized who die based on age-risk groups. |
IP_relative_inf |
positive float
|
relative infectiousness of pre-symptomatic to symptomatic people (IP to IS compartment). |
IA_relative_inf |
positive float
|
relative infectiousness of asymptomatic to symptomatic people (IA to IS compartment). |
relative_suscept |
np.ndarray of positive floats in [0,1]
|
relative susceptibility to infection by age group |
mobility_modifier |
np.ndarray of positive floats in [0,1]
|
total proportion of time spent away from home by age group |
total_contact_matrix |
np.ndarray of positive floats
|
A x A contact matrix (where A is the number of age groups), where element i,j is the average contacts from age group j that an individual in age group i has |
school_contact_matrix |
np.ndarray of positive floats
|
A x A contact matrix (where A is the number of age groups), where element i,j is the average contacts from age group j that an individual in age group i has at school -- this matrix plus the work_contact_matrix must be less than the total_contact_matrix, element-wise |
work_contact_matrix |
np.ndarray of positive floats
|
A x A contact matrix (where A is the number of age groups), where element i,j is the average contacts from age group j that an individual in age group i has at work -- this matrix plus the work_contact_matrix must be less than the total_contact_matrix, element-wise |
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
FluSubpopSchedules
dataclass
Data container for dataframes used to specify schedules
for each FluSubpopModel
instance.
THE FORMAT FOR EACH DATAFRAME IS VERY IMPORTANT -- please read and implement carefully.
Attributes:
Name | Type | Description |
---|---|---|
absolute_humidity |
DataFrame
|
must have columns "date" and "absolute_humidity" --
"date" entries must correspond to consecutive calendar days
and must either be strings with |
flu_contact_matrix |
DataFrame
|
must have columns "date", "is_school_day", and "is_work_day"
-- "date" entries must correspond to consecutive calendar
days and must either be strings with |
daily_vaccines |
DataFrame
|
must have "date" and "daily_vaccines" -- "date" entries must
correspond to consecutive calendar days and must either
be strings with |
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluSubpopState
dataclass
Bases: SubpopState
Data container for pre-specified and fixed set of
Compartment initial values and EpiMetric initial values
for FluSubpopModel
.
Each field below should be A x R np.ndarray, where A is the number of age groups and R is the number of risk groups. Note: this means all arrays should be 2D. Even if there is 1 age group and 1 risk group (no group stratification), each array should be 1x1, which is two-dimensional. For example, np.array([[100]]) is correct -- np.array([100]) is wrong.
Attributes:
Name | Type | Description |
---|---|---|
S |
np.ndarray of nonnegative integers
|
susceptible compartment for age-risk groups -- (holds current_val of Compartment "S"). |
E |
np.ndarray of nonnegative integers
|
exposed compartment for age-risk groups -- (holds current_val of Compartment "E"). |
IP |
np.ndarray of nonnegative integers
|
infected pre-symptomatic compartment for age-risk groups (holds current_val of Compartment "IP"). |
IS |
np.ndarray of nonnegative integers
|
infected symptomatic compartment for age-risk groups (holds current_val of Compartment "IS"). |
IA |
np.ndarray of nonnegative integers
|
infected asymptomatic compartment for age-risk groups (holds current_val of Compartment "IA"). |
H |
np.ndarray of nonnegative integers
|
hospital compartment for age-risk groups (holds current_val of Compartment "H"). |
R |
np.ndarray of nonnegative integers
|
recovered compartment for age-risk groups (holds current_val of Compartment "R"). |
D |
np.ndarray of nonnegative integers
|
dead compartment for age-risk groups (holds current_val of Compartment "D"). |
M |
np.ndarray of nonnegative floats
|
infection-induced population-level immunity for age-risk groups (holds current_val of EpiMetric "M"). |
MV |
np.ndarray of nonnegative floats
|
vaccine-induced population-level immunity for age-risk groups (holds current_val of EpiMetric "MV"). |
absolute_humidity |
positive float
|
grams of water vapor per cubic meter g/m^3, used as seasonality parameter that influences transmission rate beta_baseline. |
flu_contact_matrix |
np.ndarray of positive floats
|
A x A array, where A is the number of age groups -- element (a, a') corresponds to the number of contacts that a person in age group a has with people in age-risk group a'. |
beta_reduce |
float in [0, 1]
|
starting value of DynamicVal "beta_reduce" on starting day of simulation -- this DynamicVal emulates a simple staged-alert policy |
daily_vaccines |
np.ndarray of positive ints
|
holds current value of DailyVaccines instance, corresponding number of individuals who received influenza vaccine on that day, for given age-risk group (generally derived from historical data) |
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluTravelParamsTensors
dataclass
Data container for tensors for FluMetapopModel
-- used to store arrays
that contain data across all subpopulations (collected from parameters
on each location/subpopulation model, as well as from the
metapopulation's associated FluMixingParams
instance).
Note that not all fields in FluSubpopParams
are included
-- we only include parameters needed for the travel model
computation, for efficiency.
Attributes:
Name | Type | Description |
---|---|---|
num_locations |
(Tensor, 0 - dimensional)
|
number of locations (subpopulations) in the metapopulation model and therefore the travel model. |
travel_proportions |
Tensor
|
L x L array, where L is the number of locations or subpopulations, where element i,j corresponds to the proportion of the population in location i who travels to location j (on average). |
See FluSubpopParams
docstring for other attributes.
Fields are analogous -- but (most) are size (L, A, R) for
location-age-risk or size 0 tensors. Exceptions are
travel_proportions
, which is size (L, L),
and any of the contact matrices, which are size (L, A, A).
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
standardize_shapes() -> None
If field is size (L, A, R) for location-age-risk or size 0 tensors, or is not a special variable listed below, then apply dimension expansion so that fields are size (L, A, R) tensors for tensor multiplication.
Exceptions are travel_proportions
, which is size (L, L),
and any of the contact matrices, which are size (L, A, A).
Not all dimension combinations are considered not all make sense -- we assume that we only have risk IF we have age, for example.
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
FluTravelStateTensors
dataclass
Data container for tensors for FluMetapopModel
-- used to store arrays
that contain data across all subpopulations (collected from each
location/subpopulation model). Note that not all fields in
FluSubpopState
are included -- we only include compartments
needed for the travel model computation, for efficiency.
Attributes:
Name | Type | Description |
---|---|---|
IP |
torch.Tensor of nonnegative integers
|
presymptomatic infected compartment for location-age-risk
groups -- the lth element holds current_val of
Compartment "IP" on the lth location / subpopulation
on the associated |
IS |
torch.Tensor of nonnegative integers
|
symptomatic infected compartment for location-age-risk
groups -- the lth element holds current_val of
Compartment "IS" on the lth location / subpopulation
on the associated |
IA |
torch.Tensor of nonnegative integers
|
asymptomatic infected compartment for location-age-risk
groups -- the lth element holds current_val of
Compartment "IA" on the lth location / subpopulation
on the associated |
H |
torch.Tensor of nonnegative integers
|
hospital compartment for location-age-risk
groups -- the lth element holds current_val of
Compartment "H" on the lth location / subpopulation
on the associated |
flu_contact_matrix |
torch.Tensor of nonnegative integers
|
contact matrix for location-age-risk groups -- the
lth element holds current_val of |
init_vals |
dict
|
dictionary of torch.Tensor instances, where keys correspond to "IP", "IS", "IA", and "H", and values correspond to their initial values for location-age-risk groups. |
Source code in CLT_BaseModel/flu_core/flu_data_structures.py
HospToDead
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "H" to "D" compartment. The functional form is the same across subpopulations.
Each HospToDead instance forms a TransitionVariableGroup with a corresponding HospToRecovered instance (these two transition variables are jointly distributed).
The rate of HospToDead decreases as population-level immunity against hospitalization increases.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
HospToRecovered
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "H" to "R" compartment. The functional form is the same across subpopulations.
Each HospToRecovered instance forms a TransitionVariableGroup with a corresponding HospToDead instance (these two transition variables are jointly distributed).
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
InfInducedImmunity
Bases: EpiMetric
EpiMetric-derived class for infection-induced population-level immunity.
Population-level immunity increases as people move from "R" to "S" -- this is a design choice intended to avoid "double-counting." People in "R" cannot be infected at all. People who move from "R" to "S" are susceptible again, but these recently-recovered people should have partial immunity. To handle this phenomenon, this epi metric increases as people move from "R" to "S."
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R_to_S
|
RecoveredToSusceptible
|
RecoveredToSusceptible TransitionVariable in the SubpopModel -- it is an attribute because the population-level immunity increases as people move from "R" to "S". |
required |
See parent class docstring for other attributes.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_change_in_current_val(state: FluSubpopState, params: FluSubpopParams, num_timesteps: int) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
PresympToSymp
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "IP" to "IS" compartment. The functional form is the same across subpopulations.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
RecoveredToSusceptible
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "R" to "S" compartment. The functional form is the same across subpopulations.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
SusceptibleToExposed
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "S" to "E" compartment. The functional form is the same across subpopulations.
The rate depends on the corresponding subpopulation's contact matrix, transmission rate beta, number infected (symptomatic, asymptomatic, and pre-symptomatic), and population-level immunity against infection, among other parameters.
This is the most complicated transition variable in the
flu model. If using metapopulation model (travel model), then
the rate depends on the total_mixing_exposure
attribute,
which is a function of other subpopulations' states and
parameters, and travel between subpopulations.
If there is no metapopulation model, the rate is much simpler.
Attributes:
Name | Type | Description |
---|---|---|
total_mixing_exposure |
np.ndarray of positive floats
|
weighted infectious count (exposure) from movement within home location, travel to other locations, and visitors from other locations |
See parent class docstring for other attributes.
Source code in CLT_BaseModel/flu_core/flu_components.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
SympToHosp
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "IS" to "H" compartment. The functional form is the same across subpopulations.
Each SympToHosp instance forms a TransitionVariableGroup with a corresponding SympToRecovered instance (these two transition variables are jointly distributed).
The rate of SympToHosp decreases as population-level immunity against hospitalization increases.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
SympToRecovered
Bases: TransitionVariable
TransitionVariable-derived class for movement from the "IS" to "R" compartment. The functional form is the same across subpopulations.
Each SympToRecovered instance forms a TransitionVariableGroup with a corresponding SympToHosp instance (these two transition variables are jointly distributed).
Source code in CLT_BaseModel/flu_core/flu_components.py
get_current_rate(state: FluSubpopState, params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
VaxInducedImmunity
Bases: EpiMetric
EpiMetric-derived class for vaccine-induced population-level immunity.
Source code in CLT_BaseModel/flu_core/flu_components.py
get_change_in_current_val(state: FluSubpopState, params: FluSubpopParams, num_timesteps: int) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
accept_reject_admits(metapop_model: FluMetapopModel, sampling_RNG: np.random.Generator, sampling_info: dict[str, dict[str, clt.UniformSamplingSpec]], total_daily_target_admits: list[np.ndarray], num_days: int = 50, target_accepted_reps: int = int(100.0), max_reps: int = int(1000.0), early_stop_percent: float = 0.5, target_rsquared: float = 0.75)
Accept-reject sampler for a metapopulation model.
This function repeatedly samples parameters from uniform distributions
(as specified in spec
) and simulates the model until the R-squared between
simulated total admits and reference data exceeds target_rsquared
.
Accepted parameter sets and simulation states are saved as JSON files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metapop_model
|
FluMetapopModel
|
The metapopulation model to simulate and sample parameters for. |
required |
sampling_RNG
|
Generator
|
Random number generator used for uniform sampling. |
required |
sampling_info
|
dict[str, dict[str, UniformSamplingSpec]]
|
See |
required |
total_daily_target_admits
|
list[ndarray]
|
"Target" time series of total admits (across subpopulations)
for computing R-squared -- we would like parameters and
sample paths that give simulated admits close to
|
required |
num_days
|
int, default=50
|
Total number of days to simulate for accepted parameter sets. |
50
|
target_accepted_reps
|
int, default=100
|
Target number of accepted parameter sets (replicates) to collect. |
int(100.0)
|
max_reps
|
int, default=1000
|
Maximum number of sampling attempts before stopping. |
int(1000.0)
|
early_stop_percent
|
float, default=0.5
|
Fraction of |
0.5
|
target_rsquared
|
float, default=0.75
|
Minimum R-squared required between simulated and reference admits for acceptance. |
0.75
|
Notes:
- Early stopping is performed at num_days * early_stop_percent
to
quickly reject poor parameter samples.
- Accepted samples (and the state of the simulation at day
num_days
) are saved to JSON files per subpopulation.
Note that for efficiency, NOT ALL PARAMETERS ARE SAVED!
Only the parameters that are randomly sampled (and thus are
different between replications).
- Running this function can be slow -- test this function with a small
number of replications or simulation days to start.
Source code in CLT_BaseModel/flu_core/flu_accept_reject.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
advance_timestep(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, dt: float, save_calibration_targets: bool = False, save_tvar_history: bool = False) -> Tuple[FluFullMetapopStateTensors, dict, dict]
Advance the simulation one timestep, with length dt
.
Updates state corresponding to compartments and
epidemiological metrics after computing transition variables
and metric changes.
Note that in this torch "mean" deterministic implementation...
- We compute rates in the same way as the
get_binom_deterministic_no_round
transition type in the OOP code -- see
TransitionVariables
class in
clt_toolkit / base_components
for more details.
- We also implement a "mean" deterministic analog
of the multinomial distribution to handle
multiple outflows from the same compartment
- We do not round the transition variables
- We also use softplus
, a smooth approximation to the
ReLU function, to ensure that compartments are
nonnegative (which is not guaranteed using
the mean of a binomial/multinomial random variable
rather than sampling from those distributions).
Returns:
Type | Description |
---|---|
Tuple[FluFullMetapopStateTensors, dict, dict]
|
New |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
|
compute_E_to_IA_rate(params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
compute_E_to_IP_rate(params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
compute_H_to_D_rate(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_H_to_R_rate(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_IA_to_R(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_IP_to_IS(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_IS_to_H_rate(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_IS_to_R_rate(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_MV_change(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_M_change(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_R_to_S(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_S_to_E(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, dt: float) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_active_pop_LAR(state: FluTravelStateTensors, _params: FluTravelParamsTensors, precomputed: FluPrecomputedTensors) -> torch.Tensor
Compute the active population for location-age-risk (l, a, r) as a tensor. Used to compute the effective population in the travel model, which is the population size adjusted for incoming visitors, residents traveling, and assuming hospitalized individuals are not mobile enough to infect others.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (L, A, R): Active population: those who are not hospitalized (i.e. those who are not too sick to move and travel regularly) |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_beta_adjusted(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors) -> torch.Tensor
Computes beta-adjusted humidity.
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, R)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_effective_pop_LA(state: FluTravelStateTensors, params: FluTravelParamsTensors, precomputed: FluPrecomputedTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (L, A):
Effective population, summed over risk groups.
See |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_flu_contact_matrix(params: FluFullMetapopParamsTensors, schedules: FluFullMetapopScheduleTensors, day_counter: int) -> torch.Tensor
Computes flu model contact matrix in tensor format -- makes adjustments based on whether day is school day or work day.
Returns:
Type | Description |
---|---|
Tensor
|
(torch.Tensor of size (L, A, A)) |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
compute_local_to_local_exposure(flu_contact_matrix: torch.Tensor, mobility_modifier: torch.Tensor, sum_residents_nonlocal_travel_prop: torch.Tensor, wtd_infectious_ratio_LLA: torch.Tensor, location_ix: int) -> torch.Tensor
Raw means that this is unnormalized by relative_suscept
.
Excludes beta and population-level immunity adjustments --
those are factored in later.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (A):
For a given location (specified by |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_outside_visitors_exposure(flu_contact_matrix: torch.Tensor, mobility_modifier: torch.Tensor, travel_proportions: torch.Tensor, wtd_infectious_ratio_LLA: torch.Tensor, local_ix: int, visitors_ix: int) -> torch.Tensor
Computes raw (unnormalized by relative_suscept
) transmission
to local_ix
due to outside visitors from visitors_ix
.
Excludes beta and population-level immunity adjustments --
those are factored in later.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (A) |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_pop_by_age(subpop_params: FluSubpopParams) -> np.ndarray
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A x 1 array -- where A is the number of age groups -- where ith element corresponds to total population (across all compartments, including "D", and across all risk groups) in age group i |
Source code in CLT_BaseModel/flu_core/flu_components.py
compute_residents_traveling_exposure(flu_contact_matrix: torch.Tensor, mobility_modifier: torch.Tensor, travel_proportions: torch.Tensor, wtd_infectious_ratio_LLA: torch.Tensor, local_ix: int, dest_ix: int) -> torch.Tensor
Computes raw (unnormalized by relative_suscept
) transmission
to local_ix
, due to residents of local_ix
traveling to dest_ix
and getting infected in dest_ix
. Excludes beta and population-level
immunity adjustments -- those are factored in later.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (A) |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_rsquared(reference_timeseries: list[np.ndarray], simulated_timeseries: list[np.ndarray]) -> float
Source code in CLT_BaseModel/flu_core/flu_accept_reject.py
compute_total_mixing_exposure(state: FluTravelStateTensors, params: FluTravelParamsTensors, precomputed: FluPrecomputedTensors) -> torch.Tensor
Computes "total mixing exposure" for location-age-risk
(l, a, r) -- the rate of exposure to infectious individuals,
accounting for both local transmission, incoming visitors, and
residents traveling. Normalized by relative_suscept
!
Combines subroutines compute_local_to_local_exposure()
,
compute_outside_visitors_exposure()
, and compute_residents_traveling_exposure()
.
Note that these subroutines do not include relative susceptibility --
but this function includes relative susceptibility -- this is to avoid
unnecessary repeated multiplication by relative susceptible in each subroutine.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (L, A, R) |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_wtd_infectious_LA(state: FluTravelStateTensors, params: FluTravelParamsTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (L, A): Weighted infectious, summed over risk groups: includes presymptomatic, asymptomatic, and symptomatic, weighted by relative infectiousness |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_wtd_infectious_ratio_LLA(state: FluTravelStateTensors, params: FluTravelParamsTensors, precomputed: FluPrecomputedTensors) -> torch.Tensor
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor of size (L, L, A): Element i,j,a corresponds to ratio of weighted infectious people in location i, age group a (summed over risk groups) to the effective population in location j (summed over risk groups) |
Source code in CLT_BaseModel/flu_core/flu_travel_functions.py
compute_wtd_presymp_asymp_by_age(subpop_state: FluSubpopState, subpop_params: FluSubpopParams) -> np.ndarray
Returns weighted sum of IP and IA compartment for subpopulation with given state and parameters. IP and IA are weighted by their relative infectiousness respectively, and then summed over risk groups.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray of shape (A, R) |
Source code in CLT_BaseModel/flu_core/flu_components.py
create_dict_of_tensors(d: dict, requires_grad: bool = True) -> dict
Converts dictionary entries to tensor
(of type torch.float32
)
and if requires_grad
is True
, turns on gradient tracking for
each entry -- returns new dictionary.
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
torch_approx_binom_probability_from_rate(rate, dt)
Torch-compatible implementation of converting a
rate into a probability. See analogous numpy implementation
base_components/approx_binom_probability_from_rate()
docstring
for details.
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
torch_simulate_full_history(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, schedules: FluFullMetapopScheduleTensors, num_days: int, timesteps_per_day: int) -> Tuple[dict, dict]
Simulates the flu model with a differentiable torch implementation
that carries out binom_deterministic_no_round
transition types --
returns hospital admits for calibration use.
See subroutine advance_timestep
for additional details.
Returns:
Type | Description |
---|---|
Tuple[dict, dict]
|
Returns hospital admits (the IS to H transition variable value) for day, location, age, risk, in tensor format. |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
torch_simulate_hospital_admits(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, precomputed: FluPrecomputedTensors, schedules: FluFullMetapopScheduleTensors, num_days: int, timesteps_per_day: int) -> torch.Tensor
Analogous to torch_simulate_full_history
but only saves and
returns hospital admits for calibration use.
Returns:
Type | Description |
---|---|
torch.Tensor of size (num_days, L, A, R)
|
Returns hospital admits (the IS to H transition variable value) for day, location, age, risk, in tensor format. |
Source code in CLT_BaseModel/flu_core/flu_torch_det_components.py
update_state_with_schedules(state: FluFullMetapopStateTensors, params: FluFullMetapopParamsTensors, schedules: FluFullMetapopScheduleTensors, day_counter: int) -> FluFullMetapopStateTensors
Returns new dataclass formed by copying the current state
and updating specific values according to schedules
and
the simulation's current day_counter
.
Returns:
Type | Description |
---|---|
FluFullMetapopStateTensors
|
New state with updated schedule-related values:
- |