|
| 1 | +############################################################################# |
| 2 | +# Copyright (C) 2020-2024 MEmilio |
| 3 | +# |
| 4 | +# Authors: Martin J. Kuehn, Maximilian Betz |
| 5 | +# |
| 6 | +# Contact: Martin J. Kuehn <[email protected]> |
| 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 | +import os |
| 22 | +from datetime import date, datetime |
| 23 | + |
| 24 | +import matplotlib.pyplot as plt |
| 25 | +import numpy as np |
| 26 | +import pandas as pd |
| 27 | + |
| 28 | +from memilio.simulation import AgeGroup, Damping, SimulationDay |
| 29 | +from memilio.simulation.osecirvvs import InfectionState |
| 30 | +from memilio.simulation.osecirvvs import Model, simulate |
| 31 | + |
| 32 | + |
| 33 | +def run_secirvvs_simulation(show_plot=True): |
| 34 | + """ |
| 35 | + Runs the c++ SECIRVVS model using a single age group |
| 36 | + and plots the results |
| 37 | + """ |
| 38 | + |
| 39 | + t0 = 0 |
| 40 | + tmax = 30 # number of days to simulate |
| 41 | + dt = 0.1 |
| 42 | + num_groups = 1 |
| 43 | + |
| 44 | + # Initialize Parameters |
| 45 | + model = Model(num_groups) |
| 46 | + |
| 47 | + # set parameters |
| 48 | + for i in range(num_groups): |
| 49 | + # Initial number of peaople in each compartment |
| 50 | + model.populations[AgeGroup(i), InfectionState.ExposedNaive] = 10 |
| 51 | + model.populations[AgeGroup( |
| 52 | + i), InfectionState.ExposedImprovedImmunity] = 11 |
| 53 | + model.populations[AgeGroup( |
| 54 | + i), InfectionState.ExposedPartialImmunity] = 12 |
| 55 | + model.populations[AgeGroup( |
| 56 | + i), InfectionState.InfectedNoSymptomsNaive] = 13 |
| 57 | + model.populations[AgeGroup( |
| 58 | + i), InfectionState.InfectedNoSymptomsNaiveConfirmed] = 13 |
| 59 | + model.populations[AgeGroup( |
| 60 | + i), InfectionState.InfectedNoSymptomsPartialImmunity] = 14 |
| 61 | + model.populations[AgeGroup( |
| 62 | + i), InfectionState.InfectedNoSymptomsPartialImmunityConfirmed] = 14 |
| 63 | + model.populations[AgeGroup( |
| 64 | + i), InfectionState.InfectedNoSymptomsImprovedImmunity] = 15 |
| 65 | + model.populations[AgeGroup( |
| 66 | + i), InfectionState.InfectedNoSymptomsImprovedImmunityConfirmed] = 15 |
| 67 | + model.populations[AgeGroup( |
| 68 | + i), InfectionState.InfectedSymptomsNaive] = 5 |
| 69 | + model.populations[AgeGroup( |
| 70 | + i), InfectionState.InfectedSymptomsNaiveConfirmed] = 5 |
| 71 | + model.populations[AgeGroup( |
| 72 | + i), InfectionState.InfectedSymptomsPartialImmunity] = 6 |
| 73 | + model.populations[AgeGroup( |
| 74 | + i), InfectionState.InfectedSymptomsPartialImmunityConfirmed] = 6 |
| 75 | + model.populations[AgeGroup( |
| 76 | + i), InfectionState.InfectedSymptomsImprovedImmunity] = 7 |
| 77 | + model.populations[AgeGroup( |
| 78 | + i), InfectionState.InfectedSymptomsImprovedImmunityConfirmed] = 7 |
| 79 | + model.populations[AgeGroup(i), InfectionState.InfectedSevereNaive] = 8 |
| 80 | + model.populations[AgeGroup( |
| 81 | + i), InfectionState.InfectedSevereImprovedImmunity] = 1 |
| 82 | + model.populations[AgeGroup( |
| 83 | + i), InfectionState.InfectedSeverePartialImmunity] = 2 |
| 84 | + model.populations[AgeGroup( |
| 85 | + i), InfectionState.InfectedCriticalNaive] = 3 |
| 86 | + model.populations[AgeGroup( |
| 87 | + i), InfectionState.InfectedCriticalPartialImmunity] = 4 |
| 88 | + model.populations[AgeGroup( |
| 89 | + i), InfectionState.InfectedCriticalImprovedImmunity] = 5 |
| 90 | + model.populations[AgeGroup( |
| 91 | + i), InfectionState.SusceptibleImprovedImmunity] = 6 |
| 92 | + model.populations[AgeGroup( |
| 93 | + i), InfectionState.SusceptiblePartialImmunity] = 7 |
| 94 | + model.populations[AgeGroup(i), InfectionState.DeadNaive] = 0 |
| 95 | + model.populations[AgeGroup(i), InfectionState.DeadPartialImmunity] = 0 |
| 96 | + model.populations[AgeGroup(i), InfectionState.DeadImprovedImmunity] = 0 |
| 97 | + model.populations.set_difference_from_group_total_AgeGroup( |
| 98 | + (AgeGroup(i), InfectionState.SusceptibleNaive), 1000) |
| 99 | + |
| 100 | + model.parameters.ICUCapacity.value = 100 |
| 101 | + model.parameters.TestAndTraceCapacity.value = 0.0143 |
| 102 | + model.parameters.DailyFirstVaccination.resize_SimulationDay( |
| 103 | + SimulationDay(tmax + 1)) |
| 104 | + model.parameters.DailyFullVaccination.resize_SimulationDay( |
| 105 | + SimulationDay(tmax + 1)) |
| 106 | + daily_vaccinations = 10 |
| 107 | + for i, num_vaccinations in enumerate(range(0, daily_vaccinations * (tmax + 1), daily_vaccinations)): |
| 108 | + model.parameters.DailyFirstVaccination[AgeGroup( |
| 109 | + 0), SimulationDay(i)] = num_vaccinations |
| 110 | + model.parameters.DailyFullVaccination[AgeGroup( |
| 111 | + 0), SimulationDay(i)] = num_vaccinations |
| 112 | + |
| 113 | + # contact patterns |
| 114 | + baseline = np.ones((num_groups, num_groups)) * 0.5 |
| 115 | + np.fill_diagonal(baseline, 5.0) |
| 116 | + model.parameters.ContactPatterns.cont_freq_mat[0].baseline = baseline |
| 117 | + model.parameters.ContactPatterns.cont_freq_mat.add_damping(Damping( |
| 118 | + coeffs=np.ones((num_groups, num_groups)) * 0.3, t=5.0, level=0, type=0)) |
| 119 | + |
| 120 | + # times |
| 121 | + model.parameters.TimeInfectedSymptoms[AgeGroup(0)] = 7 |
| 122 | + model.parameters.TimeInfectedSevere[AgeGroup(0)] = 6 |
| 123 | + model.parameters.TimeInfectedCritical[AgeGroup(0)] = 7 |
| 124 | + |
| 125 | + # probabilities |
| 126 | + model.parameters.TransmissionProbabilityOnContact[AgeGroup(0)] = 0.15 |
| 127 | + model.parameters.RelativeTransmissionNoSymptoms[AgeGroup(0)] = 0.5 |
| 128 | + # The precise value between Risk* (situation under control) and MaxRisk* (situation not under control) |
| 129 | + # depends on incidence and test and trace capacity |
| 130 | + model.parameters.RiskOfInfectionFromSymptomatic[AgeGroup(0)] = 0.0 |
| 131 | + model.parameters.MaxRiskOfInfectionFromSymptomatic[AgeGroup(0)] = 0.4 |
| 132 | + model.parameters.RecoveredPerInfectedNoSymptoms[AgeGroup(0)] = 0.2 |
| 133 | + model.parameters.SeverePerInfectedSymptoms[AgeGroup(0)] = 0.1 |
| 134 | + model.parameters.CriticalPerSevere[AgeGroup(0)] = 0.1 |
| 135 | + model.parameters.DeathsPerCritical[AgeGroup(0)] = 0.1 |
| 136 | + |
| 137 | + model.parameters.ReducExposedPartialImmunity[AgeGroup(0)] = 0.8 |
| 138 | + model.parameters.ReducExposedImprovedImmunity[AgeGroup(0)] = 0.331 |
| 139 | + model.parameters.ReducInfectedSymptomsPartialImmunity[AgeGroup(0)] = 0.65 |
| 140 | + model.parameters.ReducInfectedSymptomsImprovedImmunity[AgeGroup(0)] = 0.243 |
| 141 | + model.parameters.ReducInfectedSevereCriticalDeadPartialImmunity[AgeGroup( |
| 142 | + 0)] = 0.1 |
| 143 | + model.parameters.ReducInfectedSevereCriticalDeadImprovedImmunity[AgeGroup( |
| 144 | + 0)] = 0.091 |
| 145 | + model.parameters.ReducTimeInfectedMild[AgeGroup(0)] = 0.9 |
| 146 | + |
| 147 | + model.parameters.Seasonality.value = 0.2 |
| 148 | + |
| 149 | + model.apply_constraints() |
| 150 | + |
| 151 | + # Run Simulation |
| 152 | + result = simulate(t0, tmax, dt, model) |
| 153 | + |
| 154 | + # # interpolate results |
| 155 | + # result = interpolate_simulation_result(result) |
| 156 | + |
| 157 | + print(result.get_last_value()) |
| 158 | + |
| 159 | + |
| 160 | +if __name__ == "__main__": |
| 161 | + arg_parser = argparse.ArgumentParser( |
| 162 | + 'osecirvvs_simple', |
| 163 | + description='Simple example demonstrating the setup and simulation of the SECIRVVS model with a single age group.') |
| 164 | + args = arg_parser.parse_args() |
| 165 | + run_secirvvs_simulation(**args.__dict__) |
0 commit comments