FIMS  v0.11.0
Loading...
Searching...
No Matches
age_specific.hpp
Go to the documentation of this file.
1
8#ifndef POPULATION_DYNAMICS_AGE_SPECIFIC_SELECTIVITY_HPP
9#define POPULATION_DYNAMICS_AGE_SPECIFIC_SELECTIVITY_HPP
10
11// #include "../../../interface/interface.hpp"
12#include "../../../common/fims_math.hpp"
13#include "../../../common/fims_vector.hpp"
14#include "selectivity_base.hpp"
15
16namespace fims_popdy {
17
48template <typename Type>
56
60 size_t n_ages;
61
65 size_t min_age;
66
68
69 virtual ~AgeSpecificSelectivity() {}
70
89 virtual const Type evaluate(const Type &x) {
90 Type a = static_cast<Type>(0.0);
91 Type b = static_cast<Type>(1.0);
92 double x_temp = fims_math::Value(x);
93 size_t x_final = static_cast<size_t>(x_temp);
94 size_t i_age = x_final - min_age;
95 return fims_math::inv_logit<Type>(a, b, logit_sel_at_age[i_age]);
96 }
97
107 virtual const Type evaluate(const Type &x, size_t pos) {
108 Type a = static_cast<Type>(0.0);
109 Type b = static_cast<Type>(1.0);
110 double x_temp = fims_math::Value(x);
111 size_t x_final = static_cast<size_t>(x_temp);
112 size_t i_age = x_final - min_age;
113 size_t n_values = logit_sel_at_age.size();
114 if (n_values == 1) {
115 return fims_math::inv_logit<Type>(a, b, logit_sel_at_age[0]);
116 }
117 if (n_ages == 0 || n_values % n_ages != 0) {
118 throw std::invalid_argument(
119 "AgeSpecificSelectivity: logit_sel_at_age has " +
120 std::to_string(n_values) + " values, which is not 1 or a multiple " +
121 "of n_ages (" + std::to_string(n_ages) + ").");
122 }
123 size_t i_value = (n_values == n_ages) ? i_age : pos * n_ages + i_age;
124 return fims_math::inv_logit<Type>(a, b, logit_sel_at_age[i_value]);
125 }
126};
127
128} // namespace fims_popdy
129
130#endif /* POPULATION_DYNAMICS_AGE_SPECIFIC_SELECTIVITY_HPP */
Definition fims_vector.hpp:27
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
std::shared_ptr< AgeToLengthConversionBase< Type > > BuildAgeToLengthConversionFleet(const std::shared_ptr< Population< Type > > &population, const std::shared_ptr< Fleet< Type > > &fleet)
Build the active age-to-length conversion for a fleet from the current population and fleet state.
Definition runtime.hpp:44
Declares the SelectivityBase class which is the base class for all selectivity functors.
Age-specific selectivity calculated using one parameter per age bin.
Definition age_specific.hpp:49
size_t min_age
Minimum modeled age, used to map input age to logit_sel_at_age.
Definition age_specific.hpp:65
virtual const Type evaluate(const Type &x, size_t pos)
Calculates selectivity for an age using its age-specific parameter.
Definition age_specific.hpp:107
virtual const Type evaluate(const Type &x)
Calculates selectivity for an age using its age-specific parameter.
Definition age_specific.hpp:89
size_t n_ages
Stores the number of modeled age bins.
Definition age_specific.hpp:60
fims::Vector< Type > logit_sel_at_age
Stores the age-specific selectivity parameters on the logit scale.
Definition age_specific.hpp:55
Base class for all selectivity functors.
Definition selectivity_base.hpp:24