Skip to content
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

1036 Simulations from paper to investigate behavior of IDE model #1130

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3df5deb
add changepoint simulation
annawendler May 21, 2024
fcc0c38
Merge branch 'main' into 1036-ide-simulations
annawendler May 21, 2024
a16486c
adjust to main
annawendler May 22, 2024
aa7937e
fix changepoint plot for flows
annawendler May 22, 2024
242fe11
adapt plots
annawendler Jun 11, 2024
17687bf
some adjustments
annawendler Jun 17, 2024
0e49636
add changepoint simulation based on covasim data
annawendler Jun 19, 2024
c3ac659
clean up
annawendler Jul 11, 2024
864e44d
add computation of parameters from covasim
lenaploetzke Jul 24, 2024
0004580
first version of real simulation
annawendler Jul 24, 2024
6b10934
Merge branch '1036-ide-simulations' of github.com:SciCompMod/memilio …
annawendler Jul 24, 2024
1ecf01d
update parameters
annawendler Jul 24, 2024
9faf4fc
roughly set initial conditions
annawendler Jul 29, 2024
df2f89f
add NPIs (not suitable for June yet)
annawendler Jul 31, 2024
8891588
update real scneario and plots
annawendler Aug 2, 2024
d52b13e
update changepoint scenario
annawendler Aug 2, 2024
93f7658
add ide convergence simulation
lenaploetzke Aug 8, 2024
59a433f
add explicit type conversions
lenaploetzke Aug 8, 2024
6a1bd98
resolve error
lenaploetzke Aug 8, 2024
9ab6458
automate for different parameters for U and some updates
annawendler Aug 15, 2024
5f11e8b
Merge branch 'main' into 1036-ide-simulations
annawendler Aug 15, 2024
db47cd6
adjust NPIs for October and adapt extrapolation of RKI data for I
annawendler Aug 15, 2024
f309619
adjust NPIs and probs for june scenario
annawendler Aug 15, 2024
278ffe6
adapt for different mu
annawendler Aug 19, 2024
40b4794
add script to investigate age distributions
annawendler Aug 20, 2024
9cb23fb
Merge remote-tracking branch 'origin/1097-demonstrate-convergence-rat…
annawendler Aug 20, 2024
ef843a3
add plot script for convergence rate
annawendler Aug 20, 2024
6cf7a13
compute mu by population
annawendler Aug 20, 2024
206a1d5
clean up and set parameters according to paper
annawendler Aug 21, 2024
aaa56d7
update contact rate in simplified setting of contact matrices
annawendler Aug 21, 2024
5f79c35
adapt parameters for age distribution plot
annawendler Aug 21, 2024
46a11df
round cont_freq in changepoint scenario
annawendler Aug 21, 2024
3abf279
clean up
annawendler Sep 30, 2024
a1bedb5
Merge branch 'main' into 1036-ide-simulations
annawendler Oct 8, 2024
aba44fa
try CI
annawendler Oct 11, 2024
ae68c76
change includes
annawendler Oct 11, 2024
9d56021
chnage type of data_dir
annawendler Oct 11, 2024
3922cb6
change missing directories
annawendler Oct 11, 2024
6ba92c5
some reordering
annawendler Dec 2, 2024
f2c9856
Merge branch 'main' into 1036-ide-simulations
annawendler Dec 17, 2024
28ab9f9
[ci skip] adapt to merge and adapt cmakelists
annawendler Dec 17, 2024
5053154
[ci skip] clean up
annawendler Dec 17, 2024
4c17d76
clean up and documentation of cpp scripts
annawendler Dec 17, 2024
c083c26
documentation
annawendler Dec 20, 2024
8ef5432
docu
annawendler Jan 6, 2025
e467e13
[ci skip] correct scaling when removing time points of ODE results
annawendler Jan 7, 2025
4ee4779
[ci skip] do ode simulation only once before doing all ide simulations
annawendler Jan 7, 2025
8927267
correct saving of ode flows again and docu of plot script
annawendler Jan 7, 2025
7dc06df
Merge branch 'main' into 1036-ide-simulations
annawendler Jan 7, 2025
1ec70e8
try ci
annawendler Jan 7, 2025
4574633
test ci
annawendler Jan 9, 2025
1378a4d
test again
annawendler Jan 9, 2025
63a3e59
test
annawendler Jan 10, 2025
8e23235
another test
annawendler Jan 10, 2025
7ab584c
again
annawendler Jan 10, 2025
670eece
first version of fix to make set_initial_flows compatible for both Co…
annawendler Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ endif()

if(MEMILIO_BUILD_SIMULATIONS)
add_subdirectory(simulations)
add_subdirectory(simulations/IDE_paper)
endif()

if(MEMILIO_BUILD_BENCHMARKS)
Expand Down
6 changes: 3 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ if(MEMILIO_HAS_HDF5)
endif()

if(MEMILIO_HAS_JSONCPP)
add_executable(ide_initialization_example ide_initialization.cpp)
target_link_libraries(ide_initialization_example PRIVATE memilio ide_secir)
target_compile_options(ide_initialization_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(ide_initialization_example ide_initialization.cpp)
target_link_libraries(ide_initialization_example PRIVATE memilio ide_secir)
target_compile_options(ide_initialization_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
endif()
2 changes: 2 additions & 0 deletions cpp/models/ide_secir/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ide_secir/infection_state.h"
#include "memilio/config.h"
#include "memilio/epidemiology/age_group.h"
#include "memilio/io/epi_data.h"
#include "memilio/utils/custom_index_array.h"
#include "memilio/utils/time_series.h"

Expand Down Expand Up @@ -358,6 +359,7 @@ class Model
friend class Simulation;
// In set_initial_flows(), we compute initial flows based on RKI data using the (private) compute_flow() function
// which is why it is defined as a friend function.
template <typename DataEntry>
friend IOResult<void> set_initial_flows(Model& model, ScalarType dt, std::string const& path, Date date,
ScalarType scale_confirmed_cases);
};
Expand Down
343 changes: 0 additions & 343 deletions cpp/models/ide_secir/parameters_io.cpp

This file was deleted.

345 changes: 343 additions & 2 deletions cpp/models/ide_secir/parameters_io.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cpp/models/ide_secir/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ namespace isecir
{

/**
* run the simulation in discrete steps and report results.
* Run the simulation in discrete steps and report results.
*/
class Simulation
{

public:
/**
* @brief setup the Simulation for an IDE model.
* @brief Setup the Simulation for an IDE model.
* @param[in] model An instance of the IDE model.
* @param[in] dt Step size of numerical solver.
*/
Expand Down
16 changes: 16 additions & 0 deletions cpp/simulations/IDE_paper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if(MEMILIO_HAS_JSONCPP AND MEMILIO_HAS_HDF5)
add_executable(ide_convergence_rate ide_convergence_rate.cpp)
target_link_libraries(ide_convergence_rate PRIVATE memilio ode_secir ide_secir Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(ide_convergence_rate PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ide_changepoints ide_changepoints.cpp)
target_link_libraries(ide_changepoints PRIVATE memilio ode_secir ide_secir Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(ide_changepoints PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(compute_parameters compute_parameters.cpp)
target_compile_options(compute_parameters PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ide_covid_scenario ide_covid_scenario.cpp)
target_link_libraries(ide_covid_scenario PRIVATE memilio ode_secir ide_secir Boost::filesystem ${HDF5_C_LIBRARIES})
target_compile_options(ide_covid_scenario PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
endif()
97 changes: 97 additions & 0 deletions cpp/simulations/IDE_paper/compute_parameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC)
*
* Authors: Lena Ploetzke
*
* Contact: Martin J. Kuehn <[email protected]>
*
* 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 <iostream>

int main()
{
/** With this file parameters without age distribution can be calculated to match those specified in the
covasim paper (https://doi.org/10.1371/journal.pcbi.1009149).
First, we calculate a weighted average time across the age groups.
If other probabilites than required are given, we calculate the right probabilities.
*/

// Age group sizes are calculated using table number 12411-04-02-4-B from www.regionalstatistik.de for the date 31.12.2020.
const double age_group_sizes[] = {7752706.0, 7581868, 9483430, 10871964, 10070748,
13304542, 10717241, 7436098, 5092743, 843691};
const int total = 83155031;
const int numagegroups = 10;

// Calculate value for probability InfectedSymptomsPerInfectedNoSymptoms.
const double InfectedSymptomsPerInfectedNoSymptoms[] = {0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.90};
double resultInfectedSymptomsPerInfectedNoSymptoms = 0;
for (int i = 0; i < numagegroups; i++) {
resultInfectedSymptomsPerInfectedNoSymptoms += age_group_sizes[i] * InfectedSymptomsPerInfectedNoSymptoms[i];
}
resultInfectedSymptomsPerInfectedNoSymptoms = resultInfectedSymptomsPerInfectedNoSymptoms / total;

std::cout << "InfectedSymptomsPerInfectedNoSymptoms: " << resultInfectedSymptomsPerInfectedNoSymptoms << std::endl;

// Calculate value for probability SeverePerInfectedSymptoms.
const double SeverePerInfectedNoSymptoms[] = {0.00050, 0.00165, 0.00720, 0.02080, 0.03430,
0.07650, 0.13280, 0.20655, 0.24570, 0.24570};
double average_SeverePerInfectedNoSymptoms = 0;
for (int i = 0; i < numagegroups; i++) {
average_SeverePerInfectedNoSymptoms += age_group_sizes[i] * SeverePerInfectedNoSymptoms[i];
}
average_SeverePerInfectedNoSymptoms = average_SeverePerInfectedNoSymptoms / total;
double resultSeverePerInfectedSymptoms =
average_SeverePerInfectedNoSymptoms / resultInfectedSymptomsPerInfectedNoSymptoms;

std::cout << "SeverePerInfectedSymptoms: " << resultSeverePerInfectedSymptoms << std::endl;

// Calculate value for probability CriticalPerSevere.
const double CriticalPerInfectedNoSymptoms[] = {0.00003, 0.00008, 0.00036, 0.00104, 0.00216,
0.00933, 0.03639, 0.08923, 0.17420, 0.17420};
double average_CriticalPerInfectedNoSymptoms = 0;
for (int i = 0; i < numagegroups; i++) {
average_CriticalPerInfectedNoSymptoms += age_group_sizes[i] * CriticalPerInfectedNoSymptoms[i];
}
average_CriticalPerInfectedNoSymptoms = average_CriticalPerInfectedNoSymptoms / total;
double resultCriticalPerSevere = average_CriticalPerInfectedNoSymptoms / average_SeverePerInfectedNoSymptoms;

std::cout << "CriticalPerSevere: " << resultCriticalPerSevere << std::endl;

// Calculate value for probability DeathsPerCritical.
const double DeathsPerInfectedNoSymptoms[] = {0.00002, 0.00002, 0.00010, 0.00032, 0.00098,
0.00265, 0.00766, 0.02439, 0.08292, 0.16190};
double average_DeathsPerInfectedNoSymptoms = 0;
for (int i = 0; i < numagegroups; i++) {
average_DeathsPerInfectedNoSymptoms += age_group_sizes[i] * DeathsPerInfectedNoSymptoms[i];
}
average_DeathsPerInfectedNoSymptoms = average_DeathsPerInfectedNoSymptoms / total;
double resultDeathsPerCritical = average_DeathsPerInfectedNoSymptoms / average_CriticalPerInfectedNoSymptoms;

std::cout << "DeathsPerCritical: " << resultDeathsPerCritical << std::endl;

// ---- Stay times for the ODE model. ----
std::cout << "\nAveraged stay times for the ODE model: " << std::endl;
std::cout << "TimeExposed: " << 4.5 << std::endl;
std::cout << "TimeInfectedNoSymptoms: "
<< 1.1 * resultInfectedSymptomsPerInfectedNoSymptoms +
8. * (1. - resultInfectedSymptomsPerInfectedNoSymptoms)
<< std::endl;
std::cout << "TimeInfectedSymptoms: "
<< 6.6 * resultSeverePerInfectedSymptoms + 8. * (1. - resultSeverePerInfectedSymptoms) << std::endl;
std::cout << "TimeInfectedSevere: " << 1.5 * resultCriticalPerSevere + 18.1 * (1. - resultCriticalPerSevere)
<< std::endl;
std::cout << "TimeInfectedCritical: " << 10.7 * resultDeathsPerCritical + 18.1 * (1. - resultDeathsPerCritical)
<< std::endl;
}
74 changes: 74 additions & 0 deletions cpp/simulations/IDE_paper/get_lognormal_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#############################################################################
# Copyright (C) 2020-2024 German Aerospace Center (DLR-SC)
#
# Authors: Anna Wendler
#
# Contact: Martin J. Kuehn <[email protected]>
#
# 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.
#############################################################################
import numpy as np
from scipy.stats import lognorm


def get_lognormal_parameters(mean, std):
"""
Compute shape and scale parameters to use in lognormal distribution for given mean and standard deviation.
The lognormal distribution we consider in state_age_function.h is based on the implementation in scipy and the parameters
shape and scale are defined accordingly.
"""
variance = std**2

mean_tmp = np.log(mean**2/np.sqrt(mean**2+variance))
variance_tmp = np.log(variance/mean**2 + 1)

shape = np.sqrt(variance_tmp)
scale = np.exp(mean_tmp)

# Test if mean and std are as expected for computed shape and scale parameters.
mean_lognorm, variance_lognorm = lognorm.stats(
shape, loc=0, scale=scale, moments='mv')

mean_test = np.exp(scale**2/2)

if np.abs(mean_lognorm-mean) > 1e-8:
print('Distribution does not have expected mean value.')

if np.abs(np.sqrt(variance_lognorm)-std) > 1e-8:
print('Distribution does not have expected standard deviation.')

return round(shape, 8), round(scale, 8)


def get_weighted_mean(prob_1, stay_time_1, stay_time_2):

weighted_mean = prob_1*stay_time_1 + (1-prob_1)*stay_time_2

return weighted_mean


if __name__ == '__main__':
shape, scale = get_lognormal_parameters(2.183, 1.052)
print(f"{shape:.12f}", f"{scale:.12f}")

weighted_mean = get_weighted_mean(0.793099, 1.1, 8.0)
print(f"{weighted_mean:.6f}")

weighted_mean = get_weighted_mean(0.078643, 6.6, 8.0)
print(f"{weighted_mean:.6f}")

weighted_mean = get_weighted_mean(0.173176, 1.5, 18.1)
print(f"{weighted_mean:.6f}")

weighted_mean = get_weighted_mean(0.387803, 10.7, 18.1)
print(f"{weighted_mean:.6f}")
Loading