-
Notifications
You must be signed in to change notification settings - Fork 19
978 Local Feedback Mechanism #1211
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7336e15
[ci skip] initial sim from paper branch
HenrZu 257ffc1
init local feedback mechanism
HenrZu 0ad8179
add tests for feedback
HenrZu 96609f9
msvc cast int
HenrZu 0f83263
doc feedback sim
HenrZu df034d2
review comments
HenrZu 6b5dccd
review
HenrZu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright (C) 2020-2025 MEmilio | ||
| * | ||
| * Authors: Henrik Zunker | ||
| * | ||
| * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #include "ode_secir/model.h" | ||
| #include "memilio/compartments/feedback_simulation.h" | ||
| #include "memilio/utils/logging.h" | ||
|
|
||
| void initialize_model(mio::osecir::Model<double>& model, int total_population, double cont_freq) | ||
| { | ||
| model.parameters.set<mio::osecir::StartDay>(60); | ||
| model.parameters.set<mio::osecir::Seasonality<double>>(0.2); | ||
|
|
||
| // time-related parameters | ||
| model.parameters.get<mio::osecir::TimeExposed<double>>() = 3.2; | ||
| model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>() = 2.0; | ||
| model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>() = 5.8; | ||
| model.parameters.get<mio::osecir::TimeInfectedSevere<double>>() = 9.5; | ||
| model.parameters.get<mio::osecir::TimeInfectedCritical<double>>() = 7.1; | ||
|
|
||
| // Set transmission and isolation parameters | ||
| model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>() = 0.05; | ||
| model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>() = 0.7; | ||
| model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>() = 0.09; | ||
| model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>() = 0.25; | ||
| model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>() = 0.45; | ||
| model.parameters.get<mio::osecir::TestAndTraceCapacity<double>>() = 35; | ||
| model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>() = 0.2; | ||
| model.parameters.get<mio::osecir::CriticalPerSevere<double>>() = 0.25; | ||
| model.parameters.get<mio::osecir::DeathsPerCritical<double>>() = 0.3; | ||
|
|
||
| // contact matrix | ||
| mio::ContactMatrixGroup& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>(); | ||
| contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(1, 1, cont_freq)); | ||
|
|
||
| // initial population | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 40; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = 30; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = 20; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = 10; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = 5; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = 20; | ||
| model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = 0; | ||
| model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}, | ||
| total_population); | ||
|
|
||
| model.apply_constraints(); | ||
| } | ||
|
|
||
| void initialize_feedback(mio::FeedbackSimulation<double, mio::Simulation<double, mio::osecir::Model<double>>, | ||
| mio::osecir::ContactPatterns<double>>& feedback_simulation) | ||
| { | ||
| // nominal ICU capacity | ||
| feedback_simulation.get_parameters().template get<mio::NominalICUCapacity<double>>() = 10; | ||
|
|
||
| // ICU occupancy in the past for memory kernel | ||
| auto& icu_occupancy = feedback_simulation.get_parameters().template get<mio::ICUOccupancyLocal<double>>(); | ||
| Eigen::VectorXd icu_day = Eigen::VectorXd::Constant(1, 1); | ||
| const auto cutoff = static_cast<int>(feedback_simulation.get_parameters().template get<mio::GammaCutOff>()); | ||
| for (int t = -cutoff; t <= 0; ++t) { | ||
| icu_occupancy.add_time_point(t, icu_day); | ||
| } | ||
|
|
||
| // bounds for contact reduction measures | ||
| feedback_simulation.get_parameters().template get<mio::ContactReductionMin<double>>() = {0.1}; | ||
| feedback_simulation.get_parameters().template get<mio::ContactReductionMax<double>>() = {0.8}; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| // This example demonstrates the implementation of a feedback mechanism for a ODE SECIR model. | ||
| // It shows how the perceived risk dynamically impacts contact reduction measures. | ||
| // The feedback mechanism adjusts contact rates during simulation based on the perceived | ||
| // risk which is calculated from the ICU occupancy using a memory kernel. | ||
| mio::set_log_level(mio::LogLevel::warn); | ||
|
|
||
| const double tmax = 35; | ||
| const int total_population = 1000; | ||
| const double cont_freq = 10; | ||
|
|
||
| // create and initialize ODE model for a single age group | ||
| mio::osecir::Model model(1); | ||
| initialize_model(model, total_population, cont_freq); | ||
|
|
||
| // determine the index for the ICU state (InfectedCritical) for feedback mechanism | ||
| auto icu_index = std::vector<size_t>{ | ||
| model.populations.get_flat_index({mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical})}; | ||
|
|
||
| // create simulation objects: first a secir simulation, then a feedback simulation | ||
| auto simulation = mio::osecir::Simulation<double, mio::Simulation<double, mio::osecir::Model<double>>>(model); | ||
| auto feedback_simulation = | ||
| mio::FeedbackSimulation<double, mio::Simulation<double, mio::osecir::Model<double>>, | ||
| mio::osecir::ContactPatterns<double>>(std::move(simulation), icu_index); | ||
|
|
||
| // set up the parameters for the feedback simulation | ||
| initialize_feedback(feedback_simulation); | ||
|
|
||
| // run the simulation with feedback mechanism | ||
| auto results = feedback_simulation.advance(tmax); | ||
|
|
||
| // print the perceived risk and the final total population | ||
| auto& perceived_risk = feedback_simulation.get_perceived_risk(); | ||
| perceived_risk.print_table({"Perceived Risk"}); | ||
| std::cout << "Population at tmax = " << results.sum() << std::endl; | ||
HenrZu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.