Populations< FP, Categories > Class Template Reference
|
CPP API
|
A class template for compartment populations. More...
#include <populations.h>
Public Types | |
| using | Base = CustomIndexArray< UncertainValue< FP >, Categories... > |
| using | Index = typename Base::Index |
Public Types inherited from mio::CustomIndexArray< UncertainValue< FP >, Categories... > | |
| using | const_iterator = typename InternalArrayType::const_iterator |
| using | Index = ::mio::Index< Tags... > |
| using | InternalArrayType = Eigen::Array< Type, Eigen::Dynamic, 1 > |
| using | iterator = typename InternalArrayType::iterator |
| using | reference = Type & |
| using | Type = UncertainValue< FP > |
| using | value_type = Type |
Public Member Functions | |
| bool | apply_constraints () |
| Checks whether all compartments have non-negative values. More... | |
| bool | check_constraints () const |
| Checks whether all compartments have non-negative values and logs an error if constraint is not satisfied. More... | |
| template<class OtherType > | |
| requires std::convertible_to< typename Base::Type::Type, OtherType > Populations< OtherType, Categories... > | convert () const |
| Convert internally stored data to OtherType and save into new Populations. More... | |
| Eigen::VectorX< FP > | get_compartments () const |
| get_compartments returns an Eigen copy of the vector of populations. More... | |
| template<class Arr > | |
| decltype(auto) | get_from (Arr &&y, Index const &cats) const |
| get_from returns the value of a flat container at the flat index corresponding to set of enum values. More... | |
| template<class T > | |
| FP | get_group_total (mio::Index< T > group_idx) const |
| get_group_total returns the total population of a group in one category More... | |
| size_t | get_num_compartments () const |
| get_num_compartments returns the number of compartments More... | |
| FP | get_total () const |
| get_total returns the total population of all compartments More... | |
| Populations (Base &&array) | |
| Create populations by taking ownership of a CustomIndexArray. More... | |
| template<class... Ts> | |
| requires std::is_constructible_v< UncertainValue< FP >, Ts... > | Populations (Index const &sizes, Ts... args) |
| template<class T > | |
| void | set_difference_from_group_total (Index const &midx, FP total_group_population) |
| set_difference_from_group_total sets the total population for a given group from a difference More... | |
| void | set_difference_from_total (Index midx, FP total_population) |
| set_difference_from_total takes a total population as input and sets the compartment of a given index to have the difference between the input total population and the current population in all other compartments More... | |
| template<class T > | |
| void | set_group_total (mio::Index< T > group_idx, FP value) |
| set_group_total sets the total population for a given group More... | |
| void | set_total (FP value) |
| set_total sets the total population More... | |
Public Member Functions inherited from mio::CustomIndexArray< UncertainValue< FP >, Categories... > | |
| auto & | array () |
| auto const & | array () const |
| array returns a reference to the internally stored flat array. More... | |
| iterator | begin () |
| Get a start iterator for the elements. More... | |
| const_iterator | begin () const |
| Get a start iterator for the elements. More... | |
| requires std::convertible_to< Type, OtherType > CustomIndexArray< OtherType, Tags... > | convert () const |
| Convert internally stored data to OtherType and save into new CustomIndexArray. More... | |
| CustomIndexArray () | |
| Create an empty CustomIndexArray with size 0. Use the resize member function to add entries. More... | |
| CustomIndexArray (Index const &dims, Iter b, Iter e) | |
| Initializes array with values from a range. More... | |
| iterator | end () |
| Get an end iterator for the elements. More... | |
| const_iterator | end () const |
| Get an end iterator for the elements. More... | |
| size_t | get_flat_index (Index const &index) const |
| get_flat_index returns the flat index into the stored array, given the indices of each category More... | |
| Ts | m_numel (product(dims)) |
| Ts | m_y (InternalArrayType::Constant(m_numel, 1, Type{std::forward< Ts >(args)...})) |
| constexpr size_t | numel () const |
| numel returns the number of elements More... | |
| CustomIndexArray & | operator= (const Type &scalar) |
| Assign the same value to each element of the array. More... | |
| Type & | operator[] (Index const &index) |
| returns the entry of the array given a MultiIndex More... | |
| Type const & | operator[] (Index const &index) const |
| returns the entry of the array given a flat index index More... | |
| requires (std::is_constructible_v< Type, Ts... >) CustomIndexArray(Index const &dims | |
CustomIndexArray constructor, that initializes the array to constant instances of CustsomIndexArray::Type. More... | |
| void | resize (Index new_dims) |
| Resize all dimensions, invalidating entries. More... | |
| void | resize (mio::Index< Tag > new_dim) |
| Resize a single dimension, invalidating entries. More... | |
| void | serialize (IOContext &io) const |
| serialize this. More... | |
| void | set_multiple (const std::vector< typename CustomIndexArray< UncertainValue< FP >, Tags... >::Index > &indices, const UncertainValue< FP > &value) |
| Set multiple entries to the same value. More... | |
| mio::Index< Tag > | size () const |
| returns the size along the dimension provided as template parameter More... | |
| Index | size () const |
| returns the size of the array along all dimensions. More... | |
| bool | operator== (const CustomIndexArray &other) const |
| Equality comparison. More... | |
| bool | operator!= (const CustomIndexArray &other) const |
| Equality comparison. More... | |
| Slice< Tag, iterator > | slice (Seq< size_t > idx_seq) |
| Creates a slice into the multidimensional array. More... | |
| Slice< Tag, const_iterator > | slice (Seq< size_t > idx_seq) const |
| Creates a slice into the multidimensional array. More... | |
| Slice< Tag, iterator > | slice (mio::Index< Tag > idx) |
| Creates a slice into the multidimensional array. More... | |
| Slice< Tag, const_iterator > | slice (mio::Index< Tag > idx) const |
| Creates a slice into the multidimensional array. More... | |
| requires std::is_enum_v< Tag > Slice< Tag, iterator > | slice (Tag idx) |
| Creates a slice into the multidimensional array. More... | |
| requires std::is_enum_v< Tag > Slice< Tag, const_iterator > | slice (Tag idx) const |
| Creates a slice into the multidimensional array. More... | |
Static Public Member Functions | |
| template<class IOContext > | |
| static IOResult< Populations > | deserialize (IOContext &io) |
| deserialize an object of this class. More... | |
Static Public Member Functions inherited from mio::CustomIndexArray< UncertainValue< FP >, Categories... > | |
| static IOResult< CustomIndexArray > | deserialize (IOContext &io) |
| deserialize an object of this class. More... | |
Additional Inherited Members | |
Public Attributes inherited from mio::CustomIndexArray< UncertainValue< FP >, Categories... > | |
| Ts && | args |
Static Protected Member Functions inherited from mio::CustomIndexArray< UncertainValue< FP >, Categories... > | |
| static IOResult< Derived > | deserialize (IOContext &io, Tag< Derived >) |
| deserialize an object of a class derived from this class. More... | |
Detailed Description
template<typename FP, class... Categories>
class mio::Populations< FP, Categories >
A class template for compartment populations.
Populations can be split up into different Categories, e.g. by age group, yearly income group, gender etc. Compartmental models introduce the additional category of infection type. For the SEIR model these are Susceptible, Exposed, Infected and Removed. Every category is assumed to contain a finite number of groups.
This template can be instantiated given an arbitrary set of Categories. The Categories are assumed to be an enum class with a member Count refering to the number of elements in the enum.
The class created from this template contains a "flat array" of compartment populations and some functions for retrieving or setting the populations.
Member Typedef Documentation
◆ Base
| using mio::Populations< FP, Categories >::Base = CustomIndexArray<UncertainValue<FP>, Categories...> |
◆ Index
| using mio::Populations< FP, Categories >::Index = typename Base::Index |
Constructor & Destructor Documentation
◆ Populations() [1/2]
|
inlineexplicit |
◆ Populations() [2/2]
|
inlineexplicit |
Create populations by taking ownership of a CustomIndexArray.
Member Function Documentation
◆ apply_constraints()
|
inline |
Checks whether all compartments have non-negative values.
This function can be used to prevent slighly negative function values in compartment sizes that came out due to roundoff errors if, e.g., population sizes were computed in a complex way. If negative values which are smaller than -1e-10 are found, an error is logged, otherwise, only a warning is logged.
Attention: This function should be used with care. It can not and will not set model parameters and compartments to meaningful values. In most cases it is preferable to use check_constraints, and correct values manually before proceeding with the simulation. The main usage for apply_constraints is in automated tests using random values for initialization.
- Returns
- Returns true if one (or more) constraint(s) were corrected, otherwise false.
◆ check_constraints()
|
inline |
Checks whether all compartments have non-negative values and logs an error if constraint is not satisfied.
- Returns
- Returns true if one or more constraints are not satisfied, false otherwise.
◆ convert()
|
inline |
Convert internally stored data to OtherType and save into new Populations.
- Template Parameters
-
OtherType The type to convert into.
- Returns
- New Populations of OtherType with copy of internal data.
◆ deserialize()
|
inlinestatic |
deserialize an object of this class.
- See also
- mio::deserialize
◆ get_compartments()
|
inline |
get_compartments returns an Eigen copy of the vector of populations.
This can be used as initial conditions for the ODE solver
- Returns
- Eigen::VectorX<FP> of populations
◆ get_from()
|
inline |
get_from returns the value of a flat container at the flat index corresponding to set of enum values.
It is the same as get, except that it takes the values from an outside reference flat container, rather than the initial values stored within this class
TODO: It would be better, to have CustomIndexArray be able to operate on shared data. Maybe using an Eigen::Map
- Parameters
-
y a reference to a flat container cats enum values for each category
- Returns
- the population of compartment
◆ get_group_total()
|
inline |
get_group_total returns the total population of a group in one category
- Parameters
-
T enum class for the category group_idx enum value of the group
- Returns
- total population of the group
◆ get_num_compartments()
|
inline |
get_num_compartments returns the number of compartments
This corresponds to the product of the category sizes
- Returns
- number of compartments
◆ get_total()
|
inline |
get_total returns the total population of all compartments
- Returns
- total population
◆ set_difference_from_group_total()
|
inline |
set_difference_from_group_total sets the total population for a given group from a difference
This function sets the population size
- Parameters
-
total_population the new value for the total population indices The indices of the compartment T The enum class of the category of the group group_idx The enum of the group within the category
◆ set_difference_from_total()
|
inline |
set_difference_from_total takes a total population as input and sets the compartment of a given index to have the difference between the input total population and the current population in all other compartments
- Parameters
-
indices the index of the compartment total_population the new value for the total population
◆ set_group_total()
|
inline |
set_group_total sets the total population for a given group
This function rescales all the compartments populations proportionally. If all compartments have zero population, the total population gets distributed equally over all compartments
- Parameters
-
T The enum class of the category of the group group_idx The enum value of the group within the category value the new value for the total population
◆ set_total()
|
inline |
set_total sets the total population
This function rescales all the compartments populations proportionally. If all compartments have zero population, the total population gets distributed equally over all compartments.
- Parameters
-
value the new value for the total population
Generated by
Public Types inherited from