LctPopulations< FP, LctStates > Class Template Reference
|
CPP API
|
A class template for compartment populations of LCT models. More...
#include <lct_populations.h>
Public Types | |
| using | InternalArrayType = Eigen::Array< Type, Eigen::Dynamic, 1 > |
| using | LctStatesGroups = TypeList< LctStates... > |
| using | Type = UncertainValue< FP > |
Public Member Functions | |
| bool | apply_constraints () |
| Checks whether all compartments have non-negative values. More... | |
| auto & | array () |
| auto const & | array () const |
| Returns a reference to the internally stored flat array. More... | |
| bool | check_constraints () const |
| Checks whether all compartments have non-negative values and logs an error if constraint is not satisfied. More... | |
| Eigen::VectorX< FP > | get_compartments () const |
| Returns an Eigen copy of the vector of populations. More... | |
| template<size_t Group> | |
| size_t | get_first_index_of_group () const |
| Gets the first index of a group in the flat array. More... | |
| template<size_t Group> | |
| FP | get_group_total () const |
| Returns the total population of a group. More... | |
| size_t | get_num_compartments () const |
| get_num_compartments Returns the number of compartments. More... | |
| FP | get_total () const |
| Returns the total population of all compartments and groups. More... | |
| LctPopulations () | |
| Default constructor. More... | |
| Type & | operator[] (size_t index) |
| Returns the entry of the array given a flat index. More... | |
Static Public Attributes | |
| static constexpr size_t | num_groups = sizeof...(LctStates) |
| Number of groups. More... | |
Static Private Member Functions | |
| template<size_t Group = 0> | |
| static size_t | get_count () |
| Sets recursively the total number of (sub-)compartments over all groups. More... | |
Private Attributes | |
| InternalArrayType | m_y {} |
Detailed Description
template<typename FP, class... LctStates>
class mio::LctPopulations< FP, LctStates >
A class template for compartment populations of LCT models.
Populations can be split up into different categories, e.g. by age group, yearly income group, gender etc. In LCT models, we want to use different numbers of subcompartments, i.e. different LctStates, for each group of a category. (Therefore, we can't use the normal Populations class because it expects the same InfectionStates for each group.)
This template must be instantiated with one LctState for each group of a category. The purpose of the LctStates is to define the number of subcompartments for each InfectionState. The number of LctStates also determines the number of groups. If you want to use more than one category, e.g. age and gender, you have to define num_age_groups * num_genders LctStates, because the number of subcompartments can be different even for (female, A05-A14) and (female, A80+) or (male, A05-A14).
The class created from this template contains a "flat array" of compartment populations and some functions for retrieving or setting the populations. The order in the flat array is: First, all (sub-)compartments of the first group, afterwards all (sub-)compartments of the second group and so on.
Member Typedef Documentation
◆ InternalArrayType
| using mio::LctPopulations< FP, LctStates >::InternalArrayType = Eigen::Array<Type, Eigen::Dynamic, 1> |
◆ LctStatesGroups
| using mio::LctPopulations< FP, LctStates >::LctStatesGroups = TypeList<LctStates...> |
◆ Type
| using mio::LctPopulations< FP, LctStates >::Type = UncertainValue<FP> |
Constructor & Destructor Documentation
◆ LctPopulations()
|
inline |
Default constructor.
Member Function Documentation
◆ apply_constraints()
|
inline |
Checks whether all compartments have non-negative values.
This function can be used to prevent slightly negative function values in compartment sizes that are produced due to rounding errors if, e.g., population sizes were computed in a complex way.
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.
◆ array() [1/2]
|
inline |
◆ array() [2/2]
|
inline |
Returns a reference to the internally stored flat array.
- Returns
- Const reference to the InternalArrayType instance.
◆ 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.
◆ get_compartments()
|
inline |
Returns an Eigen copy of the vector of populations.
This can be used as initial conditions for the ODE solver.
- Returns
- Eigen::VectorXd of populations.
◆ get_count()
|
inlinestaticprivate |
Sets recursively the total number of (sub-)compartments over all groups.
The number also corresponds to the size of the internal vector.
◆ get_first_index_of_group()
|
inline |
Gets the first index of a group in the flat array.
- Template Parameters
-
group The group for which the index should be returned.
- Returns
- The index of the first entry of group in the flat array.
◆ get_group_total()
|
inline |
Returns the total population of a group.
- Template Parameters
-
group The group for which the total population should be calculated.
- Returns
- Total population of the group.
◆ get_num_compartments()
|
inline |
get_num_compartments Returns the number of compartments.
- Returns
- Number of compartments which equals the flat array size.
◆ get_total()
|
inline |
Returns the total population of all compartments and groups.
- Returns
- Total population.
◆ operator[]()
|
inline |
Returns the entry of the array given a flat index.
- Parameters
-
index A flat index.
- Returns
- The value of the internal array at the index.
Member Data Documentation
◆ m_y
|
private |
◆ num_groups
|
staticconstexpr |
Number of groups.
Generated by