8#ifndef POPULATION_DYNAMICS_GROWTH_MODEL_HPP
9#define POPULATION_DYNAMICS_GROWTH_MODEL_HPP
17#include "../../common/def.hpp"
30template <
typename Type>
39 GrowthModel(std::size_t n_years, std::size_t n_ages, std::size_t n_sexes = 1)
43 products_(n_years, n_ages, n_sexes) {}
48 Type growth_coefficient,
49 Type reference_age_for_length_young,
50 Type reference_age_for_length_old) {
51 vb_.mean_length_young = mean_length_young;
52 vb_.mean_length_old = mean_length_old;
53 vb_.growth_coefficient = growth_coefficient;
54 vb_.reference_age_for_length_young = reference_age_for_length_young;
55 vb_.reference_age_for_length_old = reference_age_for_length_old;
61 vb_.length_weight_a = length_weight_a;
62 vb_.length_weight_b = length_weight_b;
70 length_at_age_sd_at_reference_age_young_ =
72 length_at_age_sd_at_reference_age_old_ =
92 ValidateGrowthParameterCovariance(
100 mean_length_young_mean_length_old_covariance_ =
102 mean_length_young_growth_coefficient_covariance_ =
105 mean_length_old_growth_coefficient_covariance_ =
108 use_delta_method_variability_ =
true;
109 needs_update_ =
true;
115 mean_length_young_variance_ =
static_cast<Type>(0.0);
116 mean_length_young_mean_length_old_covariance_ =
static_cast<Type>(0.0);
117 mean_length_young_growth_coefficient_covariance_ =
static_cast<Type>(0.0);
118 mean_length_old_variance_ =
static_cast<Type>(0.0);
119 mean_length_old_growth_coefficient_covariance_ =
static_cast<Type>(0.0);
120 growth_coefficient_variance_ =
static_cast<Type>(0.0);
121 use_delta_method_variability_ =
false;
122 needs_update_ =
true;
127 if (!needs_update_)
return;
130 throw std::runtime_error(
131 "VonBertalanffySchnuteGrowth requires n_ages > 0");
133 if (vb_.reference_age_for_length_old <=
134 vb_.reference_age_for_length_young) {
135 throw std::runtime_error(
136 "VonBertalanffySchnuteGrowth reference_age_for_length_old must be > "
137 "reference_age_for_length_young");
143 if (!use_delta_method_variability_) {
144 laa_min = vb_.length_at_age(vb_.reference_age_for_length_young);
145 const Type laa_max = vb_.length_at_age(vb_.reference_age_for_length_old);
148 slope = (n_ages_ > 1) ? (length_at_age_sd_at_reference_age_old_ -
149 length_at_age_sd_at_reference_age_young_) /
155 for (std::size_t
y = 0;
y < n_years_; ++
y) {
156 for (std::size_t
a = 0;
a < n_ages_; ++
a) {
157 for (std::size_t
s = 0;
s < n_sexes_; ++
s) {
165 products_.MeanLAA(
y,
a,
s) =
laa;
167 products_.MeanWAA(
y,
a,
s) =
waa;
172 needs_update_ =
false;
181 void ValidateGrowthParameterCovariance(
191 throw std::runtime_error(
"Growth parameter variances must be >= 0");
197 throw std::runtime_error(
198 "Growth covariance between mean_length_young and "
199 "mean_length_old is inconsistent with the supplied variances");
205 throw std::runtime_error(
206 "Growth covariance between mean_length_young and "
207 "growth_coefficient is inconsistent with the supplied variances");
213 throw std::runtime_error(
214 "Growth covariance between mean_length_old and "
215 "growth_coefficient is inconsistent with the supplied variances");
235 throw std::runtime_error(
236 "Growth parameter covariance matrix must be positive "
245 if (use_delta_method_variability_) {
255 ? length_at_age_sd_at_reference_age_young_ + slope * (
laa -
laa_min)
256 : length_at_age_sd_at_reference_age_young_;
263 Type ComputeLogLengthVarianceAtAge(
const Type&
age)
const {
273 mean_length_young_variance_ +
276 mean_length_young_mean_length_old_covariance_ +
278 mean_length_young_growth_coefficient_covariance_ +
280 mean_length_old_variance_ +
282 mean_length_old_growth_coefficient_covariance_ +
286 std::size_t n_years_;
288 std::size_t n_sexes_;
296 bool needs_update_ =
true;
297 Type length_at_age_sd_at_reference_age_young_ =
static_cast<Type>(3.0);
298 Type length_at_age_sd_at_reference_age_old_ =
static_cast<Type>(7.0);
299 bool use_delta_method_variability_ =
false;
300 Type mean_length_young_variance_ =
static_cast<Type>(0.0);
301 Type mean_length_young_mean_length_old_covariance_ =
static_cast<Type>(0.0);
302 Type mean_length_young_growth_coefficient_covariance_ =
303 static_cast<Type>(0.0);
304 Type mean_length_old_variance_ =
static_cast<Type>(0.0);
305 Type mean_length_old_growth_coefficient_covariance_ =
static_cast<Type>(0.0);
306 Type growth_coefficient_variance_ =
static_cast<Type>(0.0);
307 Type age_offset_ =
static_cast<Type>(0.0);
313 needs_update_ =
true;
Growth module boundary (product-oriented).
Definition growth_model_base.hpp:24
Concrete growth model using VonBertalanffySchnute growth (Phase 1).
Definition growth_model.hpp:31
void SetLengthSdParams(Type length_at_age_sd_at_reference_age_young, Type length_at_age_sd_at_reference_age_old)
Definition growth_model.hpp:68
GrowthModel(std::size_t n_years, std::size_t n_ages, std::size_t n_sexes=1)
Construct a growth model with fixed dimensions.
Definition growth_model.hpp:39
void Prepare() override
Compute and cache growth products.
Definition growth_model.hpp:126
void ClearGrowthParameterCovariance()
Definition growth_model.hpp:114
void SetLengthWeightParameters(Type length_weight_a, Type length_weight_b)
fixed length-weight params (phase 1)
Definition growth_model.hpp:60
const GrowthProducts< Type > & GetProducts() const override
Read-only access to cached growth products.
Definition growth_model.hpp:175
void SetGrowthParameterCovariance(Type mean_length_young_variance, Type mean_length_young_mean_length_old_covariance, Type mean_length_young_growth_coefficient_covariance, Type mean_length_old_variance, Type mean_length_old_growth_coefficient_covariance, Type growth_coefficient_variance)
Definition growth_model.hpp:85
void SetVonBertalanffySchnuteParameters(Type mean_length_young, Type mean_length_old, Type growth_coefficient, Type reference_age_for_length_young, Type reference_age_for_length_old)
Set fixed VonBertalanffySchnute parameters (explicit reference ages).
Definition growth_model.hpp:46
void SetAgeOffset(Type offset)
Set an age offset if population ages do not start at zero.
Definition growth_model.hpp:311
const Type ad_max(const Type &a, const Type &b, Type C=1e-5)
Definition fims_math.hpp:365
Declares the GrowthModelBase interface. This is the growth module boundary that downstream code consu...
Declares the GrowthProducts struct holding growth "products" that downstream population dynamics code...
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
Growth "products" in a consistent (year, age, sex) space.
Definition growth_products.hpp:26
Defines the VonBertalanffySchnuteGrowth class, which inherits from the GrowthBase class.