|
| 1 | +############################################################################# |
| 2 | +# Copyright (C) 2020-2025 MEmilio |
| 3 | +# |
| 4 | +# Authors: Maximilian Betz |
| 5 | +# |
| 6 | +# Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> |
| 7 | +# |
| 8 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +# you may not use this file except in compliance with the License. |
| 10 | +# You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | +############################################################################# |
| 20 | +import argparse |
| 21 | + |
| 22 | +import numpy as np |
| 23 | + |
| 24 | +from memilio.simulation import AgeGroup, Damping |
| 25 | +from memilio.simulation.ssirs import InfectionState as State |
| 26 | +from memilio.simulation.ssirs import ( |
| 27 | + Model, simulate_stochastic, interpolate_simulation_result) |
| 28 | + |
| 29 | + |
| 30 | +def run_sde_sirs_simulation(): |
| 31 | + """Runs SDE SIRS model""" |
| 32 | + |
| 33 | + tmax = 5. # simulation time frame |
| 34 | + dt = 0.001 |
| 35 | + |
| 36 | + # Initialize Model |
| 37 | + model = Model() |
| 38 | + |
| 39 | + # Mean time in Infected compartment |
| 40 | + model.parameters.TimeInfected.value = 10. |
| 41 | + model.parameters.TimeImmune.value = 100. |
| 42 | + |
| 43 | + model.parameters.TransmissionProbabilityOnContact.value = 1. |
| 44 | + |
| 45 | + # Initial number of people per compartment |
| 46 | + total_population = 10000 |
| 47 | + model.populations[State.Infected] = 100 |
| 48 | + model.populations[State.Recovered] = 1000 |
| 49 | + model.populations.set_difference_from_total( |
| 50 | + (State.Susceptible), total_population) |
| 51 | + |
| 52 | + model.parameters.ContactPatterns.baseline = np.ones( |
| 53 | + (1, 1)) * 20.7 |
| 54 | + model.parameters.ContactPatterns.minimum = np.zeros( |
| 55 | + (1, 1)) |
| 56 | + model.parameters.ContactPatterns.add_damping( |
| 57 | + Damping(coeffs=np.r_[0.6], t=2, level=0, type=0)) |
| 58 | + |
| 59 | + # Check parameter constraints |
| 60 | + model.check_constraints() |
| 61 | + |
| 62 | + # Run Simulation |
| 63 | + result = simulate_stochastic(0., days, dt, model) |
| 64 | + |
| 65 | + # Interpolate results |
| 66 | + result = interpolate_simulation_result(result) |
| 67 | + |
| 68 | + result.print_table(False, ["Susceptible", "Infected", "Recovered"], 16, 5) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + arg_parser = argparse.ArgumentParser( |
| 73 | + 'sde_sirs_simple', |
| 74 | + description='Simple example demonstrating the setup and simulation of the SDE SIRS model.') |
| 75 | + args = arg_parser.parse_args() |
| 76 | + run_sde_sirs_simulation() |
0 commit comments