Skip to content

Commit b0363c4

Browse files
authored
918 add function to change the tolerance in ide model (#919)
added new model parameter m_tol to IDE-SECIR model
1 parent d6bb6fd commit b0363c4

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

cpp/models/ide_secir/model.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void Model::compute_flow(int idx_InfectionTransitions, Eigen::Index idx_Incoming
126126
This needs to be adjusted if we are changing the finite difference scheme */
127127

128128
Eigen::Index calc_time_index = (Eigen::Index)std::ceil(
129-
parameters.get<TransitionDistributions>()[idx_InfectionTransitions].get_support_max(dt) / dt);
129+
parameters.get<TransitionDistributions>()[idx_InfectionTransitions].get_support_max(dt, m_tol) / dt);
130130

131131
Eigen::Index num_time_points = m_transitions.get_num_time_points();
132132

@@ -196,13 +196,13 @@ void Model::update_forceofinfection(ScalarType dt, bool initialization)
196196
// determine the relevant calculation area = union of the supports of the relevant transition distributions
197197
ScalarType calc_time = std::max(
198198
{parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms]
199-
.get_support_max(dt),
199+
.get_support_max(dt, m_tol),
200200
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToRecovered]
201-
.get_support_max(dt),
201+
.get_support_max(dt, m_tol),
202202
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere]
203-
.get_support_max(dt),
203+
.get_support_max(dt, m_tol),
204204
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToRecovered]
205-
.get_support_max(dt)});
205+
.get_support_max(dt, m_tol)});
206206

207207
// corresponding index
208208
/* need calc_time_index timesteps in sum,
@@ -262,8 +262,8 @@ void Model::compute_compartment(Eigen::Index idx_InfectionState, Eigen::Index id
262262

263263
// determine relevant calculation area and corresponding index
264264
ScalarType calc_time =
265-
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt),
266-
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt));
265+
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt, m_tol),
266+
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt, m_tol));
267267

268268
Eigen::Index calc_time_index = (Eigen::Index)std::ceil(calc_time / dt) - 1;
269269

cpp/models/ide_secir/model.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ class Model
7474

7575
ScalarType support_max = std::max(
7676
{parameters.get<TransitionDistributions>()[(int)InfectionTransition::ExposedToInfectedNoSymptoms]
77-
.get_support_max(dt),
77+
.get_support_max(dt, m_tol),
7878
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToInfectedSymptoms]
79-
.get_support_max(dt),
79+
.get_support_max(dt, m_tol),
8080
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedNoSymptomsToRecovered]
81-
.get_support_max(dt),
81+
.get_support_max(dt, m_tol),
8282
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToInfectedSevere]
83-
.get_support_max(dt),
83+
.get_support_max(dt, m_tol),
8484
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSymptomsToRecovered]
85-
.get_support_max(dt),
85+
.get_support_max(dt, m_tol),
8686
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSevereToInfectedCritical]
87-
.get_support_max(dt),
87+
.get_support_max(dt, m_tol),
8888
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedSevereToRecovered]
89-
.get_support_max(dt),
89+
.get_support_max(dt, m_tol),
9090
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedCriticalToDead]
91-
.get_support_max(dt),
91+
.get_support_max(dt, m_tol),
9292
parameters.get<TransitionDistributions>()[(int)InfectionTransition::InfectedCriticalToRecovered]
93-
.get_support_max(dt)});
93+
.get_support_max(dt, m_tol)});
9494

9595
if (m_transitions.get_num_time_points() < (Eigen::Index)std::ceil(support_max / dt)) {
9696
log_error(
@@ -195,6 +195,16 @@ class Model
195195
*/
196196
void compute_recovered();
197197

198+
/**
199+
* @brief Setter for the tolerance used to calculate the maximum support of the TransitionDistributions.
200+
*
201+
* @param[in] new_tol New tolerance.
202+
*/
203+
void set_tol_for_support_max(ScalarType new_tol)
204+
{
205+
m_tol = new_tol;
206+
}
207+
198208
ParameterSet parameters{}; ///< ParameterSet of Model Parameters.
199209
/* Attention: m_populations and m_transitions do not necessarily have the same number of time points due to the initialization part. */
200210
TimeSeries<ScalarType>
@@ -206,6 +216,7 @@ class Model
206216
ScalarType m_forceofinfection{0}; ///< Force of infection term needed for numerical scheme.
207217
ScalarType m_N{0}; ///< Total population size of the considered region.
208218
ScalarType m_deaths_before{0}; ///< Deaths before start of simulation (at time -m_dt).
219+
ScalarType m_tol{1e-10}; ///< Tolerance used to calculate the maximum support of the TransitionDistributions.
209220
};
210221

211222
} // namespace isecir

cpp/tests/test_ide_secir.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class ModelTestIdeSecir : public testing::Test
8686
model->parameters.set<mio::isecir::TransmissionProbabilityOnContact>(prob);
8787
model->parameters.set<mio::isecir::RelativeTransmissionNoSymptoms>(prob);
8888
model->parameters.set<mio::isecir::RiskOfInfectionFromSymptomatic>(prob);
89+
90+
model->set_tol_for_support_max(1e-10);
8991
}
9092

9193
virtual void TearDown()

0 commit comments

Comments
 (0)