Skip to content

Commit 9d5af9f

Browse files
committed
added reviewer suggestions
1 parent ef44c73 commit 9d5af9f

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

cpp/models/ide_secir/infection_state.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ enum class InfectionTransition
6161
InfectedSevereToRecovered = 7,
6262
InfectedCriticalToDead = 8,
6363
InfectedCriticalToRecovered = 9,
64-
Count = 10
64+
Count = 10,
65+
DummyIndex = 0
6566
};
6667

6768
// This is an alternative implementation for the infection transitions; currently not used.

cpp/models/ide_secir/model.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ void Model::compute_compartment_from_flows(Eigen::Index idx_InfectionState, Eige
7474
m_populations.get_last_value()[idx_InfectionState] = sum;
7575
}
7676

77-
void Model::compute_compartments_initialization(ScalarType dt)
77+
void Model::initial_compute_compartments_infection(ScalarType dt)
7878
{
7979
// Exposed
8080
compute_compartment_from_flows(
8181
Eigen::Index(InfectionState::Exposed), Eigen::Index(InfectionTransition::SusceptibleToExposed),
82-
(int)InfectionTransition::ExposedToInfectedNoSymptoms, 0,
83-
dt); // This is a dummy index as there is no transition from Exposed to Recovered in our model,
84-
// write any transition here as probability from Exposed to Recovered is 0.
82+
(int)InfectionTransition::ExposedToInfectedNoSymptoms, (int)InfectionTransition::DummyIndex,
83+
dt); // This is a dummy index as there is no transition from Exposed to Recovered in our model.
8584
// InfectedNoSymptoms
8685
compute_compartment_from_flows(Eigen::Index(InfectionState::InfectedNoSymptoms),
8786
Eigen::Index(InfectionTransition::ExposedToInfectedNoSymptoms),
@@ -104,11 +103,11 @@ void Model::compute_compartments_initialization(ScalarType dt)
104103
(int)InfectionTransition::InfectedCriticalToRecovered, dt);
105104
}
106105

107-
void Model::calculate_initial_compartment_sizes(ScalarType dt)
106+
void Model::initial_compute_compartments(ScalarType dt)
108107
{
109108
// The initialization method only affects the Susceptible and Recovered compartments.
110109
// It is possible to calculate the sizes of the other compartments in advance because only the initial values of the flows are used.
111-
compute_compartments_initialization(dt);
110+
initial_compute_compartments_infection(dt);
112111

113112
if (m_total_confirmed_cases > 1e-12) {
114113
m_initialization_method = 1;
@@ -284,7 +283,7 @@ void Model::flows_current_timestep(ScalarType dt)
284283
Eigen::Index(InfectionTransition::InfectedSevereToInfectedCritical), dt);
285284
}
286285

287-
void Model::update_compartments_current_timestep()
286+
void Model::update_compartments()
288287
{
289288
Eigen::Index num_time_points = m_populations.get_num_time_points();
290289

cpp/models/ide_secir/model.h

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class Model
4141
* @param[in, out] init TimeSeries with the initial values of the number of individuals,
4242
* which transit within one timestep dt from one compartment to another.
4343
* Possible transitions are specified in #InfectionTransition%s.
44-
* Considered time points should have the distance dt. The last time point determines the start time t0 of the simulation.
44+
* Considered time points should have the distance dt. The last time point determines the start time t0 of the
45+
* simulation.
4546
* The time history must reach a certain point in the past so that the simulation can be performed.
4647
* A warning is displayed if the condition is violated.
4748
* @param[in] N_init The population of the considered region.
@@ -54,19 +55,21 @@ class Model
5455

5556
// ---- Functionality to calculate the sizes of the compartments for time t0. ----
5657
/**
57-
* @brief Compute the compartment specified in idx_InfectionState at the current time -- only using historic flow values and disrespecting potential, previous compartment value.
58+
* @brief Compute the compartment specified in idx_InfectionState at the current time -- only using historic flow
59+
* values and disrespecting potential, previous compartment value.
5860
*
59-
* The computation is meaningful for all compartments except #Susceptible, #Recovered and #Death
61+
* The computation is meaningful for all compartments except Susceptible, Recovered and #Death
6062
* and mostly needed for initialization.
61-
* For #Susceptible, #Recovered and #Dead, use corresponding alternative functions.
63+
* For Susceptible, Recovered and Dead, use corresponding alternative functions.
6264
*
6365
* @param[in] idx_InfectionState Specifies the considered #InfectionState
6466
* @param[in] idx_IncomingFlow Specifies the index of the infoming flow to #InfectionState in m_transitions.
6567
* @param[in] idx_TransitionDistribution1 Specifies the index of the first relevant TransitionDistribution,
6668
* related to a flow from the considered #InfectionState to any other #InfectionState.
6769
* This index is also used for related probability.
6870
* @param[in] idx_TransitionDistribution2 Specifies the index of the second relevant TransitionDistribution,
69-
* related to a flow from the considered #InfectionState to any other #InfectionState (in most cases to #Recovered).
71+
* related to a flow from the considered #InfectionState to any other #InfectionState (in most cases
72+
* to Recovered).
7073
* Necessary related probability is calculated via 1-probability[idx_TransitionDistribution1].
7174
* If the second index is not needed, e.g., if probability[idx_TransitionDistribution1]=1,
7275
* just use an arbitrary legal index.
@@ -85,31 +88,34 @@ class Model
8588
*
8689
* @param[in] dt Time discretization step size.
8790
*/
88-
void compute_compartments_initialization(ScalarType dt);
91+
void initial_compute_compartments_infection(ScalarType dt);
8992

9093
/**
9194
* @brief Computes the values of compartments at initialization.
9295
*
9396
* The initialization method is selected automatically based on the different values that need to be set beforehand.
9497
* Infection compartments are always computed through historic flows.
95-
* Initialization methods for #Susceptible and #Recovered are tested in the following order:
96-
* 1.) If a positive number for the total number of confirmed cases is set, #Recovered is set according to that value and #Susceptible%s are derived.
97-
* 2.) If #Susceptible%s are set, #Recovered will be derived.
98-
* 3.) If #Recovered are set directly, #Susceptible%s are derived.
99-
* 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021) to set the #Susceptible%s.
98+
* Initialization methods for Susceptible and Recovered are tested in the following order:
99+
* 1.) If a positive number for the total number of confirmed cases is set, Recovered is set according to that
100+
* value and Susceptible%s are derived.
101+
* 2.) If Susceptible%s are set, Recovered will be derived.
102+
* 3.) If Recovered are set directly, Susceptible%s are derived.
103+
* 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021)
104+
* to set the Susceptible%s.
100105
*
101-
* The function calculate_compartments_initialization() is used in every method for the compartments Exposed, InfectedNoSymptoms, InfectedSymptoms, InfectedSevere and InfectedCritical.
106+
* The function calculate_compartments_initialization() is used in every method for the compartments Exposed,
107+
* InfectedNoSymptoms, InfectedSymptoms, InfectedSevere and InfectedCritical.
102108
* In addition, the force of infection is calculated for start time t_0.
103109
*
104110
* @param[in] dt Time discretization step size.
105111
*/
106-
void calculate_initial_compartment_sizes(ScalarType dt);
112+
void initial_compute_compartments(ScalarType dt);
107113

108114
// ---- Functionality for the iterations of a simulation. ----
109115
/**
110-
* @brief Computes number of #Susceptible%s for the current last time in m_populations.
116+
* @brief Computes number of Susceptible%s for the current last time in m_populations.
111117
*
112-
* Number is computed using previous number of #Susceptible%s and the force of infection (also from previous timestep).
118+
* Number is computed using previous number of Susceptible%s and the force of infection (also from previous timestep).
113119
* Number is stored at the matching index in m_populations.
114120
* @param[in] dt Time discretization step size.
115121
*/
@@ -139,13 +145,14 @@ class Model
139145
void flows_current_timestep(ScalarType dt);
140146

141147
/**
142-
* @brief Sets the values of compartments (all apart from #Susceptible) for the current last timestep in m_populations.
148+
* @brief Updates the values of all compartments except Susceptible at initialization.
143149
*
144-
* New values are stored in m_populations. The values are calculated using the compartment size in the previous time step and the related flows of the current time step.
150+
* New values are stored in m_populations. The values are calculated using the compartment size in the previous
151+
* time step and the related flows of the current time step.
145152
* Therefore the flows of the current time step should be calculated before using this function.
146153
*
147154
*/
148-
void update_compartments_current_timestep();
155+
void update_compartments();
149156

150157
/**
151158
* @brief Computes force of infection for the current last time in m_transitions.
@@ -154,8 +161,8 @@ class Model
154161
*
155162
* @param[in] dt Time discretization step size.
156163
* @param[in] initialization If true we are in the case of the initialization of the model.
157-
* For this we need forceofinfection at time point t0-dt and not at the current last time (given by m_transitions)
158-
* as in the other time steps.
164+
* For this we need forceofinfection at time point t0-dt and not at the current last time
165+
* (given by m_transitions) as in the other time steps.
159166
*/
160167
void compute_forceofinfection(ScalarType dt, bool initialization = false);
161168

@@ -228,11 +235,13 @@ class Model
228235
*
229236
* The initialization method is selected automatically based on the different values that need to be set beforehand.
230237
* Infection compartments are always computed through historic flow.
231-
* Initialization methods for #Susceptible and #Recovered are tested in the following order:
232-
* 1.) If a positive number for the total number of confirmed cases is set, #Recovered is set according to that value and #Susceptible%s are derived.
233-
* 2.) If #Susceptible%s are set, #Recovered will be derived.
234-
* 3.) If #Recovered are set directly, #Susceptible%s are derived.
235-
* 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021) to set the #Susceptible%s.
238+
* Initialization methods for Susceptible and Recovered are tested in the following order:
239+
* 1.) If a positive number for the total number of confirmed cases is set, Recovered is set according to that value
240+
* and Susceptible%s are derived.
241+
* 2.) If Susceptible%s are set, Recovered will be derived.
242+
* 3.) If Recovered are set directly, Susceptible%s are derived.
243+
* 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021) to
244+
* set the Susceptible%s.
236245
*
237246
* @return Index representing the initialization method.
238247
*/
@@ -243,20 +252,21 @@ class Model
243252

244253
// ---- Public parameters. ----
245254
ParameterSet parameters{}; ///< ParameterSet of Model Parameters.
246-
/* Attention: m_populations and m_transitions do not necessarily have the same number of time points due to the initialization part. */
255+
// Attention: m_populations and m_transitions do not necessarily have the same number of time points due to the
256+
// initialization part.
247257
TimeSeries<ScalarType>
248258
m_transitions; ///< TimeSeries containing points of time and the corresponding number of transitions.
249-
TimeSeries<ScalarType>
250-
m_populations; ///< TimeSeries containing points of time and the corresponding number of people in defined #InfectionState%s.
259+
TimeSeries<ScalarType> m_populations; ///< TimeSeries containing points of time and the corresponding number of
260+
// people in defined #InfectionState%s.
251261

252262
private:
253263
// ---- Private parameters. ----
254264
ScalarType m_forceofinfection{0}; ///< Force of infection term needed for numerical scheme.
255265
ScalarType m_N{0}; ///< Total population size of the considered region.
256266
ScalarType m_total_confirmed_cases{0}; ///< Total number of confirmed cases at time t0.
257267
ScalarType m_tol{1e-10}; ///< Tolerance used to calculate the maximum support of the TransitionDistributions.
258-
int m_initialization_method{
259-
0}; ///< Gives the index of the method used for the initialization of the model. See also get_initialization_method_compartments() for the number code.
268+
int m_initialization_method{0}; ///< Gives the index of the method used for the initialization of the model.
269+
//See also get_initialization_method_compartments() for the number code.
260270
};
261271

262272
} // namespace isecir

cpp/models/ide_secir/simulation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Simulation::advance(ScalarType tmax)
3434
{
3535
mio::log_info("Simulating IDE-SECIR from t0 = {} until tmax = {} with dt = {}.",
3636
m_model->m_transitions.get_last_time(), tmax, m_dt);
37-
m_model->calculate_initial_compartment_sizes(m_dt);
37+
m_model->initial_compute_compartments(m_dt);
3838

3939
// For every time step:
4040
while (m_model->m_transitions.get_last_time() < tmax - m_dt / 2) {
@@ -49,7 +49,7 @@ void Simulation::advance(ScalarType tmax)
4949
m_model->flows_current_timestep(m_dt);
5050

5151
// Update remaining compartments:
52-
m_model->update_compartments_current_timestep();
52+
m_model->update_compartments();
5353

5454
// Compute m_forceofinfection (only used for calculation of Susceptibles and flow SusceptibleToExposed in the next timestep!):
5555
m_model->compute_forceofinfection(m_dt);

0 commit comments

Comments
 (0)