-
Notifications
You must be signed in to change notification settings - Fork 19
1350 Implement RSV model #1352
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
1350 Implement RSV model #1352
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ffbe73d
first draft RSV model.
HenrZu 803ada6
bindings for rsv model
HenrZu 8c8c376
tests cpp
HenrZu 266a9db
some tests for bindings
HenrZu cfb4d7d
shorter simulation period in examples
HenrZu 56aff5e
[ci skip] add flow chart
HenrZu 254af80
Apply suggestions from code review
HenrZu 8433dc3
review comments
HenrZu 5ca5b91
Merge branch 'main' of github.com:SciCompMod/memilio into 1350-implem…
HenrZu d4fb60e
adjust to updated main
HenrZu 8b622f3
fix msvc
HenrZu 549329d
include numbers for msvc
HenrZu f2c0f65
add (de-) serialize functionality
HenrZu 7741a1c
Update cpp/models/ode_mseirs4/parameters.h
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
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,94 @@ | ||
| /* | ||
| * 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_mseirs4/model.h" | ||
| #include "memilio/compartments/simulation.h" | ||
| #include <iostream> | ||
|
|
||
| int main() | ||
| { | ||
| using FP = double; | ||
| mio::omseirs4::Model<FP> model; | ||
| auto& params = model.parameters; | ||
|
|
||
| // Example parameter values for day-based time unit (t in days) | ||
| params.get<mio::omseirs4::BaseTransmissionRate<FP>>() = 0.4; // b0 per day | ||
| params.get<mio::omseirs4::SeasonalAmplitude<FP>>() = 0.15; // b1 | ||
| params.get<mio::omseirs4::SeasonalPhase<FP>>() = 0.0; // phi; for phase shift use 2*pi*offsetDays/365 | ||
| params.get<mio::omseirs4::NaturalBirthDeathRate<FP>>() = 1.0 / (70.0 * 365.0); // mu per day | ||
| params.get<mio::omseirs4::LossMaternalImmunityRate<FP>>() = 1.0 / 90.0; // xi per day (~3 months) | ||
| params.get<mio::omseirs4::ProgressionRate<FP>>() = 1.0 / 7.0; // sigma per day (≈7 days latent) | ||
| params.get<mio::omseirs4::RecoveryRate<FP>>() = 1.0 / 14.0; // nu per day (≈14 days infectious) | ||
| params.get<mio::omseirs4::ImmunityWaningRate<FP>>() = 1.0 / (5.0 * 365.0); // gamma per day (5 years) | ||
| // factors default already set (0.5, 0.35, 0.25) as in the paper https://doi.org/10.1016/S0025-5564(01)00066-9. | ||
|
|
||
| // Initial population (absolute counts), set all compartments explicitly. | ||
| double N = 1e6; | ||
|
|
||
| // Initial populations. | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::MaternalImmune)}] = | ||
| 5000.0; | ||
|
|
||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::E1)}] = 300.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::E2)}] = 150.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::E3)}] = 80.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::E4)}] = 70.0; | ||
|
|
||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::I1)}] = 200.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::I2)}] = 100.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::I3)}] = 50.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::I4)}] = 50.0; | ||
|
|
||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::R1)}] = 40000.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::R2)}] = 30000.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::R3)}] = 20000.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::R4)}] = 10000.0; | ||
|
|
||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::S2)}] = 100000.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::S3)}] = 50000.0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::S4)}] = 50000.0; | ||
|
|
||
| // Compute S1 as residual to match N | ||
| double assigned = 5000.0 + (300.0 + 150.0 + 80.0 + 70.0) + (200.0 + 100.0 + 50.0 + 50.0) + | ||
| (40000.0 + 30000.0 + 20000.0 + 10000.0) + (100000.0 + 50000.0 + 50000.0); | ||
| double S1 = N - assigned; | ||
| if (S1 < 0) | ||
| S1 = 0; | ||
| model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::S1)}] = S1; | ||
|
|
||
| model.check_constraints(); | ||
|
|
||
| // simulate | ||
| double t0 = 0.0; | ||
| double tmax = 20.0; // days | ||
| double dt = 1.0; // daily output | ||
| auto result = mio::simulate(t0, tmax, dt, model); | ||
|
|
||
| // print header | ||
| std::cout << "t M S1 S2 S3 S4 E1 E2 E3 E4 I1 I2 I3 I4 R1 R2 R3 R4\n"; | ||
| for (size_t i = 0; i < (size_t)result.get_num_time_points(); ++i) { | ||
| std::cout << result.get_time(i); | ||
| const auto& y = result.get_value(i); | ||
| for (size_t k = 0; k < (size_t)mio::omseirs4::InfectionState::Count; ++k) { | ||
| std::cout << ' ' << y[(Eigen::Index)k]; | ||
| } | ||
| std::cout << '\n'; | ||
| } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| add_library(ode_mseirs4 | ||
| infection_state.h | ||
| parameters.h | ||
| model.h | ||
| model.cpp | ||
| ) | ||
| target_link_libraries(ode_mseirs4 PUBLIC memilio) | ||
| target_include_directories(ode_mseirs4 PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
| target_compile_options(ode_mseirs4 PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS}) |
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,18 @@ | ||
| # ODE MSEIRS4 Model | ||
|
|
||
| Implementation of the MSEIRS4 model (maternal immunity + susceptible stages S1-S4 + exposed, infectious, recovered stages with four parallel infection/recovery classes). | ||
| This model is designed for Respiratory Syncytial Virus (RSV) and is based on: | ||
|
|
||
| - Weber A, Weber M, Milligan P. (2001). *Modeling epidemics caused by respiratory syncytial virus (RSV).* Mathematical Biosciences 172(2): 95–113. `DOI:10.1016/S0025-5564(01)00066-9 <https://doi.org/10.1016/S0025-5564(01)00066-9>`_ | ||
|
|
||
|
|
||
| ## Meaning of indices 1–4 (S1–S4, E1–E4, I1–I4, R1–R4) | ||
|
|
||
| - S1: fully susceptible after loss of maternal immunity (highest susceptibility). | ||
| - S2: susceptible after first infection (R1 → S2 via waning; reduced susceptibility). | ||
| - S3: susceptible after second infection (R2 → S3). | ||
| - S4: susceptible after ≥3 infections (R3 → S4 and R4 → S4; lowest susceptibility). | ||
|
|
||
| Correspondingly, E_k/I_k/R_k represent exposed/infectious/recovered states of the k-th infection episode. All infectious classes (I1..I4) contribute to transmission equally in the basic formulation of the paper. | ||
|
|
||
| The model includes seasonality by adjusting the transmission rate with a cosine function. | ||
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,52 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| #ifndef ODE_MSEIRS4_INFECTION_STATE_H | ||
| #define ODE_MSEIRS4_INFECTION_STATE_H | ||
|
|
||
| namespace mio | ||
| { | ||
| namespace omseirs4 | ||
| { | ||
| enum class InfectionState | ||
| { | ||
| MaternalImmune = 0, | ||
HenrZu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| S1, | ||
| S2, | ||
| S3, | ||
| S4, | ||
| E1, | ||
| E2, | ||
| E3, | ||
| E4, | ||
| I1, | ||
| I2, | ||
| I3, | ||
| I4, | ||
| R1, | ||
| R2, | ||
| R3, | ||
| R4, | ||
| Count | ||
| }; | ||
|
|
||
| } // namespace omseirs4 | ||
| } // namespace mio | ||
|
|
||
| #endif // ODE_MSEIRS4_INFECTION_STATE_H | ||
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,28 @@ | ||
| /* | ||
| * 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_mseirs4/model.h" | ||
|
|
||
| namespace mio | ||
| { | ||
| namespace omseirs4 | ||
| { | ||
|
|
||
| } // namespace omseirs4 | ||
| } // namespace mio |
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.