model.h Source File

CPP API: model.h Source File
sde_seirvv/model.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Nils Wassmuth, Rene Schmieding, Martin J. Kuehn
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 
21 #ifndef MIO_SDE_SEIRVV_MODEL_H
22 #define MIO_SDE_SEIRVV_MODEL_H
23 
28 #include "sde_seirvv/parameters.h"
29 
30 namespace mio
31 {
32 namespace sseirvv
33 {
34 
35 /********************
36  * define the model *
37  ********************/
38 
48 
49 template <typename FP>
50 class Model
51  : public mio::StochasticModel<FP, InfectionState, mio::Populations<FP, InfectionState>, Parameters<FP>, Flows>
52 {
54 
55 public:
57  : Base(typename Base::Populations({InfectionState::Count}, 0.0), typename Base::ParameterSet())
58  {
59  }
60 
61  void get_flows(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
62  Eigen::Ref<Eigen::VectorX<FP>> flows) const
63  {
64  const auto& params = this->parameters;
65  params.template get<ContactPatterns<FP>>().get_matrix_at(SimulationTime<FP>(t))(0, 0);
66  FP coeffStoIV1 = params.template get<ContactPatterns<FP>>().get_matrix_at(SimulationTime<FP>(t))(0, 0) *
67  params.template get<TransmissionProbabilityOnContactV1<FP>>() / this->populations.get_total();
68  FP coeffStoIV2 = params.template get<ContactPatterns<FP>>().get_matrix_at(SimulationTime<FP>(t))(0, 0) *
69  params.template get<TransmissionProbabilityOnContactV2<FP>>() / this->populations.get_total();
70 
71  flows[this->template get_flat_flow_index<InfectionState::Susceptible, InfectionState::ExposedV1>()] =
72  coeffStoIV1 * y[(size_t)InfectionState::Susceptible] * pop[(size_t)InfectionState::InfectedV1];
73 
74  flows[this->template get_flat_flow_index<InfectionState::Susceptible, InfectionState::ExposedV2>()] =
75  coeffStoIV2 * y[(size_t)InfectionState::Susceptible] *
76  (pop[(size_t)InfectionState::InfectedV1V2] + pop[(size_t)InfectionState::InfectedV2]);
77 
78  flows[this->template get_flat_flow_index<InfectionState::ExposedV1, InfectionState::InfectedV1>()] =
79  (1.0 / params.template get<TimeExposedV1<FP>>()) * y[(size_t)InfectionState::ExposedV1];
80 
81  flows[this->template get_flat_flow_index<InfectionState::ExposedV2, InfectionState::InfectedV2>()] =
82  (1.0 / params.template get<TimeExposedV2<FP>>()) * y[(size_t)InfectionState::ExposedV2];
83 
84  flows[this->template get_flat_flow_index<InfectionState::InfectedV1, InfectionState::RecoveredV1>()] =
85  (1.0 / params.template get<TimeInfectedV1<FP>>()) * y[(size_t)InfectionState::InfectedV1];
86 
87  flows[this->template get_flat_flow_index<InfectionState::InfectedV2, InfectionState::RecoveredV2>()] =
88  (1.0 / params.template get<TimeInfectedV2<FP>>()) * y[(size_t)InfectionState::InfectedV2];
89 
90  flows[this->template get_flat_flow_index<InfectionState::RecoveredV1, InfectionState::ExposedV1V2>()] =
91  coeffStoIV2 * y[(size_t)InfectionState::RecoveredV1] *
92  (pop[(size_t)InfectionState::InfectedV1V2] + pop[(size_t)InfectionState::InfectedV2]);
93 
94  flows[this->template get_flat_flow_index<InfectionState::ExposedV1V2, InfectionState::InfectedV1V2>()] =
95  (1.0 / params.template get<TimeExposedV2<FP>>()) * y[(size_t)InfectionState::ExposedV1V2];
96 
97  flows[this->template get_flat_flow_index<InfectionState::InfectedV1V2, InfectionState::RecoveredV1V2>()] =
98  (1.0 / params.template get<TimeInfectedV2<FP>>()) * y[(size_t)InfectionState::InfectedV1V2];
99  }
100 
101  void get_noise(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
102  Eigen::Ref<Eigen::VectorX<FP>> noise) const
103  {
104  Eigen::VectorX<FP> flows(Flows::size());
105  get_flows(pop, y, t, flows);
106  flows = flows.array().sqrt() * Base::white_noise(Flows::size()).array();
107  this->get_derivatives(flows, noise);
108  }
109 };
110 
111 } // namespace sseirvv
112 } // namespace mio
113 
114 #endif // MIO_SDE_SEIRVV_MODEL_H
A class template for compartment populations.
Definition: populations.h:55
double simulation time.
Definition: damping.h:58
A CompartmentalModel with an additional get_noise member.
Definition: stochastic_model.h:35
auto white_noise(Eigen::Index size) const
Sample a vector of independent standard normal distributed values from the model's RNG.
Definition: stochastic_model.h:66
Definition: sde_seirvv/model.h:52
void get_noise(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> noise) const
Calculate random changes to the population at a certain time point.
Definition: sde_seirvv/model.h:101
void get_flows(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> flows) const
Definition: sde_seirvv/model.h:61
Model()
Definition: sde_seirvv/model.h:56
Parameters of stochastic SEIRVV model.
Definition: sde_seirvv/parameters.h:161
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
A Flow defines a possible transition between two Compartments in a FlowModel.
Definition: flow.h:33
Collection of types. Each type is mapped to an index of type size_t.
Definition: type_list.h:32
static constexpr size_t size()
returns the number of Types in TypeList
Definition: type_list.h:45