FIMS  v0.11.0
Loading...
Searching...
No Matches
growth_model_adapter.hpp
Go to the documentation of this file.
1
6#ifndef POPULATION_DYNAMICS_GROWTH_MODEL_ADAPTER_HPP
7#define POPULATION_DYNAMICS_GROWTH_MODEL_ADAPTER_HPP
8
9#include <cmath>
10#include <memory>
11#include <stdexcept>
12
15#include "growth_model.hpp"
18
19namespace fims_popdy {
20
25template <typename Type>
26class GrowthDerivedObservationBase : public GrowthBase<Type> {
27 public:
28 GrowthDerivedObservationBase() : GrowthBase<Type>() {}
29 virtual ~GrowthDerivedObservationBase() = default;
30
35 virtual void SetAgeOffset(double min_age) = 0;
36
43 virtual void Initialize(std::size_t n_years, std::size_t n_ages,
44 std::size_t n_sexes = 1) = 0;
45
52 virtual bool SupportsAgeToLengthConversionDerived() const = 0;
53
57 virtual void PrepareGrowthProducts() = 0;
58
64
70 virtual Type EvaluateWeightAtLength(const Type& length) const = 0;
71};
72
77template <typename Type>
78class VonBertalanffySchnuteGrowthModelAdapter
79 : public GrowthDerivedObservationBase<Type> {
80 public:
81 VonBertalanffySchnuteGrowthModelAdapter()
82 : GrowthDerivedObservationBase<Type>() {}
83
88 kEstimatedReferenceLengths = 0,
89 kConstantLengthYoungEstimatedLengthOld,
90 kEstimatedLengthYoungBelowConstantLengthOld,
91 kBothConstant
92 };
93
98 length_reference_parameterization_ =
99 LengthReferenceParameterization::kEstimatedReferenceLengths;
100 growth_products_prepared_ = false;
101 }
102
110 Type constant_mean_length_young) {
111 length_reference_parameterization_ =
112 LengthReferenceParameterization::kConstantLengthYoungEstimatedLengthOld;
113 constant_mean_length_young_ = constant_mean_length_young;
114 growth_products_prepared_ = false;
115 }
116
124 Type constant_mean_length_old) {
125 length_reference_parameterization_ = LengthReferenceParameterization::
126 kEstimatedLengthYoungBelowConstantLengthOld;
127 constant_mean_length_old_ = constant_mean_length_old;
128 growth_products_prepared_ = false;
129 }
130
139 void UseConstantReferenceMeanLengths(Type constant_mean_length_young,
140 Type constant_mean_length_old) {
141 length_reference_parameterization_ =
142 LengthReferenceParameterization::kBothConstant;
143 constant_mean_length_young_ = constant_mean_length_young;
144 constant_mean_length_old_ = constant_mean_length_old;
145 growth_products_prepared_ = false;
146 }
147
154 use_param_vectors_ = true;
155 vb_params_set_ = true;
156 growth_products_prepared_ = false;
157 return mean_length_young_vector_;
158 }
159
167 use_param_vectors_ = true;
168 vb_params_set_ = true;
169 growth_products_prepared_ = false;
170 return mean_length_old_vector_;
171 }
172
179 use_param_vectors_ = true;
180 vb_params_set_ = true;
181 growth_products_prepared_ = false;
182 return growth_coefficient_vector_;
183 }
184
190 use_param_vectors_ = true;
191 vb_params_set_ = true;
192 growth_products_prepared_ = false;
193 return reference_age_for_length_young_vector_;
194 }
195
201 use_param_vectors_ = true;
202 vb_params_set_ = true;
203 growth_products_prepared_ = false;
204 return reference_age_for_length_old_vector_;
205 }
206
212 use_param_vectors_ = true;
213 lw_params_set_ = true;
214 growth_products_prepared_ = false;
215 return length_weight_a_vector_;
216 }
217
223 use_param_vectors_ = true;
224 lw_params_set_ = true;
225 growth_products_prepared_ = false;
226 return length_weight_b_vector_;
227 }
228
234 use_param_vectors_ = true;
235 growth_products_prepared_ = false;
236 return length_at_age_sd_young_vector_;
237 }
238
244 use_param_vectors_ = true;
245 growth_products_prepared_ = false;
246 return length_at_age_sd_old_vector_;
247 }
248
254 use_param_vectors_ = true;
255 growth_products_prepared_ = false;
256 return log_sd_mean_length_young_vector_;
257 }
258
264 use_param_vectors_ = true;
265 growth_products_prepared_ = false;
266 return log_sd_mean_length_old_vector_;
267 }
268
274 use_param_vectors_ = true;
275 growth_products_prepared_ = false;
276 return log_sd_growth_coefficient_vector_;
277 }
278
285 use_param_vectors_ = true;
286 growth_products_prepared_ = false;
287 return mean_length_young_mean_length_old_logit_corr_vector_;
288 }
289
296 use_param_vectors_ = true;
297 growth_products_prepared_ = false;
298 return mean_length_young_growth_coefficient_logit_corr_vector_;
299 }
300
307 use_param_vectors_ = true;
308 growth_products_prepared_ = false;
309 return mean_length_old_growth_coefficient_logit_corr_vector_;
310 }
311
316 void SetAgeOffset(double min_age) override {
317 age_offset_ = min_age;
318 age_offset_set_ = true;
319 growth_products_prepared_ = false;
320 if (model_) {
321 model_->SetAgeOffset(static_cast<Type>(age_offset_));
322 }
323 }
324
331 void Initialize(std::size_t n_years, std::size_t n_ages,
332 std::size_t n_sexes = 1) override {
333 EnsureParamsSet();
334 if (n_sexes != 1) {
335 throw std::runtime_error(
336 "VonBertalanffySchnuteGrowthModelAdapter currently supports n_sexes "
337 "== 1");
338 }
339 n_years_ = n_years;
340 n_ages_ = n_ages;
341 n_sexes_ = n_sexes;
342 growth_products_prepared_ = false;
343 model_ = std::make_shared<GrowthModel<Type>>(n_years, n_ages, n_sexes);
344 SyncParamsToModel();
345 if (age_offset_set_) {
346 model_->SetAgeOffset(static_cast<Type>(age_offset_));
347 }
348 }
349
355 bool SupportsAgeToLengthConversionDerived() const override { return true; }
356
357 virtual const Type evaluate(int year, const double& a) override {
358 if (a < 0.0) {
359 throw std::runtime_error("Negative age not supported");
360 }
361 const double a_round = std::round(a);
362 const double tol = 1e-8;
363 if (std::fabs(a - a_round) > tol) {
364 throw std::runtime_error("Non-integer age not supported yet");
365 }
366 EnsureParamsSet();
367 const Type ref_age_young = CurrentReferenceAgeForLengthYoung();
368 const Type ref_age_old = CurrentReferenceAgeForLengthOld();
369 if (ref_age_old <= ref_age_young) {
370 throw std::runtime_error(
371 "VonBertalanffySchnuteGrowth reference_age_for_length_old must be > "
372 "reference_age_for_length_young");
373 }
374
375 if (!model_) {
376 return EvaluateWithFunctor(year, a);
377 }
378
379 SyncParamsToModel();
380 model_->Prepare();
381 const auto& p = model_->GetProducts();
382 const double offset = age_offset_set_ ? age_offset_ : 0.0;
383 const double age_index_raw = a_round - offset;
384 const double age_index_round = std::round(age_index_raw);
385 if (std::fabs(age_index_raw - age_index_round) <= tol &&
386 age_index_round >= 0.0) {
387 const std::size_t age_index = static_cast<std::size_t>(age_index_round);
388 if (age_index < p.n_ages) {
389 const std::size_t year_index =
390 (year >= 0 && static_cast<std::size_t>(year) < p.n_years)
391 ? static_cast<std::size_t>(year)
392 : static_cast<std::size_t>(0);
393 return p.MeanWAA(year_index, age_index, 0);
394 }
395 }
396
397 // Outside cached model age bins: fall back to direct functor evaluation.
398 return EvaluateWithFunctor(year, a);
399 }
400
404 void PrepareGrowthProducts() override {
405 growth_products_prepared_ = false;
406 if (!model_) {
407 if (n_ages_ == 0) {
408 throw std::runtime_error("Growth model not initialized; n_ages is 0");
409 }
410 Initialize(n_years_ == 0 ? 1 : n_years_, n_ages_,
411 n_sexes_ == 0 ? 1 : n_sexes_);
412 }
413 SyncParamsToModel();
414 model_->Prepare();
415 growth_products_prepared_ = true;
416 }
417
423 if (!model_ || !growth_products_prepared_) {
424 return nullptr;
425 }
426 return &(model_->GetProducts());
427 }
428
439 Type EvaluateWeightAtLength(const Type& length) const override {
440 EnsureParamsSet();
441 const Type length_safe = fims_math::ad_max(length, static_cast<Type>(1e-8));
442 return CurrentLengthWeightA() *
443 fims_math::pow(length_safe, CurrentLengthWeightB());
444 }
445
446 private:
447 // Reference-length working scales depend on estimation settings:
448 // estimated older length uses log(older - younger); estimated younger
449 // length uses log(younger), or a bounded logit when older is constant.
450 // Constant lengths are stored on log scales.
451 // Other positive parameters use log scales, reference ages stay on the
452 // natural scale, and correlations use transformed working-scale values.
453 fims::Vector<Type> mean_length_young_vector_;
454 fims::Vector<Type> mean_length_old_vector_;
455 fims::Vector<Type> growth_coefficient_vector_;
456 fims::Vector<Type> reference_age_for_length_young_vector_;
457 fims::Vector<Type> reference_age_for_length_old_vector_;
458 fims::Vector<Type> length_weight_a_vector_;
459 fims::Vector<Type> length_weight_b_vector_;
460 fims::Vector<Type> length_at_age_sd_young_vector_;
461 fims::Vector<Type> length_at_age_sd_old_vector_;
462 fims::Vector<Type> log_sd_mean_length_young_vector_;
463 fims::Vector<Type> log_sd_mean_length_old_vector_;
464 fims::Vector<Type> log_sd_growth_coefficient_vector_;
465 fims::Vector<Type> mean_length_young_mean_length_old_logit_corr_vector_;
466 fims::Vector<Type> mean_length_young_growth_coefficient_logit_corr_vector_;
467 fims::Vector<Type> mean_length_old_growth_coefficient_logit_corr_vector_;
468 bool use_param_vectors_ = false;
469 LengthReferenceParameterization length_reference_parameterization_ =
470 LengthReferenceParameterization::kEstimatedReferenceLengths;
471 Type constant_mean_length_young_ = Type(0.0);
472 Type constant_mean_length_old_ = Type(0.0);
473 std::size_t n_years_ = 0;
474 std::size_t n_ages_ = 0;
475 std::size_t n_sexes_ = 1;
476 double age_offset_ = 0.0;
477 bool age_offset_set_ = false;
478 bool vb_params_set_ = false;
479 bool lw_params_set_ = false;
480 bool growth_products_prepared_ = false;
481
482 mutable std::shared_ptr<GrowthModel<Type>> model_;
483
484 Type EvaluateWithFunctor(int year, const double& a) const {
485 EnsureParamsSet();
487 vb.mean_length_young = CurrentMeanLengthYoung();
488 vb.mean_length_old = CurrentMeanLengthOld();
489 vb.growth_coefficient = CurrentGrowthCoefficient();
490 vb.reference_age_for_length_young = CurrentReferenceAgeForLengthYoung();
491 vb.reference_age_for_length_old = CurrentReferenceAgeForLengthOld();
492 vb.length_weight_a = CurrentLengthWeightA();
493 vb.length_weight_b = CurrentLengthWeightB();
494 return vb.evaluate(year, a);
495 }
496
497 void SyncParamsToModel() const {
498 if (!model_) return;
499 EnsureParamsSet();
500
501 model_->SetVonBertalanffySchnuteParameters(
502 CurrentMeanLengthYoung(), CurrentMeanLengthOld(),
503 CurrentGrowthCoefficient(), CurrentReferenceAgeForLengthYoung(),
504 CurrentReferenceAgeForLengthOld());
505 model_->SetLengthWeightParameters(CurrentLengthWeightA(),
506 CurrentLengthWeightB());
507
508 if (HasInterpolationSdInputs()) {
509 model_->SetLengthSdParams(CurrentLengthAtAgeSdAtReferenceAge1(),
510 CurrentLengthAtAgeSdAtReferenceAge2());
511 }
512
513 if (HasStructuredDeltaMethodInputs()) {
514 model_->SetGrowthParameterCovariance(
515 CurrentMeanLengthYoungVariance(),
516 CurrentMeanLengthYoungLengthAtRefAgeOldCovariance(),
517 CurrentMeanLengthYoungKCovariance(), CurrentMeanLengthOldVariance(),
518 CurrentMeanLengthOldKCovariance(),
519 CurrentGrowthCoefficientVariance());
520 } else {
521 model_->ClearGrowthParameterCovariance();
522 }
523 }
524
525 Type CurrentMeanLengthYoungStorage() const {
526 return fims_math::exp(mean_length_young_vector_[0]);
527 }
528
529 Type CurrentMeanLengthOldStorage() const {
530 return fims_math::exp(mean_length_old_vector_[0]);
531 }
532
533 Type CurrentMeanLengthYoung() const {
534 switch (length_reference_parameterization_) {
535 case LengthReferenceParameterization::kEstimatedReferenceLengths:
536 return CurrentMeanLengthYoungStorage();
537
538 case LengthReferenceParameterization::
539 kConstantLengthYoungEstimatedLengthOld:
540 return constant_mean_length_young_;
541
542 case LengthReferenceParameterization::
543 kEstimatedLengthYoungBelowConstantLengthOld:
544 return fims_math::inv_logit(static_cast<Type>(0.0),
545 constant_mean_length_old_,
546 mean_length_young_vector_[0]);
547
548 case LengthReferenceParameterization::kBothConstant:
549 return constant_mean_length_young_;
550 }
551
552 return CurrentMeanLengthYoungStorage();
553 }
554
555 Type CurrentMeanLengthOld() const {
556 switch (length_reference_parameterization_) {
557 case LengthReferenceParameterization::kEstimatedReferenceLengths:
558 case LengthReferenceParameterization::
559 kConstantLengthYoungEstimatedLengthOld:
560 // Recover older length from younger length plus the positive
561 // difference.
562 return CurrentMeanLengthYoung() + CurrentMeanLengthOldStorage();
563
564 case LengthReferenceParameterization::
565 kEstimatedLengthYoungBelowConstantLengthOld:
566 return constant_mean_length_old_;
567
568 case LengthReferenceParameterization::kBothConstant:
569 return constant_mean_length_old_;
570 }
571
572 return CurrentMeanLengthOldStorage();
573 }
574
575 Type CurrentGrowthCoefficient() const {
576 return fims_math::exp(growth_coefficient_vector_[0]);
577 }
578 Type CurrentReferenceAgeForLengthYoung() const {
579 return reference_age_for_length_young_vector_[0];
580 }
581 Type CurrentReferenceAgeForLengthOld() const {
582 return reference_age_for_length_old_vector_[0];
583 }
584 Type CurrentLengthWeightA() const {
585 return fims_math::exp(length_weight_a_vector_[0]);
586 }
587 Type CurrentLengthWeightB() const {
588 return fims_math::exp(length_weight_b_vector_[0]);
589 }
590 Type CurrentLengthAtAgeSdAtReferenceAge1() const {
591 return fims_math::exp(length_at_age_sd_young_vector_[0]);
592 }
593 Type CurrentLengthAtAgeSdAtReferenceAge2() const {
594 return fims_math::exp(length_at_age_sd_old_vector_[0]);
595 }
596 Type CurrentSdLengthAtRefAgeYoung() const {
597 return fims_math::exp(log_sd_mean_length_young_vector_[0]);
598 }
599
600 Type CurrentSdLengthAtRefAgeOld() const {
601 return fims_math::exp(log_sd_mean_length_old_vector_[0]);
602 }
603
604 Type CurrentSdGrowthCoefficient() const {
605 return fims_math::exp(log_sd_growth_coefficient_vector_[0]);
606 }
607
608 Type CurrentCorrLengthAtRefAgeYoungLengthAtRefAgeOld() const {
610 static_cast<Type>(-1.0), static_cast<Type>(1.0),
611 mean_length_young_mean_length_old_logit_corr_vector_[0]);
612 }
613
614 Type CurrentCorrLengthAtRefAgeYoungK() const {
616 static_cast<Type>(-1.0), static_cast<Type>(1.0),
617 mean_length_young_growth_coefficient_logit_corr_vector_[0]);
618 }
619
620 Type CurrentCorrLengthAtRefAgeOldK() const {
622 static_cast<Type>(-1.0), static_cast<Type>(1.0),
623 mean_length_old_growth_coefficient_logit_corr_vector_[0]);
624 }
625
626 Type CurrentMeanLengthYoungVariance() const {
627 const Type sd = CurrentSdLengthAtRefAgeYoung();
628 return sd * sd;
629 }
630
631 Type CurrentMeanLengthOldVariance() const {
632 const Type sd = CurrentSdLengthAtRefAgeOld();
633 return sd * sd;
634 }
635
636 Type CurrentGrowthCoefficientVariance() const {
637 const Type sd = CurrentSdGrowthCoefficient();
638 return sd * sd;
639 }
640
641 Type CurrentMeanLengthYoungLengthAtRefAgeOldCovariance() const {
642 return CurrentCorrLengthAtRefAgeYoungLengthAtRefAgeOld() *
643 CurrentSdLengthAtRefAgeYoung() * CurrentSdLengthAtRefAgeOld();
644 }
645
646 Type CurrentMeanLengthYoungKCovariance() const {
647 return CurrentCorrLengthAtRefAgeYoungK() * CurrentSdLengthAtRefAgeYoung() *
648 CurrentSdGrowthCoefficient();
649 }
650
651 Type CurrentMeanLengthOldKCovariance() const {
652 return CurrentCorrLengthAtRefAgeOldK() * CurrentSdLengthAtRefAgeOld() *
653 CurrentSdGrowthCoefficient();
654 }
655
656 bool HasInterpolationSdInputs() const {
657 return length_at_age_sd_young_vector_.size() > 0 ||
658 length_at_age_sd_old_vector_.size() > 0;
659 }
660
661 bool HasAnyStructuredDeltaMethodInput() const {
662 return log_sd_mean_length_young_vector_.size() > 0 ||
663 log_sd_mean_length_old_vector_.size() > 0 ||
664 log_sd_growth_coefficient_vector_.size() > 0 ||
665 mean_length_young_mean_length_old_logit_corr_vector_.size() > 0 ||
666 mean_length_young_growth_coefficient_logit_corr_vector_.size() > 0 ||
667 mean_length_old_growth_coefficient_logit_corr_vector_.size() > 0;
668 }
669
670 bool HasStructuredDeltaMethodInputs() const {
671 return log_sd_mean_length_young_vector_.size() > 0 &&
672 log_sd_mean_length_old_vector_.size() > 0 &&
673 log_sd_growth_coefficient_vector_.size() > 0 &&
674 mean_length_young_mean_length_old_logit_corr_vector_.size() > 0 &&
675 mean_length_young_growth_coefficient_logit_corr_vector_.size() > 0 &&
676 mean_length_old_growth_coefficient_logit_corr_vector_.size() > 0;
677 }
678
679 void EnsureParamsSet() const {
680 if (!use_param_vectors_ || mean_length_young_vector_.size() < 1 ||
681 mean_length_old_vector_.size() < 1 ||
682 growth_coefficient_vector_.size() < 1 ||
683 reference_age_for_length_young_vector_.size() < 1 ||
684 reference_age_for_length_old_vector_.size() < 1 ||
685 length_weight_a_vector_.size() < 1 ||
686 length_weight_b_vector_.size() < 1) {
687 throw std::runtime_error(
688 "VonBertalanffySchnuteGrowth parameters not set");
689 }
690
691 if (mean_length_young_vector_.size() != 1 ||
692 mean_length_old_vector_.size() != 1 ||
693 growth_coefficient_vector_.size() != 1 ||
694 reference_age_for_length_young_vector_.size() != 1 ||
695 reference_age_for_length_old_vector_.size() != 1 ||
696 length_weight_a_vector_.size() != 1 ||
697 length_weight_b_vector_.size() != 1) {
698 throw std::runtime_error(
699 "VonBertalanffySchnuteGrowthModelAdapter currently supports a single "
700 "growth pattern; expected size 1 for von Bertalanffy--Schnute and "
701 "length-weight parameter vectors");
702 }
703
704 const bool has_sd = HasInterpolationSdInputs();
705 const bool has_any_structured_delta = HasAnyStructuredDeltaMethodInput();
706 const bool has_structured_delta = HasStructuredDeltaMethodInputs();
707
708 if (!has_sd && !has_any_structured_delta) {
709 throw std::runtime_error(
710 "VonBertalanffySchnuteGrowthModelAdapter requires either "
711 "both length_at_age_sd_young and length_at_age_sd_old, "
712 "or the structured delta-method growth variability inputs");
713 }
714
715 if (has_any_structured_delta && !has_structured_delta) {
716 throw std::runtime_error(
717 "VonBertalanffySchnuteGrowthModelAdapter requires all six structured "
718 "delta-method variability inputs when using that path");
719 }
720
721 if (has_sd && has_structured_delta) {
722 throw std::runtime_error(
723 "von Bertalanffy--Schnute growth adapter requires variability inputs "
724 "for exactly one supported path. Supply either the interpolation "
725 "inputs length_at_age_sd_young and length_at_age_sd_old or the full "
726 "delta-method variability inputs, but not both");
727 }
728
729 if (has_sd && (length_at_age_sd_young_vector_.size() != 1 ||
730 length_at_age_sd_old_vector_.size() != 1)) {
731 throw std::runtime_error(
732 "VonBertalanffySchnuteGrowthModelAdapter requires exactly one "
733 "length_at_age_sd_young value and one length_at_age_sd_old value");
734 }
735
736 if (has_structured_delta &&
737 (log_sd_mean_length_young_vector_.size() != 1 ||
738 log_sd_mean_length_old_vector_.size() != 1 ||
739 log_sd_growth_coefficient_vector_.size() != 1 ||
740 mean_length_young_mean_length_old_logit_corr_vector_.size() != 1 ||
741 mean_length_young_growth_coefficient_logit_corr_vector_.size() != 1 ||
742 mean_length_old_growth_coefficient_logit_corr_vector_.size() != 1)) {
743 throw std::runtime_error(
744 "VonBertalanffySchnuteGrowthModelAdapter currently supports a single "
745 "structured delta-method variability parameter set; expected "
746 "size 1 for each structured uncertainty input");
747 }
748 }
749};
750
751} // namespace fims_popdy
752
753#endif // POPULATION_DYNAMICS_GROWTH_MODEL_ADAPTER_HPP
Definition fims_vector.hpp:27
virtual bool SupportsAgeToLengthConversionDerived() const =0
Report whether this growth object can support the dynamic age-to-length conversion path.
virtual void Initialize(std::size_t n_years, std::size_t n_ages, std::size_t n_sexes=1)=0
Initialize any cached growth products.
virtual void SetAgeOffset(double min_age)=0
Set the minimum modeled age used to translate cached age indices.
virtual void PrepareGrowthProducts()=0
Prepare growth products for the current model state.
virtual Type EvaluateWeightAtLength(const Type &length) const =0
Evaluate weight at a supplied length.
virtual const GrowthProducts< Type > * TryGetPreparedGrowthProducts() const =0
Return prepared growth products without triggering preparation.
LengthReferenceParameterization
Options for how the two reference lengths are supplied.
Definition growth_model_adapter.hpp:87
void UseConstantReferenceMeanLengths(Type constant_mean_length_young, Type constant_mean_length_old)
Fix both young and old reference mean lengths.
Definition growth_model_adapter.hpp:139
fims::Vector< Type > & LogSdGrowthCoefficientVector()
Access the log-SD vector for growth_coefficient.
Definition growth_model_adapter.hpp:273
virtual const Type evaluate(int year, const double &a) override
Calculates the growth at the independent variable value.
Definition growth_model_adapter.hpp:357
fims::Vector< Type > & LogitCorrLengthAtRefAgeYoungKVector()
Access the transformed correlation vector for mean_length_young and growth_coefficient.
Definition growth_model_adapter.hpp:295
fims::Vector< Type > & LogSdLengthAtRefAgeOldVector()
Access the log-SD vector for mean_length_old.
Definition growth_model_adapter.hpp:263
fims::Vector< Type > & ReferenceAgeForLengthYoungVector()
Access the first reference-age vector.
Definition growth_model_adapter.hpp:189
void SetAgeOffset(double min_age) override
Set the minimum modeled age used by cached growth products.
Definition growth_model_adapter.hpp:316
bool SupportsAgeToLengthConversionDerived() const override
Report that the adapter supports growth-derived age-to-length conversion calculations.
Definition growth_model_adapter.hpp:355
fims::Vector< Type > & LengthWeightAVector()
Access the log-scale length-weight-a vector.
Definition growth_model_adapter.hpp:211
void Initialize(std::size_t n_years, std::size_t n_ages, std::size_t n_sexes=1) override
Initialize the backing growth model and cache dimensions.
Definition growth_model_adapter.hpp:331
fims::Vector< Type > & LogitCorrLengthAtRefAgeOldKVector()
Access the transformed correlation vector for mean_length_old and growth_coefficient.
Definition growth_model_adapter.hpp:306
fims::Vector< Type > & ReferenceAgeForLengthOldVector()
Access the second reference-age vector.
Definition growth_model_adapter.hpp:200
void UseEstimatedMeanLengthYoungBelowConstantMeanLengthOld(Type constant_mean_length_old)
Estimate young reference length below a fixed old reference length.
Definition growth_model_adapter.hpp:123
Type EvaluateWeightAtLength(const Type &length) const override
Evaluate the length-weight relationship at a supplied length.
Definition growth_model_adapter.hpp:439
fims::Vector< Type > & MeanLengthOldVector()
Access working-scale storage for the older reference length.
Definition growth_model_adapter.hpp:166
fims::Vector< Type > & LengthWeightBVector()
Access the log-scale length-weight-b vector.
Definition growth_model_adapter.hpp:222
fims::Vector< Type > & LogitCorrLengthAtRefAgeYoungLengthAtRefAgeOldVector()
Access the transformed correlation vector for mean_length_young and mean_length_old.
Definition growth_model_adapter.hpp:284
void UseEstimatedReferenceMeanLengths()
Estimate both reference mean lengths.
Definition growth_model_adapter.hpp:97
void PrepareGrowthProducts() override
Prepare growth products for the current model state.
Definition growth_model_adapter.hpp:404
fims::Vector< Type > & MeanLengthYoungVector()
Access the working-scale storage for the first reference-length parameter.
Definition growth_model_adapter.hpp:153
const GrowthProducts< Type > * TryGetPreparedGrowthProducts() const override
Return prepared growth products without triggering preparation.
Definition growth_model_adapter.hpp:422
fims::Vector< Type > & LogSdLengthAtRefAgeYoungVector()
Access the log-SD vector for mean_length_young.
Definition growth_model_adapter.hpp:253
fims::Vector< Type > & GrowthCoefficientVector()
Access the log-scale VonBertalanffySchnute growth coefficient vector.
Definition growth_model_adapter.hpp:178
fims::Vector< Type > & LengthAtAgeSdYoungVector()
Access the log-scale length-at-age SD at the younger reference age.
Definition growth_model_adapter.hpp:233
fims::Vector< Type > & LengthAtAgeSdOldVector()
Access the log-scale length-at-age SD at the older reference age.
Definition growth_model_adapter.hpp:243
void UseConstantMeanLengthYoungWithEstimatedMeanLengthOld(Type constant_mean_length_young)
Fix young reference length and estimate older reference mean length.
Definition growth_model_adapter.hpp:109
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
const Type inv_logit(const Type &a, const Type &b, const Type &logit_x)
An inverse logit function for bounding of parameters.
Definition fims_math.hpp:294
Establishes the FIMS Vector class.
Declares the GrowthBase class which is the base class for all growth functors.
Concrete growth model implementation (Phase 1).
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
GrowthBase()
Constructor.
Definition growth_base.hpp:34
Growth "products" in a consistent (year, age, sex) space.
Definition growth_products.hpp:26
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 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 length_weight_b
Exponent in the length-weight relationship, W = a * L^b.
Definition vonb_schnute.hpp:47
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:231
Type mean_length_old
Expected length at the second reference age.
Definition vonb_schnute.hpp:36
Defines the VonBertalanffySchnuteGrowth class, which inherits from the GrowthBase class.