model.h Source File

CPP API: model.h Source File
sde_sir/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_SIR_MODEL_H
22 #define MIO_SDE_SIR_MODEL_H
23 
28 #include "sde_sir/parameters.h"
29 
30 namespace mio
31 {
32 namespace ssir
33 {
34 
35 /********************
36  * define the model *
37  ********************/
38 
41 
42 template <typename FP>
43 class Model
44  : public mio::StochasticModel<FP, InfectionState, mio::Populations<FP, InfectionState>, Parameters<FP>, Flows>
45 {
46 public:
48 
50  : Base(typename Base::Populations({InfectionState::Count}, 0.), typename Base::ParameterSet())
51  {
52  }
53 
54  void get_flows(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
55  Eigen::Ref<Eigen::VectorX<FP>> flows) const
56  {
57  auto& params = Base::parameters;
58  FP coeffStoI = params.template get<ContactPatterns<FP>>().get_matrix_at(SimulationTime<FP>(t))(0, 0) *
59  params.template get<TransmissionProbabilityOnContact<FP>>() / this->populations.get_total();
60 
61  flows[Base::template get_flat_flow_index<InfectionState::Susceptible, InfectionState::Infected>()] =
62  coeffStoI * y[(size_t)InfectionState::Susceptible] * pop[(size_t)InfectionState::Infected];
63  flows[Base::template get_flat_flow_index<InfectionState::Infected, InfectionState::Recovered>()] =
64  (1.0 / params.template get<TimeInfected<FP>>()) * y[(size_t)InfectionState::Infected];
65  }
66 
67  void get_noise(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
68  Eigen::Ref<Eigen::VectorX<FP>> noise) const
69  {
70  Eigen::VectorX<FP> flows(Flows::size());
71  get_flows(pop, y, t, flows);
72  flows = flows.array().sqrt() * Base::white_noise(Flows::size()).array();
73  this->get_derivatives(flows, noise);
74  }
75 };
76 
77 } // namespace ssir
78 } // namespace mio
79 
80 #endif // MIO_SDE_SIR_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_sir/model.h:45
Model()
Definition: sde_sir/model.h:49
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_sir/model.h:54
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_sir/model.h:67
Parameters of SIR model.
Definition: sde_sir/parameters.h:93
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