Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully rename parameters and decide hospitalization when symptoms appear #83

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/usage/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Data is either written as an ``int`` or a ``real``.

- Real data:

- ``incubation_period``: (currently misleadingly named) Latent period length, i.e. time between exposure and infectiousness.
- ``latent_period``: Latent period length, i.e. time between exposure and infectiousness.

- ``infectious_period``: Infections period length, i.e. time during which agent can spread disease

- ``symptomdev_period``: Symptom development period length (known as incubation period in some contexts), i.e. time between exposure and symptoms appearing.
- ``incubation_period``: Symptom development period length (known as incubation period in some contexts), i.e. time between exposure and symptoms appearing.

- Every day (time-varying)

Expand Down
6 changes: 3 additions & 3 deletions etc/plot_infected.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"never = []\n",
"with open(\"agent_data/run_9_cases.out\") as f:\n",
" for line in f:\n",
" if line.startswith(\"Never infected: \"):\n",
" if line.startswith(\"Susceptible: \"):\n",
" never.append(int(line.strip().split()[-1]))\n",
" if line.startswith(\"Infected: \"):\n",
" infected.append(int(line.strip().split()[1]))\n",
" if line.startswith(\"Immune: \"):\n",
" if line.startswith(\"Recovered: \"):\n",
" immune.append(int(line.strip().split()[1]))"
]
},
Expand All @@ -53,7 +53,7 @@
"ax = plt.gca()\n",
"ax.set_xlabel(\"Day\")\n",
"ax.set_ylabel(\"Number\")\n",
"plt.legend((\"Never infected\", \"Infected\", \"Immune\"))\n",
"plt.legend((\"Susceptible\", \"Infected\", \"Recovered\"))\n",
"\n",
"plt.savefig(\"infected_9_cases\")"
]
Expand Down
8 changes: 4 additions & 4 deletions src/AgentContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ void AgentContainer::infectAgents ()

auto counter_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::disease_counter).data();
auto prob_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::prob).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::incubation_period).data();
auto latent_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::latent_period).data();
auto infectious_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::infectious_period).data();
auto symptomdev_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::symptomdev_period).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::incubation_period).data();

auto* lparm = m_d_parm[d];

Expand All @@ -510,9 +510,9 @@ void AgentContainer::infectAgents ()
if (amrex::Random(engine) < prob_ptr[i]) {
status_ptr[i] = Status::infected;
counter_ptr[i] = 0.0_rt;
incubation_period_ptr[i] = amrex::RandomNormal(lparm->latent_length_mean, lparm->latent_length_std, engine);
latent_period_ptr[i] = amrex::RandomNormal(lparm->latent_length_mean, lparm->latent_length_std, engine);
infectious_period_ptr[i] = amrex::RandomNormal(lparm->infectious_length_mean, lparm->infectious_length_std, engine);
symptomdev_period_ptr[i] = amrex::RandomNormal(lparm->incubation_length_mean, lparm->incubation_length_std, engine);
incubation_period_ptr[i] = amrex::RandomNormal(lparm->incubation_length_mean, lparm->incubation_length_std, engine);
return;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/AgentDefinitions.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct RealIdxDisease
treatment_timer = 0, /*!< Timer since hospital admission */
disease_counter, /*!< Counter since start of infection */
prob, /*!< Probability of infection */
incubation_period, /*!< Time until infectious */
latent_period, /*!< Time until infectious */
infectious_period, /*!< Length of time infectious */
symptomdev_period, /*!< Time until symptoms would develop */
incubation_period, /*!< Time until symptoms would develop */
nattribs /*!< number of real-type attribute*/
};
};
Expand Down Expand Up @@ -163,7 +163,7 @@ bool notInfectiousButInfected ( const int a_idx, /*!< Agent index */
{
return ( (a_ptd.m_runtime_idata[i0(a_d)+IntIdxDisease::status][a_idx] == Status::infected)
&& (a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::disease_counter][a_idx]
<= a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::incubation_period][a_idx]) );
<= a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::latent_period][a_idx]) );
}

/*! \brief Is an agent infectious? */
Expand All @@ -175,7 +175,7 @@ bool isInfectious ( const int a_idx, /*!< Agent index */
{
return ( (a_ptd.m_runtime_idata[i0(a_d)+IntIdxDisease::status][a_idx] == Status::infected)
&& (a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::disease_counter][a_idx]
>= a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::incubation_period][a_idx]) );
>= a_ptd.m_runtime_rdata[r0(a_d)+RealIdxDisease::latent_period][a_idx]) );
}

/*! \brief Is an agent susceptible? */
Expand Down
8 changes: 4 additions & 4 deletions src/CensusData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,9 @@ int infect_random_community (AgentContainer& pc, /*!< Agent container (particle
auto status_ptr = soa.GetIntData(i_RT+i0(d_idx)+IntIdxDisease::status).data();

auto counter_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::disease_counter).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::incubation_period).data();
auto latent_period_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::latent_period).data();
auto infectious_period_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::infectious_period).data();
auto symptomdev_period_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::symptomdev_period).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d_idx)+RealIdxDisease::incubation_period).data();

//auto unit_arr = pc.m_unit_mf[mfi].array();
auto comm_arr = censusData.comm_mf[mfi].array();
Expand Down Expand Up @@ -932,9 +932,9 @@ int infect_random_community (AgentContainer& pc, /*!< Agent container (particle
} else {
status_ptr[pindex] = Status::infected;
counter_ptr[pindex] = 0;
incubation_period_ptr[pindex] = amrex::RandomNormal(lparm->latent_length_mean, lparm->latent_length_std, engine);
latent_period_ptr[pindex] = amrex::RandomNormal(lparm->latent_length_mean, lparm->latent_length_std, engine);
infectious_period_ptr[pindex] = amrex::RandomNormal(lparm->infectious_length_mean, lparm->infectious_length_std, engine);
symptomdev_period_ptr[pindex] = amrex::RandomNormal(lparm->incubation_length_mean, lparm->incubation_length_std, engine);
incubation_period_ptr[pindex] = amrex::RandomNormal(lparm->incubation_length_mean, lparm->incubation_length_std, engine);
++ni;
}
}
Expand Down
57 changes: 27 additions & 30 deletions src/DiseaseStatus.H
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DiseaseStatus
+ If agent status is #Status::never or #Status::susceptible, do nothing
+ If agent status is #Status::infected, then
+ Increment its counter by 1 day
+ If counter is within incubation period, do nothing more
+ If counter is within latent period, do nothing more
+ Else, use hospitalization probabilities (by age group)
to decide if agent is hospitalized. If yes, use age group to set hospital timer. Also, use
age-group-wise probabilities to move agent to ICU and then to ventilator. Adjust timer
Expand All @@ -72,7 +72,7 @@ class DiseaseStatus
status (using the agent's home community)
+ Else (beyond 3 days), count down hospital timer if agent is hospitalized. At end of hospital
stay, determine if agent is #Status dead or #Status::immune. For non-hospitalized agents,
set them to #Status::immune after incubation length + infection length days.
set them to #Status::immune after latent length + infection length days.

The input argument is a MultiFab with 4 components corresponding to "hospitalizations", "ICU",
"ventilator", and "death". It contains the cumulative totals of these quantities for each
Expand Down Expand Up @@ -140,9 +140,9 @@ void DiseaseStatus<AC,ACT,ACTD,A>::updateAgents(AC& a_agents, /*!< Agent contain
auto timer_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::treatment_timer).data();
auto counter_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::disease_counter).data();
auto prob_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::prob).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::incubation_period).data();
auto latent_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::latent_period).data();
auto infectious_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::infectious_period).data();
auto symptomdev_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::symptomdev_period).data();
auto incubation_period_ptr = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::incubation_period).data();

auto* disease_parm_d = a_agents.getDiseaseParameters_d(d);
auto* disease_parm_h = a_agents.getDiseaseParameters_h(d);
Expand Down Expand Up @@ -175,7 +175,7 @@ void DiseaseStatus<AC,ACT,ACTD,A>::updateAgents(AC& a_agents, /*!< Agent contain
symptomatic_ptr[i] = SymptomStatus::presymptomatic;
}
}
if (counter_ptr[i] == Math::floor(symptomdev_period_ptr[i])) {
if (counter_ptr[i] == Math::floor(incubation_period_ptr[i])) {
if (symptomatic_ptr[i] != SymptomStatus::asymptomatic) {
symptomatic_ptr[i] = SymptomStatus::symptomatic;
}
Expand All @@ -184,31 +184,28 @@ void DiseaseStatus<AC,ACT,ACTD,A>::updateAgents(AC& a_agents, /*!< Agent contain
&& (Random(engine) < symptomatic_withdraw_compliance)) {
withdrawn_ptr[i] = 1;
}
}
if (counter_ptr[i] < incubation_period_ptr[i]) {
// incubation phase
return;
}
if (counter_ptr[i] == Math::ceil(incubation_period_ptr[i])) {
int flag_ICU_i = 0, flag_vent_i = 0;
Real num_days = 0;
disease_parm_d->check_hospitalization( num_days,
flag_ICU_i,
flag_vent_i,
age_group_ptr[i],
u50frac,
engine );
timer_ptr[i] = ParticleReal(num_days);
if (timer_ptr[i] > 0) { flag_hosp_ptr[i] = 1; }
if (flag_ICU_i) { flag_ICU_ptr[i] = 1; }
if (flag_vent_i) { flag_vent_ptr[i] = 1; }
} else {
if (!isHospitalized(i,ptd)) {
if (counter_ptr[i] >= (incubation_period_ptr[i] + infectious_period_ptr[i])) {
status_ptr[i] = Status::immune;
counter_ptr[i] = amrex::RandomNormal(immune_length_mean, immune_length_std, engine);
symptomatic_ptr[i] = SymptomStatus::presymptomatic;
withdrawn_ptr[i] = 0;

if (symptomatic_ptr[i] == SymptomStatus::symptomatic) {
int flag_ICU_i = 0, flag_vent_i = 0;
Real num_days = 0;
disease_parm_d->check_hospitalization( num_days,
flag_ICU_i,
flag_vent_i,
age_group_ptr[i],
u50frac,
engine );
timer_ptr[i] = ParticleReal(num_days);
if (timer_ptr[i] > 0) { flag_hosp_ptr[i] = 1; }
if (flag_ICU_i) { flag_ICU_ptr[i] = 1; }
if (flag_vent_i) { flag_vent_ptr[i] = 1; }
} else {
if (!isHospitalized(i,ptd)) {
if (counter_ptr[i] >= (latent_period_ptr[i] + infectious_period_ptr[i])) {
status_ptr[i] = Status::immune;
counter_ptr[i] = amrex::RandomNormal(immune_length_mean, immune_length_std, engine);
symptomatic_ptr[i] = SymptomStatus::presymptomatic;
withdrawn_ptr[i] = 0;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/HospitalModel.H
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ void HospitalModel<AC,ACT,ACTD,A>::treatAgents(AC& a_agents, /*!< Agent containe
int r_RT = RealIdx::nattribs;

GpuArray<int*,ExaEpi::max_num_diseases> status_ptrs, symptomatic_ptrs;
GpuArray<ParticleReal*,ExaEpi::max_num_diseases> counter_ptrs, timer_ptrs, incub_per_ptrs;
GpuArray<ParticleReal*,ExaEpi::max_num_diseases> counter_ptrs, timer_ptrs, latent_per_ptrs;
for (int d = 0; d < n_disease; d++) {
status_ptrs[d] = soa.GetIntData(i_RT+i0(d)+IntIdxDisease::status).data();
symptomatic_ptrs[d] = soa.GetIntData(i_RT+i0(d)+IntIdxDisease::symptomatic).data();
counter_ptrs[d] = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::disease_counter).data();
timer_ptrs[d] = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::treatment_timer).data();
incub_per_ptrs[d] = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::incubation_period).data();
latent_per_ptrs[d] = soa.GetRealData(r_RT+r0(d)+RealIdxDisease::latent_period).data();
}

Gpu::DeviceVector<int> is_alive;
Expand Down Expand Up @@ -139,7 +139,7 @@ void HospitalModel<AC,ACT,ACTD,A>::treatAgents(AC& a_agents, /*!< Agent containe
// agent is not in hospital
return;
}
if (counter_ptrs[d][i] == Math::ceil(incub_per_ptrs[d][i])) {
if (counter_ptrs[d][i] == Math::ceil(latent_per_ptrs[d][i])) {
// agent just started treatment
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ void writePlotFile (const AgentContainer& pc, /*!< Agent (particle) container */
real_varnames.push_back("treatment_timer"); write_real_comp.push_back(1);
real_varnames.push_back("disease_counter"); write_real_comp.push_back(1);
real_varnames.push_back("infection_prob"); write_real_comp.push_back(1);
real_varnames.push_back("incubation_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back("latent_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back("infectious_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back("symptomdev_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back("incubation_period"); write_real_comp.push_back(static_cast<int>(step==0));
int_varnames.push_back ("status"); write_int_comp.push_back(1);
int_varnames.push_back ("strain"); write_int_comp.push_back(static_cast<int>(step==0));
int_varnames.push_back ("symptomatic"); write_int_comp.push_back(1);
Expand All @@ -137,9 +137,9 @@ void writePlotFile (const AgentContainer& pc, /*!< Agent (particle) container */
real_varnames.push_back(disease_names[d]+"treatment_timer"); write_real_comp.push_back(1);
real_varnames.push_back(disease_names[d]+"_disease_counter"); write_real_comp.push_back(1);
real_varnames.push_back(disease_names[d]+"_infection_prob"); write_real_comp.push_back(1);
real_varnames.push_back(disease_names[d]+"_incubation_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back(disease_names[d]+"_latent_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back(disease_names[d]+"_infectious_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back(disease_names[d]+"_symptomdev_period"); write_real_comp.push_back(static_cast<int>(step==0));
real_varnames.push_back(disease_names[d]+"_incubation_period"); write_real_comp.push_back(static_cast<int>(step==0));
int_varnames.push_back (disease_names[d]+"_status"); write_int_comp.push_back(1);
int_varnames.push_back (disease_names[d]+"_strain"); write_int_comp.push_back(static_cast<int>(step==0));
int_varnames.push_back (disease_names[d]+"_symptomatic"); write_int_comp.push_back(1);
Expand Down
4 changes: 2 additions & 2 deletions src/InteractionModHome.H
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ class InteractionModHome : public InteractionModel<AC,ACT,ACTD,A>
+ Find its bin and the range of indices in the bin-sorted array for agents in its bin
+ If the agent is #Status::immune, do nothing.
+ If the agent is #Status::infected with the number of days infected (RealIdxDisease::disease_counter)
less than the incubation length, do nothing.
less than the latent length, do nothing.
+ Else, for each agent *j* in the same bin:
+ If the agent is #Status::immune, do nothing.
+ If the agent is #Status::infected with the number of days infected (RealIdxDisease::disease_counter)
less than the incubation length, do nothing.
less than the latent length, do nothing.
+ Else if *i* is not infected and *j* is infected, compute probability of *i* getting infected
from *j* (see below).

Expand Down
4 changes: 2 additions & 2 deletions src/InteractionModNborhood.H
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ class InteractionModNborhood : public InteractionModel<AC,ACT,ACTD,A>
+ Find its bin and the range of indices in the bin-sorted array for agents in its bin
+ If the agent is #Status::immune, do nothing.
+ If the agent is #Status::infected with the number of days infected (RealIdxDisease::disease_counter)
less than the incubation length, do nothing.
less than the latent length, do nothing.
+ Else, for each agent *j* in the same bin:
+ If the agent is #Status::immune, do nothing.
+ If the agent is #Status::infected with the number of days infected (RealIdxDisease::disease_counter)
less than the incubation length, do nothing.
less than the latent length, do nothing.
+ Else if *i* is not infected and *j* is infected, compute probability of *i* getting infected
from *j* (see below).

Expand Down
Loading
Loading