9#ifndef POPULATION_DYNAMICS_GROWTH_VONB_SCHNUTE_HPP
10#define POPULATION_DYNAMICS_GROWTH_VONB_SCHNUTE_HPP
31template <
typename Type>
32struct VonBertalanffySchnuteGrowth :
public GrowthBase<Type> {
49 VonBertalanffySchnuteGrowth() :
GrowthBase<Type>() {}
61 const Type reference_age_span =
65 auto scaled_decay = [](
const Type& x, Type* decay_derivative) -> Type {
66 const Type threshold = Type(1e-3);
68 const Type series_x = fims_math::cond_exp_lt(x, threshold, x, Type(0.0));
69 const Type regular_x = fims_math::cond_exp_lt(x, threshold, Type(1.0), x);
73 series_x * (Type(-0.5) +
74 series_x * (Type(1.0 / 6.0) +
75 series_x * (Type(-1.0 / 24.0) +
76 series_x * Type(1.0 / 120.0))));
77 const Type regular = (Type(1.0) - fims_math::exp(-regular_x)) / regular_x;
79 if (decay_derivative !=
nullptr) {
80 const Type series_derivative =
81 Type(-0.5) + series_x * (Type(1.0 / 3.0) +
82 series_x * (Type(-1.0 / 8.0) +
83 series_x * Type(1.0 / 30.0)));
84 const Type regular_derivative =
85 (fims_math::exp(-regular_x) - regular) / regular_x;
87 *decay_derivative = fims_math::cond_exp_lt(
88 x, threshold, series_derivative, regular_derivative);
91 return fims_math::cond_exp_lt(x, threshold, series, regular);
94 Type elapsed_derivative = Type(0.0);
95 Type reference_derivative = Type(0.0);
96 const Type elapsed_decay =
98 derivative !=
nullptr ? &elapsed_derivative :
nullptr);
99 const Type reference_decay =
101 derivative !=
nullptr ? &reference_derivative :
nullptr);
102 const Type age_ratio = elapsed_age / reference_age_span;
103 const Type decay_ratio = elapsed_decay / reference_decay;
105 if (derivative !=
nullptr) {
106 *derivative = age_ratio *
107 (elapsed_age * elapsed_derivative -
108 decay_ratio * reference_age_span * reference_derivative) /
112 return age_ratio * decay_ratio;
127 const Type age_nonnegative = age <= Type(0.0) ? Type(0.0) : age;
144 return fims_math::log(length_safe);
159 Type& d_log_laa_d_length_young,
160 Type& d_log_laa_d_length_old,
161 Type& d_log_laa_d_k)
const {
164 const Type age_nonnegative = age <= Type(0.0) ? Type(0.0) : age;
167 const Type mean_length_safe =
170 d_log_laa_d_length_young = ratio / mean_length_safe;
171 d_log_laa_d_length_old = Type(0.0);
172 d_log_laa_d_k = Type(0.0);
176 Type d_ratio_d_k = Type(0.0);
180 const Type mean_length_safe =
183 const Type d_length_d_l1 = Type(1.0) - ratio;
184 const Type d_length_d_l2 = ratio;
185 const Type d_length_d_k = delta_length * d_ratio_d_k;
186 d_log_laa_d_length_young = d_length_d_l1 / mean_length_safe;
187 d_log_laa_d_length_old = d_length_d_l2 / mean_length_safe;
188 d_log_laa_d_k = d_length_d_k / mean_length_safe;
206 Type& d_log_laa_d_log_length_young,
207 Type& d_log_laa_d_log_length_old,
208 Type& d_log_laa_d_log_k)
const {
209 Type d_log_laa_d_length_young = Type(0.0);
210 Type d_log_laa_d_length_old = Type(0.0);
211 Type d_log_laa_d_k = Type(0.0);
214 d_log_laa_d_length_old, d_log_laa_d_k);
231 virtual const Type
evaluate(
int year,
const double& a)
override {
A collection of mathematical functions used in FIMS.
const Type ad_max(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:410
Declares the GrowthBase class which is the base class for all growth functors.
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
GrowthBase()
Constructor.
Definition growth_base.hpp:34
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:120
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:226
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 [log(mean_length_young),...
Definition vonb_schnute.hpp:205
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:141
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:158
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
Type growth_fraction(const Type &age, Type *derivative=nullptr) const
Growth fraction at or after the younger reference age.
Definition vonb_schnute.hpp:59
virtual const Type evaluate(int year, const double &a) override
Calculates the growth at the independent variable value.
Definition vonb_schnute.hpp:231
Type mean_length_old
Expected length at the second reference age.
Definition vonb_schnute.hpp:36