FIMS  v0.10.0
Loading...
Searching...
No Matches
vonb_schnute.hpp
Go to the documentation of this file.
1
9#ifndef POPULATION_DYNAMICS_GROWTH_VONB_SCHNUTE_HPP
10#define POPULATION_DYNAMICS_GROWTH_VONB_SCHNUTE_HPP
11
12#include "../../../common/fims_math.hpp"
13#include "growth_base.hpp"
14
15namespace fims_popdy {
16
31template <typename Type>
43
48
51
57 Type length_at_age(const Type& age) const {
60 // For early ages, avoid back-extrapolating the curved growth equation.
61 // This no-seasons ramp goes from length 0 at age 0 to length young at
62 // age young; seasonal growth may need a different transition in the
63 // future.
64 const Type age_nonnegative = age <= Type(0.0) ? Type(0.0) : age;
67 }
68
69 const Type denom =
70 Type(1.0) -
73 // AD-safe floor to avoid divide-by-zero/NaN when denominator is tiny.
74 const Type denom_safe =
75 fims_math::ad_max(fims_math::ad_fabs(denom), static_cast<Type>(1e-8));
76 const Type numer =
77 Type(1.0) - fims_math::exp(-growth_coefficient *
79 return mean_length_young +
81 }
82
90 const Type length_safe = fims_math::ad_max(length, static_cast<Type>(1e-8));
91 return fims_math::log(length_safe);
92 }
93
108 Type& d_log_laa_d_k) const {
111 const Type age_nonnegative = age <= Type(0.0) ? Type(0.0) : age;
114 const Type mean_length_safe =
115 fims_math::ad_max(mean_length, static_cast<Type>(1e-8));
116
119 d_log_laa_d_k = Type(0.0);
120 return;
121 }
122
124 const Type age_delta_2 =
126
127 const Type exp_num = fims_math::exp(-growth_coefficient * age_delta_1);
128 const Type exp_den = fims_math::exp(-growth_coefficient * age_delta_2);
129
130 const Type numer = Type(1.0) - exp_num;
131 const Type denom = Type(1.0) - exp_den;
132 const Type denom_safe =
133 fims_math::ad_max(fims_math::ad_fabs(denom), static_cast<Type>(1e-8));
134
135 const Type ratio = numer / denom_safe;
138 const Type mean_length_safe =
139 fims_math::ad_max(mean_length, static_cast<Type>(1e-8));
140
141 const Type d_length_d_l1 = Type(1.0) - ratio;
142 const Type d_length_d_l2 = ratio;
143
149
153 }
154
183
189 Type weight_at_age(const Type& age) const {
191 return length_weight_a * fims_math::pow(length, length_weight_b);
192 }
193
194 virtual const Type evaluate(int year, const double& a) override {
195 (void)year;
196 return weight_at_age(Type(a));
197 }
198};
199} // namespace fims_popdy
200
201#endif // POPULATION_DYNAMICS_GROWTH_VONB_SCHNUTE_HPP
Declares the GrowthBase class which is the base class for all growth functors.
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
Base class for all growth functors.
Definition growth_base.hpp:24
VonBertalanffySchnute growth functor for length-at-age and weight-at-age.
Definition vonb_schnute.hpp:32
Type mean_length_young
Expected length at the first reference age.
Definition vonb_schnute.hpp:34
Type length_at_age(const Type &age) const
Evaluate mean length at age.
Definition vonb_schnute.hpp:57
Type reference_age_for_length_old
Second reference age for the length parameterization.
Definition vonb_schnute.hpp:42
Type growth_coefficient
Growth coefficient.
Definition vonb_schnute.hpp:38
Type weight_at_age(const Type &age) const
Evaluate mean weight at age via the length-weight relationship.
Definition vonb_schnute.hpp:189
void log_length_at_age_logscale_gradient(const Type &age, Type &d_log_laa_d_log_length_young, Type &d_log_laa_d_log_length_old, Type &d_log_laa_d_log_k) const
Evaluate the gradient of log mean length at age with respect to the log-scale FIMS VonBertalanffySchn...
Definition vonb_schnute.hpp:168
Type length_weight_b
Exponent in the length-weight relationship, W = a * L^b.
Definition vonb_schnute.hpp:47
Type log_length_at_age(const Type &age) const
Evaluate log mean length at age.
Definition vonb_schnute.hpp:88
void log_length_at_age_gradient(const Type &age, Type &d_log_laa_d_length_young, Type &d_log_laa_d_length_old, Type &d_log_laa_d_k) const
Evaluate the gradient of log mean length at age with respect to the current natural-scale FIMS VonBer...
Definition vonb_schnute.hpp:105
Type reference_age_for_length_young
First reference age for the length parameterization.
Definition vonb_schnute.hpp:40
Type length_weight_a
Coefficient in the length-weight relationship, W = a * L^b.
Definition vonb_schnute.hpp:45
virtual const Type evaluate(int year, const double &a) override
Calculates the growth at the independent variable value.
Definition vonb_schnute.hpp:194
Type mean_length_old
Expected length at the second reference age.
Definition vonb_schnute.hpp:36