-
Notifications
You must be signed in to change notification settings - Fork 20
905 add age group resolution to seir and sir model #911
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
HenrZu
merged 37 commits into
main
from
905-add-age-group-reolution-to-seir-and-sir-model
May 2, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
dbf58b7
modified parameters.h to account for AgeGroups
johapau 1ed2b67
modified sir model.h
johapau 1e0c195
added agegroups to sir model
johapau c4e6fdc
finished
johapau a971131
agegroup extension finished
johapau 2514ded
try to fix CI
johapau f14ed43
hope to fix CI
johapau d018c30
get ci to work
johapau f66bdfe
easier indexing
johapau f9fd94a
gitignore changed
johapau df3dcec
added contact matrices
johapau 8120e44
added ageres examples
johapau 5a47464
first try to implement agegroup test
johapau 851c0e2
push
johapau 0bfd71c
test agegroup
johapau 832b364
new tests added
johapau f918c6b
seir tests changed
johapau cf70d1c
remove vscode folder
HenrZu 9c9436e
Merge branch 'main' into 905-add-age-group-reolution-to-seir-and-sir-…
HenrZu 6d3ae4f
cleanup examples
HenrZu 197f371
[ci skip] fix bug. Tests still fail
HenrZu 3a3615c
fix tests
HenrZu 2bdf03f
Merge branch 'main' into 905-add-age-group-reolution-to-seir-and-sir-…
HenrZu 7078c46
fix msvc
HenrZu f6e1683
adjust bindings + tests pycode
HenrZu 1d1ceec
some formating + print generation
HenrZu 6f2aa09
rm print, adjust tests
HenrZu ac1c59f
print results generation
HenrZu 83ea545
add space
HenrZu cca2bab
fix buffer
HenrZu 9210861
rm space gitignore
HenrZu 622b7ad
Update cpp/examples/ode_seir.cpp
HenrZu 99aec4c
fixes from review
HenrZu 183eb2b
Merge branch 'main' into 905-add-age-group-reolution-to-seir-and-sir-…
HenrZu 266ac20
more extensive testing of simulation and get_flows
HenrZu 140942d
Update cpp/examples/ode_seir.cpp
HenrZu 4e874c9
naming
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
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,62 @@ | ||
| #include "ode_seir/model.h" | ||
| #include "ode_seir/infection_state.h" | ||
| #include "ode_seir/parameters.h" | ||
| #include "memilio/compartments/simulation.h" | ||
| #include "memilio/utils/logging.h" | ||
|
|
||
| int main() | ||
| { | ||
| mio::set_log_level(mio::LogLevel::debug); | ||
|
|
||
| double t0 = 0; | ||
| double tmax = 50; | ||
| double dt = 0.001; | ||
|
|
||
| mio::log_info("Simulating SEIR; t={} ... {} with dt = {}.", t0, tmax, dt); | ||
|
|
||
| double cont_freq = 10; | ||
|
|
||
| double nb_total_t0 = 10000, nb_exp_t0 = 100, nb_inf_t0 = 50, nb_rec_t0 = 10; | ||
| const size_t num_groups = 3; | ||
|
|
||
| mio::oseir::Model model(num_groups); | ||
| double fact = 1.0 / num_groups; | ||
|
|
||
| auto& params = model.parameters; | ||
|
|
||
| for (auto i = mio::AgeGroup(0); i < mio::AgeGroup(num_groups); i++) { | ||
| model.populations[{i, mio::oseir::InfectionState::Exposed}] = fact * nb_exp_t0; | ||
| model.populations[{i, mio::oseir::InfectionState::Infected}] = fact * nb_inf_t0; | ||
| model.populations[{i, mio::oseir::InfectionState::Recovered}] = fact * nb_rec_t0; | ||
| model.populations.set_difference_from_group_total<mio::AgeGroup>({i, mio::oseir::InfectionState::Susceptible}, | ||
| fact * nb_total_t0); | ||
|
|
||
| model.parameters.get<mio::oseir::TimeExposed>()[i] = 5.2; | ||
| model.parameters.get<mio::oseir::TimeInfected>()[i] = 6; | ||
| model.parameters.get<mio::oseir::TransmissionProbabilityOnContact>()[i] = 0.04; | ||
| } | ||
|
|
||
| mio::ContactMatrixGroup& contact_matrix = params.get<mio::oseir::ContactPatterns>(); | ||
| contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(num_groups, num_groups, fact * cont_freq)); | ||
| contact_matrix.add_damping(Eigen::MatrixXd::Constant(num_groups, num_groups, 0.7), mio::SimulationTime(30.)); | ||
|
|
||
| model.apply_constraints(); | ||
|
|
||
| mio::TimeSeries<double> seir = simulate(t0, tmax, dt, model); | ||
|
|
||
| std::vector<std::string> vars = {"S", "E", "I", "R"}; | ||
| printf("Number of time points :%d\n", static_cast<int>(seir.get_num_time_points())); | ||
| printf("People in\n"); | ||
|
|
||
| for (size_t k = 0; k < (size_t)mio::oseir::InfectionState::Count; k++) { | ||
| double dummy = 0; | ||
|
|
||
| for (size_t i = 0; i < (size_t)params.get_num_groups(); i++) { | ||
| printf("\t %s[%d]: %.0f", vars[k].c_str(), (int)i, | ||
| seir.get_last_value()[k + (size_t)mio::oseir::InfectionState::Count * (int)i]); | ||
| dummy += seir.get_last_value()[k + (size_t)mio::oseir::InfectionState::Count * (int)i]; | ||
| } | ||
|
|
||
| printf("\t %s_otal: %.0f\n", vars[k].c_str(), dummy); | ||
| } | ||
| } | ||
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,61 @@ | ||
| #include "memilio/epidemiology/age_group.h" | ||
| #include "memilio/utils/time_series.h" | ||
| #include "memilio/utils/logging.h" | ||
| #include "memilio/compartments/simulation.h" | ||
| #include "ode_sir/model.h" | ||
|
|
||
| int main() | ||
| { | ||
| mio::set_log_level(mio::LogLevel::debug); | ||
|
|
||
| double t0 = 0; | ||
| double tmax = 50; | ||
| double dt = 0.1; | ||
|
|
||
| mio::log_info("Simulating SIR; t={} ... {} with dt = {}.", t0, tmax, dt); | ||
|
|
||
| double cont_freq = 10; // see Polymod study | ||
|
|
||
| double nb_total_t0 = 10000, nb_inf_t0 = 50, nb_rec_t0 = 10; | ||
|
|
||
| const size_t num_groups = 3; | ||
| mio::osir::Model model(num_groups); | ||
|
|
||
| double fact = 1.0 / num_groups; | ||
|
|
||
| auto& params = model.parameters; | ||
|
|
||
| for (auto i = mio::AgeGroup(0); i < mio::AgeGroup(num_groups); i++) { | ||
| model.populations[{i, mio::osir::InfectionState::Infected}] = fact * nb_inf_t0; | ||
| model.populations[{i, mio::osir::InfectionState::Recovered}] = fact * nb_rec_t0; | ||
| model.populations.set_difference_from_group_total<mio::AgeGroup>({i, mio::osir::InfectionState::Susceptible}, | ||
| fact * nb_total_t0); | ||
|
|
||
| model.parameters.get<mio::osir::TimeInfected>()[i] = 2.0; | ||
| model.parameters.get<mio::osir::TransmissionProbabilityOnContact>()[i] = 0.3; | ||
| } | ||
|
|
||
| mio::ContactMatrixGroup& contact_matrix = params.get<mio::osir::ContactPatterns>(); | ||
| contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(num_groups, num_groups, fact * cont_freq)); | ||
| contact_matrix.add_damping(Eigen::MatrixXd::Constant(num_groups, num_groups, 0.7), mio::SimulationTime(30.)); | ||
|
|
||
| model.apply_constraints(); | ||
|
|
||
| mio::TimeSeries<double> sir = simulate(t0, tmax, dt, model); | ||
|
|
||
| std::vector<std::string> vars = {"S", "I", "R"}; | ||
| printf("Number of time points :%d\n", static_cast<int>(sir.get_num_time_points())); | ||
| printf("People in\n"); | ||
|
|
||
| for (size_t k = 0; k < (size_t)mio::osir::InfectionState::Count; k++) { | ||
| double dummy = 0; | ||
|
|
||
| for (size_t i = 0; i < (size_t)params.get_num_groups(); i++) { | ||
| printf("\t %s[%d]: %.0f", vars[k].c_str(), (int)i, | ||
| sir.get_last_value()[k + (size_t)mio::osir::InfectionState::Count * (int)i]); | ||
| dummy += sir.get_last_value()[k + (size_t)mio::osir::InfectionState::Count * (int)i]; | ||
| } | ||
|
|
||
| printf("\t %s_otal: %.0f\n", vars[k].c_str(), dummy); | ||
| } | ||
| } |
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.