-
Notifications
You must be signed in to change notification settings - Fork 16
/
ode_seir_simple.py
84 lines (68 loc) · 2.79 KB
/
ode_seir_simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#############################################################################
# Copyright (C) 2020-2024 MEmilio
#
# Authors: Martin J. Kuehn, Wadim Koslow, Daniel Abele
#
# 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 argparse
import numpy as np
from memilio.simulation import AgeGroup, Damping
from memilio.simulation.oseir import Index_InfectionState
from memilio.simulation.oseir import InfectionState as State
from memilio.simulation.oseir import (Model, interpolate_simulation_result,
simulate)
def run_ode_seir_simulation():
"""
Runs the c++ ODE SEIR model
"""
# Define population of age groups
populations = [83000]
days = 100 # number of days to simulate
dt = 0.1
# Initialize Parameters
num_groups = 1
model = Model(num_groups)
A0 = AgeGroup(0)
# Compartment transition duration
model.parameters.TimeExposed[A0] = 5.2
model.parameters.TimeInfected[A0] = 6.
# Compartment transition propabilities
model.parameters.TransmissionProbabilityOnContact[A0] = 1.
# Initial number of people in each compartment
model.populations[A0, State.Exposed] = 100
model.populations[A0, State.Infected] = 50
model.populations[A0, State.Recovered] = 10
model.populations.set_difference_from_total(
(A0, State.Susceptible), populations[0])
model.parameters.ContactPatterns.cont_freq_mat[0].baseline = np.ones(
(num_groups, num_groups))
model.parameters.ContactPatterns.cont_freq_mat[0].minimum = np.zeros(
(num_groups, num_groups))
model.parameters.ContactPatterns.cont_freq_mat.add_damping(
Damping(coeffs=np.r_[0.9], t=30.0, level=0, type=0))
# Check logical constraints to parameters
model.check_constraints()
# Run Simulation
result = simulate(0, days, dt, model)
# interpolate results
result = interpolate_simulation_result(result)
print(result.get_last_value())
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(
'ode_seir_simple',
description='Simple example demonstrating the setup and simulation of the ODE SEIR model.')
args = arg_parser.parse_args()
run_ode_seir_simulation()