Skip to content

Commit f859b60

Browse files
committed
formatting and typos
1 parent 2f2b2a6 commit f859b60

12 files changed

Lines changed: 158 additions & 51 deletions

.clang-format

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
SortIncludes: false
4+
ColumnLimit: 120
5+
AlignTrailingComments: false
6+
AccessModifierOffset: -4
7+
AlignConsecutiveAssignments: true
8+
ReflowComments: true
9+
BraceWrapping:
10+
AfterClass: true
11+
AfterFunction: true
12+
BeforeElse: true
13+
BeforeCatch: true
14+
AfterNamespace: true
15+
AfterEnum: true
16+
BreakBeforeBraces: "Custom"
17+
PointerAlignment: Left
18+
AllowShortFunctionsOnASingleLine: false
19+
NamespaceIndentation: None
20+
BreakConstructorInitializersBeforeComma: true
21+
AlwaysBreakTemplateDeclarations: Yes
22+
AllowShortLambdasOnASingleLine: Empty

cpp-tutorials/exercises/exercise01.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
int main()
66
{
7-
// MEmilio implements various models based on ordinary differential equations (ODEs). ODE-based models are a subclass of compartmental models in which individuals are grouped into subpopulations called compartments.
7+
// MEmilio implements various models based on ordinary differential equations (ODEs). ODE-based models are a
8+
// subclass of compartmental models in which individuals are grouped into subpopulations called compartments.
89

9-
// In this tutorial we will setup and run MEmilio's ODE-based SECIR-type model. This model is particularly suited for pathogens with pre- or asymptomatic infection states and when severe or critical symptoms are possible. The model assumes perfect immunity after recovery. The used infection states or compartments are Susceptible (S), Exposed(E), Non-symptomatically Infected (Ins), Symptomatically Infected (Isy), Severely Infected (Isev), Critically Infected (Icri), Dead (D) and Recovered (R). The transitions are depicted in the following figure.
10+
// In this tutorial we will setup and run MEmilio's ODE-based SECIR-type model. This model is particularly
11+
// suited for pathogens with pre- or asymptomatic infection states and when severe or critical symptoms are possible.
12+
// The model assumes perfect immunity after recovery. The used infection states or compartments are Susceptible (S),
13+
// Exposed(E), Non-symptomatically Infected (Ins), Symptomatically Infected (Isy), Severely Infected (Isev),
14+
// Critically Infected (Icri), Dead (D) and Recovered (R). The transitions are depicted in the following figure.
1015

1116
// *** Set up model. ***
12-
// We need to specify basic parameters. In this tutorial, we use a simple model without spatial resolution and with only one age group.
17+
// We need to specify basic parameters. In this tutorial, we use a simple model without spatial resolution and
18+
// with only one age group.
1319
size_t num_agegroups = 1;
14-
// We first define the `total_population` size and the simulation horizong through the start day `t0`, and the simulation's end point `tmax`. By default, the ODE is solved with adaptive time stepping and the initial time step is `dt`.
20+
// We first define the `total_population` size and the simulation horizong through the start day `t0`, and the
21+
// simulation's end point `tmax`. By default, the ODE is solved with adaptive time stepping and the initial time step is `dt`.
1522
ScalarType total_population = 100000;
1623
ScalarType t0 = 0;
1724
ScalarType tmax = 100;
@@ -20,7 +27,9 @@ int main()
2027
// Create model
2128
mio::osecir::Model<ScalarType> model(num_agegroups);
2229

23-
// Next, we have to set the epidemiological model parameters which include the average stay times per infection state, the state transition probabilities, and the contact frequency. A list of all parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html. The parameters can be set as follows:
30+
// Next, we have to set the epidemiological model parameters which include the average stay times per infection
31+
// state, the state transition probabilities, and the contact frequency. A list of all parameters can be found
32+
// at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html. The parameters can be set as follows:
2433
// Set infection state stay times (in days)
2534
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<ScalarType>>() = 2.;
2635
model.parameters.get<mio::osecir::TimeInfectedSymptoms<ScalarType>>() = 6.;
@@ -42,15 +51,21 @@ int main()
4251

4352
// EXERCISE: Please set the average time individuals spend in the exposed state (TimeExposed) to 4 days
4453

45-
// In addition to the parameters, the initial number of individuals in each compartment has to be set. If a compartment is not set, its initial value is zero by default. In this example, we start our simulation with 1 % of the population initially infected, distributing them equally to the `Exposed` and the `InfectedNoSymptoms` state, where the latter contains pre- and asymptomatic infectious individuals. With the last line, we set the remaining part of the population (99%) to be susceptible.
54+
// In addition to the parameters, the initial number of individuals in each compartment has to be set. If a
55+
// compartment is not set, its initial value is zero by default. In this example, we start our simulation with 1 %
56+
// of the population initially infected, distributing them equally to the `Exposed` and the `InfectedNoSymptoms`
57+
// state, where the latter contains pre- and asymptomatic infectious individuals. With the last line,
58+
// we set the remaining part of the population (99%) to be susceptible.
4659
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 0.005 * total_population;
4760
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = 0.005 * total_population;
4861
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
4962
total_population);
5063

5164
// EXERCISE: Please set 2% of the population initially infected. The initially infected should be distributed to the compartpartments as follows: 0.5% is initially exposed (state `Exposed`), 0.5% is non-symptomatically infected (state `InfectedNosymptoms`) and 1% is symptomatically infected (state `InfectedSymptoms`).
5265

53-
// To check that all initial parameter and compartmental values are in a meaningful range, MEmilio provides the `check_constraints` function. If a value exceeds its meaningful range, a warning is printed and the function returns `True`, otherwise it returns `False`.
66+
// To check that all initial parameter and compartmental values are in a meaningful range, MEmilio provides the
67+
// `check_constraints` function. If a value exceeds its meaningful range, a warning is printed and the function
68+
// returns `True`, otherwise it returns `False`.
5469
model.check_constraints();
5570

5671
// *** Simulate model. ***

cpp-tutorials/exercises/exercise03.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
int main()
66
{
7-
// In the previous tutorial, we created, initialized and simulated MEmilio's ODE-based SECIR-type model with one (age) group. In this tutorial, we will show how to incorporate non-pharmaceutical interventions (NPIs) through the use of `Dampings` in the ODE-based SECIR-type model.
7+
// In the previous tutorial, we created, initialized and simulated MEmilio's ODE-based SECIR-type model with one
8+
// (age) group. In this tutorial, we will show how to incorporate non-pharmaceutical interventions (NPIs) through
9+
// the use of `Dampings` in the ODE-based SECIR-type model.
810

911
// *** Set up model. ***
10-
// First we create and initialize a SECIR-type model with one age group. For a detailed description on taht, see Tutorial 1.
12+
// First we create and initialize a SECIR-type model with one age group. For a detailed description, see Tutorial 1.
1113
size_t num_agegroups = 1;
1214
ScalarType total_population = 100000;
1315
ScalarType t0 = 0;
@@ -39,13 +41,22 @@ int main()
3941

4042
// EXERCISE: Please set the model's contact frequency to 10.
4143

42-
// After the model initialization, we add a contact reduction (`Damping`) that represents an NPI like e.g. mask wearing or social distancing. Dampings are a factor applied to the contact frequency and can be added to the model at fixed simulation time points before simulating. They have a *Level* and a *Type*. A damping with a given level and type replaces the previously active one with the same level and type, while all currently active dampings of one level and different types are summed up. If two dampings have different levels (independent of the type) they are combined multiplicatively. In the following we apply a `Damping` of 0.9 after 10 days and another damping of 0.6 after 20 days which means that the contacts are reduced by 10% and 40%, respectively. To always retain a minimum level of contacts, a minimum contact frequency can be set that is never deceeded. In our example we set this minimum contact rate to 0.
44+
// After the model initialization, we add a contact reduction (`Damping`) that represents an NPI like
45+
// mask wearing or social distancing. Dampings are a factor applied to the contact frequency and can be added
46+
// to the model at fixed simulation time points before simulating. They have a *Level* and a *Type*.
47+
// A damping with a given level and type replaces the previously active one with the same level and type, while
48+
// all currently active dampings of one level and different types are summed up. If two dampings have different
49+
// levels (independent of the type) they are combined multiplicatively. In the following we apply a `Damping`
50+
// of 0.9 after 10 days and another damping of 0.6 after 20 days which means that the contacts are reduced
51+
// by 10% and 40%, respectively. To always retain a minimum level of contacts, a minimum contact frequency can
52+
// be set that is never deceeded. In our example we set this minimum contact rate to 0.
4353
contact_matrix[0].add_damping(0.9, mio::SimulationTime<ScalarType>(10.));
4454
contact_matrix[0].add_damping(0.6, mio::SimulationTime<ScalarType>(20.));
4555

4656
//EXERCISE: Please create a damping that replaces the 10% reduction after 10 days by a 20% reduction. Additionally, add a damping after 40 days that increases the contact rate by 50%.
4757

48-
// Again, we start with 0.5% of the population initially in `Exposed` and 0.5% initially in `InfectedNoSymptoms` while the remaining 99% is `Susceptible`.
58+
// Again, we start with 0.5% of the population initially in `Exposed` and 0.5% initially in `InfectedNoSymptoms`
59+
// while the remaining 99% is `Susceptible`.
4960
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 0.005 * total_population;
5061
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = 0.005 * total_population;
5162
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},

cpp-tutorials/exercises/exercise07.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,31 @@
88

99
int main()
1010
{
11-
// In the previous tutorials, we saw how to set up and run an age-resolved ODE-based SECIR-type model. However, one limiting assumption of simple ODE-based models is the assumption of homogenous mixing within the population. To overcome this limitation and incorporate spatial heterogeneity, in this example we show how to use MEmilio's graph-based metapopulation model. This model realizes mobility between regions via graph edges, while every region is represented by a graph node containing it's own ODE-based model.
11+
// In the previous tutorials, we saw how to set up and run an age-resolved ODE-based SECIR-type model.
12+
// However, one limiting assumption of simple ODE-based models is the assumption of homogenous mixing within
13+
// the population. To overcome this limitation and incorporate spatial heterogeneity, in this example we show
14+
// how to use MEmilio's graph-based metapopulation model. This model realizes mobility between regions via
15+
// graph edges, while every region is represented by a graph node containing it's own ODE-based model.
1216

1317
// *** Set up model. ***
1418
// We set the simulation start time `t0`, the end time `tmax` and the initial step size `dt` as:
1519
ScalarType t0 = 0;
1620
ScalarType tmax = 100;
1721
ScalarType dt = 0.1;
1822

19-
// Next, we need to specify the parameters. We will initialize a metapopulation model with two regions. The total population as well as the epidemiological parameters will be the same for both regions.
23+
// Next, we need to specify the parameters. We will initialize a metapopulation model with two regions.
24+
// The total population as well as the epidemiological parameters will be the same for both regions.
2025
ScalarType total_population_per_region = 100000;
2126

2227
// We use a model with three age groups for both regions:
2328
size_t num_agegroups = 3;
2429
// Create model with three age groups
2530
mio::osecir::Model<ScalarType> model(num_agegroups);
2631

27-
// Now, we have to set the epidemiological model parameters which are dependent on age group. A list of all parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html.
28-
// We choose an increasing risk of severe and critical infections for age group 2 and 3 compared to age group 1. The other parameters are equal for all age groups.
32+
// Now, we have to set the epidemiological model parameters which are dependent on age group. A list of all
33+
// parameters can be found at https://memilio.readthedocs.io/en/latest/cpp/models/osecir.html.
34+
// We choose an increasing risk of severe and critical infections for age group 2 and 3 compared to age group 1.
35+
// The other parameters are equal for all age groups.
2936

3037
for (size_t i = 0; i < num_agegroups; i++) {
3138
// Set infection state stay times (in days)
@@ -65,7 +72,11 @@ int main()
6572
auto model_region1 = model;
6673
auto model_region2 = model;
6774

68-
// In the graph-based metapopulation model, every graph node gets it's own ODE-based model which is copied when adding a graph node and handing the model to it as parameter. Therefore we can choose different initial conditions (as well as differing parameters) for different graph nodes. In our example, we simulate two regions with only one region having initially infected individuals. We choose 1% initially infected for that region while the other region starts with a totally susceptible population.
75+
// In the graph-based metapopulation model, every graph node gets it's own ODE-based model which is copied when
76+
// adding a graph node and handing the model to it as parameter. Therefore we can choose different initial conditions
77+
// (as well as differing parameters) for different graph nodes. In our example, we simulate two regions with only one
78+
// region having initially infected individuals. We choose 1% initially infected for that region while the other
79+
// region starts with a totally susceptible population.
6980
// The model compartments for the first node are initialized via:
7081
for (size_t i = 0; i < num_agegroups; i++) {
7182
model_region1.populations[{mio::AgeGroup(i), mio::osecir::InfectionState::Exposed}] =
@@ -86,9 +97,11 @@ int main()
8697
graph.add_node(0, model_region1, t0, dt);
8798

8899
//EXERCISE: Please add the second node to the graph.
89-
90-
// If we would simulate the graph-based metapopulation model now, we would just have two independent ODE-based SECIR-type models running with different initial conditions. In reality, there is usually exchange between regions through individuals travelling or commuting from one region to another. This can be realized via graph edges.
91-
// We here use a symmetric mobility i.e. we have the same number of individuals that travel from node 0 to node 1 as vice versa. We let 10% of the population commute via the edges twice a day.
100+
// If we would simulate the graph-based metapopulation model now, we would just have two independent ODE-based
101+
// SECIR-type models running with different initial conditions. In reality, there is usually exchange between
102+
// regions through individuals travelling or commuting from one region to another. This can be realized via graph edges.
103+
// We here use a symmetric mobility i.e. we have the same number of individuals that travel from node 0 to node 1
104+
// as vice versa. We let 10% of the population commute via the edges twice a day.
92105
graph.add_edge(
93106
0, 1, Eigen::VectorX<ScalarType>::Constant((size_t)mio::osecir::InfectionState::Count * num_agegroups, 0.1));
94107

cpp-tutorials/exercises/exercise10.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//
1313
// Large-scale studies, such as the POLYMOD project, have measured social contact patterns across different
1414
// locations (like home, school, work, and others) in various countries. For instance, see
15-
// Mossong J, Hens N, Jit M, Beutels P, Auranen K, et al. (2008) Social Contacts and Mixing Patterns Relevant to the Spread of Infectious Diseases.
16-
// PLoS Med 5(3): e74. https://doi.org/10.1371/journal.pmed.0050074
17-
// Prem K, Cook AR, Jit M (2017) Projecting social contact matrices in 152 countries using contact surveys and demographic data.
18-
// PLoS Comput Biol 13(9): e1005697. https://doi.org/10.1371/journal.pcbi.1005697
15+
// Mossong J, Hens N, Jit M, Beutels P, Auranen K, et al. (2008) Social Contacts and Mixing Patterns Relevant to
16+
// the Spread of Infectious Diseases. PLoS Med 5(3): e74. https://doi.org/10.1371/journal.pmed.0050074
17+
// Prem K, Cook AR, Jit M (2017) Projecting social contact matrices in 152 countries using contact surveys and
18+
// demographic data. PLoS Comput Biol 13(9): e1005697. https://doi.org/10.1371/journal.pcbi.1005697
1919
//
2020
// In this tutorial, we extend the approach from Tutorial 3 by splitting the contact matrix into
2121
// location-specific contact matrices using ContactMatrixGroup. This allows us to apply NPIs to individual

cpp-tutorials/exercises/exercise_ide.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int main()
8181
// After having initialized the model, we now set the epidemiological parameters.
8282
// We start with setting the transition distributions between the InfectionStates. With this, we define the times
8383
// individuals spend on average in the respective InfectionStates.
84-
// We start by defining a SmootherCosine object that is defined by an initial distribtion parameter.
84+
// We start by defining a SmootherCosine object that is defined by an initial distribution parameter.
8585
mio::SmootherCosine<ScalarType> smoothcos(4.0);
8686
// This is passed to a StateAgeFunctionWrapper object which is the type of oject used within the model to allow
8787
// for variable transition distributions.

0 commit comments

Comments
 (0)