Skip to content

Commit 8569422

Browse files
committed
changed order of initialization methods
1 parent c484b89 commit 8569422

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

cpp/models/ide_secir/model.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,46 @@ void Model::initialize(ScalarType dt)
6666
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] -
6767
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
6868
}
69+
else if (m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] > 1e-12) {
70+
//take initialized value for Susceptibles if value can't be calculated via the standard formula
71+
m_initialization_method = 2;
72+
//calculate other compartment sizes for t=0
73+
other_compartments_current_timestep(dt);
74+
75+
//R; need an initial value for R, therefore do not calculate via compute_recovered()
76+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] =
77+
m_N - m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] -
78+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Exposed)] -
79+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedNoSymptoms)] -
80+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSymptoms)] -
81+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSevere)] -
82+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedCritical)] -
83+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
84+
}
85+
else if (m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] > 1e-12) {
86+
//if value for Recovered is initialized and standard method is not applicable, calculate Susceptibles via other compartments
87+
//determining other compartment sizes is not dependent of Susceptibles(0), just of the transitions of the past.
88+
//calculate other compartment sizes for t=0
89+
m_initialization_method = 3;
90+
other_compartments_current_timestep(dt);
91+
92+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] =
93+
m_N - m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Exposed)] -
94+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedNoSymptoms)] -
95+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSymptoms)] -
96+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSevere)] -
97+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedCritical)] -
98+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] -
99+
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
100+
}
69101
else {
70102

71103
// compute Susceptibles at time 0 and m_forceofinfection at time -dt as initial values for discretization scheme
72104
// use m_forceofinfection at -dt to be consistent with further calculations of S (see compute_susceptibles()),
73105
// where also the value of m_forceofinfection for the previous timestep is used
74106
update_forceofinfection(dt, true);
75107
if (m_forceofinfection > 1e-12) {
76-
m_initialization_method = 2;
108+
m_initialization_method = 4;
77109
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] =
78110
m_transitions.get_last_value()[Eigen::Index(InfectionTransition::SusceptibleToExposed)] /
79111
(dt * m_forceofinfection);
@@ -91,46 +123,14 @@ void Model::initialize(ScalarType dt)
91123
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedCritical)] -
92124
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
93125
}
94-
else if (m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] > 1e-12) {
95-
//take initialized value for Susceptibles if value can't be calculated via the standard formula
96-
m_initialization_method = 3;
97-
//calculate other compartment sizes for t=0
98-
other_compartments_current_timestep(dt);
99-
100-
//R; need an initial value for R, therefore do not calculate via compute_recovered()
101-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] =
102-
m_N - m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] -
103-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Exposed)] -
104-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedNoSymptoms)] -
105-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSymptoms)] -
106-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSevere)] -
107-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedCritical)] -
108-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
109-
}
110-
else if (m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] > 1e-12) {
111-
//if value for Recovered is initialized and standard method is not applicable, calculate Susceptibles via other compartments
112-
//determining other compartment sizes is not dependent of Susceptibles(0), just of the transitions of the past.
113-
//calculate other compartment sizes for t=0
114-
m_initialization_method = 4;
115-
other_compartments_current_timestep(dt);
116-
117-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Susceptible)] =
118-
m_N - m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Exposed)] -
119-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedNoSymptoms)] -
120-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSymptoms)] -
121-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedSevere)] -
122-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::InfectedCritical)] -
123-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Recovered)] -
124-
m_populations[Eigen::Index(0)][Eigen::Index(InfectionState::Dead)];
125-
}
126126
else {
127127
m_initialization_method = -1;
128128
log_error("Error occured while initializing compartments: Force of infection is evaluated to 0 and neither "
129129
"Susceptibles nor Recovered or total confirmed cases for time 0 were set. One of them should be "
130130
"larger 0.");
131131
}
132132
}
133-
// compute m_forceofinfection at time 0 needed for further simulation
133+
// Compute m_forceofinfection at time 0 needed for further simulation.
134134
update_forceofinfection(dt);
135135
}
136136

cpp/models/ide_secir/model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ class Model
212212
*
213213
* @returns 0 if the initialization method has not yet been selected,
214214
* 1 if the method using the total number of confirmed cases at time 0 is used,
215-
* 2 if the force of infection method is used,
216-
* 3 if the initialization is calculated using a prior set value for S,
217-
* 4 if the initialization is calculated using a prior set value for R and
215+
* 2 if the initialization is calculated using a prior set value for S,
216+
* 3 if the initialization is calculated using a prior set value for R
217+
* 4 if the force of infection method is used,and
218218
* -1 if the initialization was not possible using any of the methods.
219219
*/
220220
int get_initialization_method()

cpp/tests/test_ide_secir.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,6 @@ TEST(IdeSecir, checkInitializations)
281281
// Verify that the expected initialization method was used.
282282
EXPECT_EQ(1, sim1.get_model().get_initialization_method());
283283

284-
// --- Case with forceofinfection.
285-
mio::TimeSeries<ScalarType> init_copy2(init);
286-
mio::isecir::Model model2(std::move(init_copy2), N, deaths, 0);
287-
288-
// Carry out simulation.
289-
mio::isecir::Simulation sim2(model2, 0, dt);
290-
sim2.advance(tmax);
291-
292-
// Verify that the expected initialization method was used.
293-
EXPECT_EQ(2, sim2.get_model().get_initialization_method());
294-
295284
// --- Case with S.
296285
/* !! For the other tests, the contact rate is set to 0 so that the force of infection is zero.
297286
The forceofinfection initialization method is therefore not used for these tests.*/
@@ -311,7 +300,7 @@ TEST(IdeSecir, checkInitializations)
311300
sim3.advance(tmax);
312301

313302
// Verify that the expected initialization method was used.
314-
EXPECT_EQ(3, sim3.get_model().get_initialization_method());
303+
EXPECT_EQ(2, sim3.get_model().get_initialization_method());
315304

316305
// --- Case with R.
317306
mio::TimeSeries<ScalarType> init_copy4(init);
@@ -325,7 +314,18 @@ TEST(IdeSecir, checkInitializations)
325314
sim4.advance(tmax);
326315

327316
// Verify that the expected initialization method was used.
328-
EXPECT_EQ(4, sim4.get_model().get_initialization_method());
317+
EXPECT_EQ(3, sim4.get_model().get_initialization_method());
318+
319+
// --- Case with forceofinfection.
320+
mio::TimeSeries<ScalarType> init_copy2(init);
321+
mio::isecir::Model model2(std::move(init_copy2), N, deaths, 0);
322+
323+
// Carry out simulation.
324+
mio::isecir::Simulation sim2(model2, 0, dt);
325+
sim2.advance(tmax);
326+
327+
// Verify that the expected initialization method was used.
328+
EXPECT_EQ(4, sim2.get_model().get_initialization_method());
329329

330330
// --- Case without fitting initialization method.
331331
// Deactivate temporarily log output for next test. Error is expected here.

0 commit comments

Comments
 (0)