From 755849690f07e62381a4dfd79f7e34f73bd86780 Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Tue, 29 Aug 2023 17:02:41 -0400 Subject: [PATCH 01/11] refactor add_tmb_to_fims_internal --- .../interface/rcpp/rcpp_objects/rcpp_data.hpp | 154 ++--- .../rcpp/rcpp_objects/rcpp_fleet.hpp | 226 ++------ .../rcpp/rcpp_objects/rcpp_growth.hpp | 75 +-- .../rcpp/rcpp_objects/rcpp_maturity.hpp | 151 ++--- .../rcpp/rcpp_objects/rcpp_population.hpp | 225 ++------ .../rcpp/rcpp_objects/rcpp_recruitment.hpp | 273 +++------ .../rcpp/rcpp_objects/rcpp_selectivity.hpp | 534 ++++++------------ .../rcpp_objects/rcpp_tmb_distribution.hpp | 500 +++++++--------- 8 files changed, 683 insertions(+), 1455 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 0c5ab585..6168697b 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -78,61 +78,42 @@ class AgeCompDataInterface : public DataInterface { **/ virtual uint32_t get_id() { return this->id; } - /** - * @brief adds parameters to the model - */ - virtual bool add_to_fims_tmb() { - std::shared_ptr> age_comp_data_0 = - std::make_shared>(this->ymax, - this->amax); - std::shared_ptr> age_comp_data_1 = - std::make_shared>(this->ymax, - this->amax); - std::shared_ptr> age_comp_data_2 = - std::make_shared>(this->ymax, - this->amax); - std::shared_ptr> age_comp_data_3 = - std::make_shared>(this->ymax, - this->amax); - - age_comp_data_0->id = this->id; - - age_comp_data_1->id = this->id; - - age_comp_data_2->id = this->id; - - age_comp_data_3->id = this->id; - - for (int y = 0; y < ymax; y++) { - for (int a = 0; a < amax; a++) { - int index_ya = y * amax + a; - age_comp_data_0->at(y, a) = this->age_comp_data[index_ya]; - age_comp_data_1->at(y, a) = this->age_comp_data[index_ya]; - age_comp_data_2->at(y, a) = this->age_comp_data[index_ya]; - age_comp_data_3->at(y, a) = this->age_comp_data[index_ya]; - } - } - - std::shared_ptr> d0 = - fims::Information::GetInstance(); - - d0->data_objects[this->id] = age_comp_data_0; - std::shared_ptr> d1 = - fims::Information::GetInstance(); - - d1->data_objects[this->id] = age_comp_data_1; - std::shared_ptr> d2 = - fims::Information::GetInstance(); - - d2->data_objects[this->id] = age_comp_data_2; - std::shared_ptr> d3 = - fims::Information::GetInstance(); +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr> age_comp_data = + std::make_shared> (this->ymax, + this->amax); + + age_comp_data->id = this->id; + for (int y = 0; y < ymax; y++) { + for (int a = 0; a < amax; a++) { + int index_ya = y * amax + a; + age_comp_data->at(y, a) = this->age_comp_data[index_ya]; + } + } + + std::shared_ptr> info = + fims::Information::GetInstance(); + + info->data_objects[this->id] = age_comp_data; + } - d3->data_objects[this->id] = age_comp_data_3; + /** + * @brief adds parameters to the model + */ + virtual bool add_to_fims_tmb() { + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - return true; - } + return true; + } + + #endif }; /** @@ -158,52 +139,41 @@ class IndexDataInterface : public DataInterface { **/ virtual uint32_t get_id() { return this->id; } - /** - *@brief function to add to TMB - */ - virtual bool add_to_fims_tmb() { - std::shared_ptr> index_data_0 = - std::make_shared>(this->ymax); - std::shared_ptr> index_data_1 = - std::make_shared>(this->ymax); - std::shared_ptr> index_data_2 = - std::make_shared>(this->ymax); - std::shared_ptr> index_data_3 = - std::make_shared>(this->ymax); - index_data_0->id = this->id; - - index_data_1->id = this->id; - - index_data_2->id = this->id; - - index_data_3->id = this->id; - - for (int y = 0; y < ymax; y++) { - index_data_0->at(y) = this->index_data[y]; - index_data_1->at(y) = this->index_data[y]; - index_data_2->at(y) = this->index_data[y]; - index_data_3->at(y) = this->index_data[y]; - } + +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr> data = + std::make_shared> (this->ymax); - std::shared_ptr> d0 = - fims::Information::GetInstance(); + data->id = this->id; - d0->data_objects[this->id] = index_data_0; + for (int y = 0; y < ymax; y++) { + data->at(y) = this->index_data[y]; + } - std::shared_ptr> d1 = - fims::Information::GetInstance(); + std::shared_ptr> info = + fims::Information::GetInstance(); - d1->data_objects[this->id] = index_data_1; - std::shared_ptr> d2 = - fims::Information::GetInstance(); + info->data_objects[this->id] = data; - d2->data_objects[this->id] = index_data_2; - std::shared_ptr> d3 = - fims::Information::GetInstance(); + } - d3->data_objects[this->id] = index_data_3; - return true; - } + /** + *@brief function to add to TMB + */ + virtual bool add_to_fims_tmb() { + + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + + return true; + } + +#endif }; #endif diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index 689ea09f..a96e7d06 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -95,188 +95,68 @@ class FleetInterface : public FIMSRcppInterfaceBase { this->selectivity_id = selectivity_id; } - /** @brief this adds the values to the TMB model object */ - virtual bool add_to_fims_tmb() { - // base model - std::shared_ptr> d0 = - fims::Information::GetInstance(); - std::shared_ptr> f0 = - std::make_shared>(); - - // set relative info - f0->id = this->id; - f0->is_survey = this->is_survey; - f0->nages = this->nages; - f0->nyears = this->nyears; - f0->agecomp_likelihood_id = this->agecomp_likelihood_id; - f0->index_likelihood_id = this->index_likelihood_id; - f0->observed_agecomp_data_id = this->observed_agecomp_data_id; - f0->observed_index_data_id = this->observed_index_data_id; - f0->selectivity_id = this->selectivity_id; - - f0->log_obs_error = this->log_obs_error.value; - if (this->log_obs_error.estimated) { - d0->RegisterParameter(f0->log_obs_error); - } - f0->log_q = this->log_q; - if (this->estimate_q) { - if (this->random_q) { - d0->RegisterRandomEffect(f0->log_q); - } else { - d0->RegisterParameter(f0->log_q); - } - } - - f0->log_Fmort.resize(this->log_Fmort.size()); - for (int i = 0; i < log_Fmort.size(); i++) { - f0->log_Fmort[i] = this->log_Fmort[i]; - - if (this->estimate_F) { - if (this->random_F) { - d0->RegisterRandomEffect(f0->log_Fmort[i]); - } else { - d0->RegisterParameter(f0->log_Fmort[i]); +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr> info = + fims::Information::GetInstance(); + + std::shared_ptr> f = + std::make_shared> (); + + // set relative info + f->id = this->id; + f->is_survey = this->is_survey; + f->nages = this->nages; + f->nyears = this-> nyears; + f->agecomp_likelihood_id = this->agecomp_likelihood_id; + f->index_likelihood_id = this->index_likelihood_id; + f->observed_agecomp_data_id = this->observed_agecomp_data_id; + f->observed_index_data_id = this->observed_index_data_id; + f->selectivity_id = this->selectivity_id; + + f->log_obs_error = this->log_obs_error.value; + if (this->log_obs_error.estimated) { + info->RegisterParameter(f->log_obs_error); } - } - } - // add to Information - d0->fleets[f0->id] = f0; - - // 1st derivative model - std::shared_ptr> d1 = - fims::Information::GetInstance(); - - std::shared_ptr> f1 = - std::make_shared>(); - - f1->id = this->id; - f1->is_survey = this->is_survey; - f1->nages = this->nages; - f1->nyears = this->nyears; - f1->agecomp_likelihood_id = this->agecomp_likelihood_id; - f1->index_likelihood_id = this->index_likelihood_id; - f1->observed_agecomp_data_id = this->observed_agecomp_data_id; - f1->observed_index_data_id = this->observed_index_data_id; - f1->log_obs_error = this->log_obs_error.value; - if (this->log_obs_error.estimated) { - d1->RegisterParameter(f1->log_obs_error); - } - f1->selectivity_id = this->selectivity_id; - - f1->log_q = this->log_q; - if (this->estimate_q) { - if (this->random_q) { - d1->RegisterRandomEffect(f1->log_q); - } else { - d1->RegisterParameter(f1->log_q); - } - } - - f1->log_Fmort.resize(this->log_Fmort.size()); - for (int i = 0; i < log_Fmort.size(); i++) { - f1->log_Fmort[i] = this->log_Fmort[i]; - if (this->estimate_F) { - if (this->random_F) { - d1->RegisterRandomEffect(f1->log_Fmort[i]); - } else { - d1->RegisterParameter(f1->log_Fmort[i]); + f->log_q = this->log_q; + if (this->estimate_q) { + if (this->random_q) { + info->RegisterRandomEffect(f->log_q); + } else { + info->RegisterParameter(f->log_q); + } } - } - } - // add to Information - d1->fleets[f1->id] = f1; - - // 2nd derivative model - std::shared_ptr> d2 = - fims::Information::GetInstance(); - - std::shared_ptr> f2 = - std::make_shared>(); - - f2->id = this->id; - f2->is_survey = this->is_survey; - f2->nages = this->nages; - f2->nyears = this->nyears; - f2->agecomp_likelihood_id = this->agecomp_likelihood_id; - f2->index_likelihood_id = this->index_likelihood_id; - f2->observed_agecomp_data_id = this->observed_agecomp_data_id; - f2->observed_index_data_id = this->observed_index_data_id; - f2->log_obs_error = this->log_obs_error.value; - if (this->log_obs_error.estimated) { - d2->RegisterParameter(f2->log_obs_error); - } - f2->selectivity_id = this->selectivity_id; - f2->log_q = this->log_q; - if (this->estimate_q) { - if (this->random_q) { - d2->RegisterRandomEffect(f2->log_q); - } else { - d2->RegisterParameter(f2->log_q); - } - } - - f2->log_Fmort.resize(this->log_Fmort.size()); - for (int i = 0; i < log_Fmort.size(); i++) { - f2->log_Fmort[i] = this->log_Fmort[i]; - if (this->estimate_F) { - if (this->random_F) { - d2->RegisterRandomEffect(f2->log_Fmort[i]); - } else { - d2->RegisterParameter(f2->log_Fmort[i]); + f->log_Fmort.resize(this->log_Fmort.size()); + for (int i = 0; i < log_Fmort.size(); i++) { + f->log_Fmort[i] = this->log_Fmort[i]; + + if (this->estimate_F) { + if (this->random_F) { + info->RegisterRandomEffect(f->log_Fmort[i]); + } else { + info->RegisterParameter(f->log_Fmort[i]); + } + } } - } + // add to Information + info->fleets[f->id] = f; } - // add to Information - d2->fleets[f2->id] = f2; - - // 3rd derivative model - std::shared_ptr> d3 = - fims::Information::GetInstance(); - - std::shared_ptr> f3 = - std::make_shared>(); + /** @brief this adds the values to the TMB model object */ + virtual bool add_to_fims_tmb() { + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - f3->id = this->id; - f3->is_survey = this->is_survey; - f3->nages = this->nages; - f3->nyears = this->nyears; - f3->agecomp_likelihood_id = this->agecomp_likelihood_id; - f3->index_likelihood_id = this->index_likelihood_id; - f3->observed_agecomp_data_id = this->observed_agecomp_data_id; - f3->observed_index_data_id = this->observed_index_data_id; - f3->selectivity_id = this->selectivity_id; - f3->log_obs_error = this->log_obs_error.value; - if (this->log_obs_error.estimated) { - d3->RegisterParameter(f3->log_obs_error); + return true; } - f3->log_q = this->log_q; - if (this->estimate_q) { - if (this->random_q) { - d3->RegisterRandomEffect(f3->log_q); - } else { - d3->RegisterParameter(f3->log_q); - } - } - - f3->log_Fmort.resize(this->log_Fmort.size()); - for (int i = 0; i < log_Fmort.size(); i++) { - f3->log_Fmort[i] = this->log_Fmort[i]; - if (this->estimate_F) { - if (this->random_F) { - d3->RegisterRandomEffect(f3->log_Fmort[i]); - } else { - d3->RegisterParameter(f3->log_Fmort[i]); - } - } - } - - // add to Information - d3->fleets[f3->id] = f3; - return true; - } + +#endif }; uint32_t FleetInterface::id_g = 1; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp index 3829281f..3369e4fd 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp @@ -104,66 +104,35 @@ class EWAAGrowthInterface : public GrowthInterfaceBase { EWAAGrowth.ewaa = this->ewaa; return EWAAGrowth.evaluate(age); } +#ifdef TMB_MODEL - /** @brief this adds the values to the TMB model object */ - virtual bool add_to_fims_tmb() { - // base model - std::shared_ptr > d0 = - fims::Information::GetInstance(); + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > b0 = - std::make_shared >(); + std::shared_ptr > data = + std::make_shared >(); - // set relative info - b0->id = this->id; - b0->ewaa = make_map(this->ages, this->weights); // this->ewaa; - // add to Information - d0->growth_models[b0->id] = b0; - - // base model - std::shared_ptr > d1 = - fims::Information::GetInstance(); - - std::shared_ptr > b1 = - std::make_shared >(); - - // set relative info - b1->id = this->id; - b1->ewaa = make_map(this->ages, this->weights); // this->ewaa; - - // add to Information - d1->growth_models[b0->id] = b1; - - // base model - std::shared_ptr > d2 = - fims::Information::GetInstance(); - - std::shared_ptr > b2 = - std::make_shared >(); - - // set relative info - b2->id = this->id; - b2->ewaa = make_map(this->ages, this->weights); // this->ewaa; - - // add to Information - d2->growth_models[b2->id] = b2; - - // base model - std::shared_ptr > d3 = - fims::Information::GetInstance(); + // set relative info + data->id = this->id; + data->ewaa = make_map(this->ages, this->weights); //this->ewaa; + // add to Information + info->growth_models[data->id] = data; + } - std::shared_ptr > b3 = - std::make_shared >(); + /** @brief this adds the values to the TMB model object */ + virtual bool add_to_fims_tmb() { + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - // set relative info - b3->id = this->id; - b3->ewaa = make_map(this->ages, this->weights); // this->ewaa; - // add to Information - d3->growth_models[b3->id] = b3; + return true; + } - return true; - } +#endif }; #endif diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp index 1d1e27d4..aabec53b 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp @@ -79,123 +79,52 @@ class LogisticMaturityInterface : public MaturityInterfaceBase { return LogisticMat.evaluate(x); } - /** @brief this adds the parameter values and derivatives to the TMB model - * object */ - virtual bool add_to_fims_tmb() { - std::shared_ptr > d0 = - fims::Information::GetInstance(); - - std::shared_ptr > lm0 = - std::make_shared >(); - - // set relative info - lm0->id = this->id; - lm0->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d0->RegisterRandomEffect(lm0->median); - } else { - d0->RegisterParameter(lm0->median); - } +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); + + std::shared_ptr > maturity = + std::make_shared >(); + + // set relative info + maturity->id = this->id; + maturity->median = this->median.value; + if (this->median.estimated) { + if (this->median.is_random_effect) { + info->RegisterRandomEffect(maturity->median); + } else { + info->RegisterParameter(maturity->median); + } + } + maturity->slope = this->slope.value; + if (this->slope.estimated) { + if (this->slope.is_random_effect) { + info->RegisterRandomEffect(maturity->slope); + } else { + info->RegisterParameter(maturity->slope); + } + } + + // add to Information + info->maturity_models[maturity->id] = maturity; } - lm0->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d0->RegisterRandomEffect(lm0->slope); - } else { - d0->RegisterParameter(lm0->slope); - } - } - - // add to Information - d0->maturity_models[lm0->id] = lm0; - - std::shared_ptr > d1 = - fims::Information::GetInstance(); - std::shared_ptr > lm1 = - std::make_shared >(); + /** @brief this adds the parameter values and derivatives to the TMB model + * object */ + virtual bool add_to_fims_tmb() { - // set relative info - lm1->id = this->id; - lm1->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d1->RegisterRandomEffect(lm1->median); - } else { - d1->RegisterParameter(lm1->median); - } - } - lm1->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d1->RegisterRandomEffect(lm1->slope); - } else { - d1->RegisterParameter(lm1->slope); - } - } + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - // add to Information - d1->maturity_models[lm1->id] = lm1; - - std::shared_ptr > d2 = - fims::Information::GetInstance(); - - std::shared_ptr > lm2 = - std::make_shared >(); - - // set relative info - lm2->id = this->id; - lm2->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d2->RegisterRandomEffect(lm2->median); - } else { - d2->RegisterParameter(lm2->median); - } - } - lm2->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d2->RegisterRandomEffect(lm2->slope); - } else { - d2->RegisterParameter(lm2->slope); - } + return true; } - // add to Information - d2->maturity_models[lm2->id] = lm2; - - std::shared_ptr > d3 = - fims::Information::GetInstance(); - - std::shared_ptr > lm3 = - std::make_shared >(); - - // set relative info - lm3->id = this->id; - lm3->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d3->RegisterRandomEffect(lm3->median); - } else { - d3->RegisterParameter(lm3->median); - } - } - lm3->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d3->RegisterRandomEffect(lm3->slope); - } else { - d3->RegisterParameter(lm3->slope); - } - } - - // add to Information - d3->maturity_models[lm3->id] = lm3; - - return true; - } +#endif }; #endif \ No newline at end of file diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index a9e7593b..c0109bc5 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -97,178 +97,69 @@ class PopulationInterface : public PopulationInterfaceBase { fims::Population population; return population.Evaluate(); } - - /** @brief this adds the parameter values and derivatives to the TMB model - * object */ - virtual bool add_to_fims_tmb() { - // base model - std::shared_ptr > d0 = - fims::Information::GetInstance(); - - std::shared_ptr > b0 = - std::make_shared >(); - - // set relative info - b0->id = this->id; - b0->nyears = this->nyears; - b0->nfleets = this->nfleets; - b0->nseasons = this->nseasons; - b0->nages = this->nages; - if (this->nages == this->ages.size()) { - b0->ages.resize(this->nages); - } else { - warning("The ages vector is not of size nages."); - } - - b0->growth_id = this->growth_id; - b0->recruitment_id = this->recruitment_id; - b0->maturity_id = this->maturity_id; - b0->log_M.resize(this->log_M.size()); - b0->log_init_naa.resize(this->log_init_naa.size()); - for (int i = 0; i < log_M.size(); i++) { - b0->log_M[i] = this->log_M[i]; - if (estimate_M) { - d0->RegisterParameter(b0->log_M[i]); - } + +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); + + std::shared_ptr > population = + std::make_shared >(); + + // set relative info + population->id = this->id; + population->nyears = this->nyears; + population->nfleets = this->nfleets; + population->nseasons = this->nseasons; + population->nages = this->nages; + if (this->nages == this->ages.size()) { + population->ages.resize(this->nages); + } else { + warning("The ages vector is not of size nages."); + } + + population->growth_id = this->growth_id; + population->recruitment_id = this->recruitment_id; + population->maturity_id = this->maturity_id; + population->log_M.resize(this->log_M.size()); + population->log_init_naa.resize(this->log_init_naa.size()); + for (size_t i = 0; i < log_M.size(); i++) { + population->log_M[i] = this->log_M[i]; + if (estimate_M) { + info->RegisterParameter(population->log_M[i]); + } + } + + for (size_t i = 0; i < log_init_naa.size(); i++) { + population->log_init_naa[i] = this->log_init_naa[i]; + if (estimate_initNAA) { + info->RegisterParameter(population->log_init_naa[i]); + } + + } + for (size_t i = 0; i < ages.size(); i++) { + population->ages[i] = this->ages[i]; + } + + // add to Information + info->populations[population->id] = population; } - for (int i = 0; i < log_init_naa.size(); i++) { - b0->log_init_naa[i] = this->log_init_naa[i]; - if (estimate_initNAA) { - d0->RegisterParameter(b0->log_init_naa[i]); - } - } - for (int i = 0; i < ages.size(); i++) { - b0->ages[i] = this->ages[i]; - } - - // add to Information - d0->populations[b0->id] = b0; - - // first-order derivative - std::shared_ptr > d1 = - fims::Information::GetInstance(); - - std::shared_ptr > b1 = - std::make_shared >(); + /** @brief this adds the parameter values and derivatives to the TMB model + * object */ + virtual bool add_to_fims_tmb() { - // set relative info - b1->id = this->id; - b1->nyears = this->nyears; - b1->nfleets = this->nfleets; - b1->nseasons = this->nseasons; - b1->nages = this->nages; - b1->ages.resize(this->nages); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - b1->growth_id = this->growth_id; - b1->recruitment_id = this->recruitment_id; - b1->maturity_id = this->maturity_id; - - b1->log_M.resize(this->log_M.size()); - b1->log_init_naa.resize(this->log_init_naa.size()); - for (int i = 0; i < log_M.size(); i++) { - b1->log_M[i] = this->log_M[i]; - if (estimate_M) { - d1->RegisterParameter(b1->log_M[i]); - } - } - for (int i = 0; i < log_init_naa.size(); i++) { - b1->log_init_naa[i] = this->log_init_naa[i]; - if (estimate_initNAA) { - d1->RegisterParameter(b1->log_init_naa[i]); - } - } - for (int i = 0; i < ages.size(); i++) { - b1->ages[i] = this->ages[i]; + return true; } - - // add to Information - d1->populations[b1->id] = b1; - - // second-order derivative - std::shared_ptr > d2 = - fims::Information::GetInstance(); - - std::shared_ptr > b2 = - std::make_shared >(); - - // set relative info - b2->id = this->id; - b2->nyears = this->nyears; - b2->nfleets = this->nfleets; - b2->nseasons = this->nseasons; - b2->nages = this->nages; - b2->log_M.resize(this->log_M.size()); - b2->ages.resize(nages); - - b2->growth_id = this->growth_id; - b2->recruitment_id = this->recruitment_id; - b2->maturity_id = this->maturity_id; - - b2->log_init_naa.resize(this->log_init_naa.size()); - for (int i = 0; i < log_M.size(); i++) { - b2->log_M[i] = this->log_M[i]; - if (estimate_M) { - d2->RegisterParameter(b2->log_M[i]); - } - } - for (int i = 0; i < log_init_naa.size(); i++) { - b2->log_init_naa[i] = this->log_init_naa[i]; - if (estimate_initNAA) { - d2->RegisterParameter(b2->log_init_naa[i]); - } - } - - for (int i = 0; i < ages.size(); i++) { - b2->ages[i] = this->ages[i]; - } - - // add to Information - d2->populations[b2->id] = b2; - - // third-order derivative - std::shared_ptr > d3 = - fims::Information::GetInstance(); - - std::shared_ptr > b3 = - std::make_shared >(); - - // set relative info - b3->id = this->id; - b3->nyears = this->nyears; - b3->nfleets = this->nfleets; - b3->nseasons = this->nseasons; - b3->nages = this->nages; - b3->log_M.resize(this->log_M.size()); - b3->log_init_naa.resize(this->log_init_naa.size()); - b3->ages.resize(this->nages); - - b3->growth_id = this->growth_id; - b3->recruitment_id = this->recruitment_id; - b3->maturity_id = this->maturity_id; - - for (int i = 0; i < log_M.size(); i++) { - b3->log_M[i] = this->log_M[i]; - if (estimate_M) { - d3->RegisterParameter(b3->log_M[i]); - } - } - for (int i = 0; i < log_init_naa.size(); i++) { - b3->log_init_naa[i] = this->log_init_naa[i]; - if (estimate_initNAA) { - d3->RegisterParameter(b3->log_init_naa[i]); - } - } - - for (int i = 0; i < ages.size(); i++) { - b3->ages[i] = this->ages[i]; - } - - // add to Information - d3->populations[b3->id] = b3; - - return true; - } + +#endif }; #endif diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp index c8b6062c..0df6501e 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp @@ -121,211 +121,74 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase { return NLL.evaluate_nll(); } - /** @brief this adds the parameter values and derivatives to the TMB model - * object */ - virtual bool add_to_fims_tmb() { - // base model - std::shared_ptr > d0 = - fims::Information::GetInstance(); - - std::shared_ptr > b0 = - std::make_shared >(); - - // set relative info - b0->id = this->id; - b0->logit_steep = this->logit_steep.value; - if (this->logit_steep.estimated) { - if (this->logit_steep.is_random_effect) { - d0->RegisterRandomEffect(b0->logit_steep); - } else { - d0->RegisterParameter(b0->logit_steep); - } - } - b0->log_rzero = this->log_rzero.value; - if (this->log_rzero.estimated) { - if (this->log_rzero.is_random_effect) { - d0->RegisterRandomEffect(b0->log_rzero); - } else { - d0->RegisterParameter(b0->log_rzero); - } - } - b0->log_sigma_recruit = this->log_sigma_recruit.value; - if (this->log_sigma_recruit.estimated) { - if (this->log_sigma_recruit.is_random_effect) { - d0->RegisterRandomEffect(b0->log_sigma_recruit); - } else { - d0->RegisterParameter(b0->log_sigma_recruit); - } - } - - b0->recruit_deviations.resize(this->deviations.size()); - if (this->estimate_deviations) { - for (size_t i = 0; i < b0->recruit_deviations.size(); i++) { - b0->recruit_deviations[i] = this->deviations[i]; - d0->RegisterParameter(b0->recruit_deviations[i]); - } - } else { - for (size_t i = 0; i < b0->recruit_deviations.size(); i++) { - b0->recruit_deviations[i] = this->deviations[i]; - } - } - - b0->use_recruit_bias_adjustment = this->use_bias_correction; - // add to Information - d0->recruitment_models[b0->id] = b0; - - // first-order derivative - std::shared_ptr > d1 = - fims::Information::GetInstance(); - - std::shared_ptr > b1 = - std::make_shared >(); - - // set relative info - b1->id = this->id; - b1->logit_steep = this->logit_steep.value; - if (this->logit_steep.estimated) { - if (this->logit_steep.is_random_effect) { - d1->RegisterRandomEffect(b1->logit_steep); - } else { - d1->RegisterParameter(b1->logit_steep); - } - } - b1->log_rzero = this->log_rzero.value; - if (this->log_rzero.estimated) { - if (this->log_rzero.is_random_effect) { - d1->RegisterRandomEffect(b1->log_rzero); - } else { - d1->RegisterParameter(b1->log_rzero); - } - } - b1->log_sigma_recruit = this->log_sigma_recruit.value; - if (this->log_sigma_recruit.estimated) { - if (this->log_sigma_recruit.is_random_effect) { - d1->RegisterRandomEffect(b1->log_sigma_recruit); - } else { - d1->RegisterParameter(b1->log_sigma_recruit); - } - } - - b1->recruit_deviations.resize(this->deviations.size()); - if (this->estimate_deviations) { - for (size_t i = 0; i < b1->recruit_deviations.size(); i++) { - b1->recruit_deviations[i] = this->deviations[i]; - d1->RegisterParameter(b1->recruit_deviations[i]); - } - } else { - for (size_t i = 0; i < b1->recruit_deviations.size(); i++) { - b1->recruit_deviations[i] = this->deviations[i]; - } - } - - b1->use_recruit_bias_adjustment = this->use_bias_correction; - // add to Information - d1->recruitment_models[b1->id] = b1; - - // second-order derivative - std::shared_ptr > d2 = - fims::Information::GetInstance(); - - std::shared_ptr > b2 = - std::make_shared >(); - - // set relative info - b2->id = this->id; - b2->logit_steep = this->logit_steep.value; - if (this->logit_steep.estimated) { - if (this->logit_steep.is_random_effect) { - d2->RegisterRandomEffect(b2->logit_steep); - } else { - d2->RegisterParameter(b2->logit_steep); - } - } - b2->log_rzero = this->log_rzero.value; - if (this->log_rzero.estimated) { - if (this->log_rzero.is_random_effect) { - d2->RegisterRandomEffect(b2->log_rzero); - } else { - d2->RegisterParameter(b2->log_rzero); - } - } - b2->log_sigma_recruit = this->log_sigma_recruit.value; - if (this->log_sigma_recruit.estimated) { - if (this->log_sigma_recruit.is_random_effect) { - d2->RegisterRandomEffect(b2->log_sigma_recruit); - } else { - d2->RegisterParameter(b2->log_sigma_recruit); - } - } - - b2->recruit_deviations.resize(this->deviations.size()); - if (this->estimate_deviations) { - for (size_t i = 0; i < b2->recruit_deviations.size(); i++) { - b2->recruit_deviations[i] = this->deviations[i]; - d2->RegisterParameter(b2->recruit_deviations[i]); - } - } else { - for (size_t i = 0; i < b2->recruit_deviations.size(); i++) { - b2->recruit_deviations[i] = this->deviations[i]; - } - } - - b2->use_recruit_bias_adjustment = this->use_bias_correction; - // add to Information - d2->recruitment_models[b2->id] = b2; - - // third-order derivative - std::shared_ptr > d3 = - fims::Information::GetInstance(); - - std::shared_ptr > b3 = - std::make_shared >(); - - // set relative info - b3->id = this->id; - b3->logit_steep = this->logit_steep.value; - if (this->logit_steep.estimated) { - if (this->logit_steep.is_random_effect) { - d3->RegisterRandomEffect(b3->logit_steep); - } else { - d3->RegisterParameter(b3->logit_steep); - } - } - b3->log_rzero = this->log_rzero.value; - if (this->log_rzero.estimated) { - if (this->log_rzero.is_random_effect) { - d3->RegisterRandomEffect(b3->log_rzero); - } else { - d3->RegisterParameter(b3->log_rzero); - } - } - b3->log_sigma_recruit = this->log_sigma_recruit.value; - if (this->log_sigma_recruit.estimated) { - if (this->log_sigma_recruit.is_random_effect) { - d3->RegisterRandomEffect(b3->log_sigma_recruit); - } else { - d3->RegisterParameter(b3->log_sigma_recruit); - } - } - - b3->recruit_deviations.resize(this->deviations.size()); - if (this->estimate_deviations) { - for (size_t i = 0; i < b3->recruit_deviations.size(); i++) { - b3->recruit_deviations[i] = this->deviations[i]; - d3->RegisterParameter(b3->recruit_deviations[i]); - } - } else { - for (size_t i = 0; i < b3->recruit_deviations.size(); i++) { - b3->recruit_deviations[i] = this->deviations[i]; - } - } - - b3->use_recruit_bias_adjustment = this->use_bias_correction; - // add to Information - d3->recruitment_models[b3->id] = b3; - - return true; - } +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); + + std::shared_ptr > recruitment = + std::make_shared >(); + + // set relative info + recruitment->id = this->id; + recruitment->logit_steep = this->logit_steep.value; + if (this->logit_steep.estimated) { + if (this->logit_steep.is_random_effect) { + info->RegisterRandomEffect(recruitment->logit_steep); + } else { + info->RegisterParameter(recruitment->logit_steep); + } + } + recruitment->log_rzero = this->log_rzero.value; + if (this->log_rzero.estimated) { + if (this->log_rzero.is_random_effect) { + info->RegisterRandomEffect(recruitment->log_rzero); + } else { + info->RegisterParameter(recruitment->log_rzero); + } + } + recruitment->log_sigma_recruit = this->log_sigma_recruit.value; + if (this->log_sigma_recruit.estimated) { + if (this->log_sigma_recruit.is_random_effect) { + info->RegisterRandomEffect(recruitment->log_sigma_recruit); + } else { + info->RegisterParameter(recruitment->log_sigma_recruit); + } + } + + recruitment->recruit_deviations.resize(this->deviations.size()); + if (this->estimate_deviations) { + for (size_t i = 0; i < recruitment->recruit_deviations.size(); i++) { + recruitment->recruit_deviations[i] = this->deviations[i]; + info->RegisterParameter(recruitment->recruit_deviations[i]); + } + } else { + for (size_t i = 0; i < recruitment->recruit_deviations.size(); i++) { + recruitment->recruit_deviations[i] = this->deviations[i]; + } + } + + recruitment->use_recruit_bias_adjustment = this->use_bias_correction; + // add to Information + info->recruitment_models[recruitment->id] = recruitment; + + } + + /** @brief this adds the parameter values and derivatives to the TMB model + * object */ + virtual bool add_to_fims_tmb() { + + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + + return true; + } + +#endif }; #endif diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp index d33cd0b7..cdb9f118 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp @@ -15,186 +15,121 @@ /**************************************************************** * Selectivity Rcpp interface * ***************************************************************/ + /** * @brief SelectivityInterfaceBase class should be inherited to * define different Rcpp interfaces for each possible Selectivity function * */ class SelectivityInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t id_g; /**< static id of the recruitment interface base*/ - uint32_t id; /**< id of the recruitment interface base */ - static std::map - selectivity_objects; /**< map associating the ids of +public: + static uint32_t id_g; /**< static id of the recruitment interface base*/ + uint32_t id; /**< id of the recruitment interface base */ + static std::map + selectivity_objects; /**< map associating the ids of SelectivityInterfaceBase to the objects */ - SelectivityInterfaceBase() { - this->id = SelectivityInterfaceBase::id_g++; - SelectivityInterfaceBase::selectivity_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } + SelectivityInterfaceBase() { + this->id = SelectivityInterfaceBase::id_g++; + SelectivityInterfaceBase::selectivity_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } - virtual ~SelectivityInterfaceBase() {} + virtual ~SelectivityInterfaceBase() { + } - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() = 0; + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() = 0; - /** - * @brief evaluate the function - * - */ - virtual double evaluate(double x) = 0; + /** + * @brief evaluate the function + * + */ + virtual double evaluate(double x) = 0; }; uint32_t SelectivityInterfaceBase::id_g = 1; std::map - SelectivityInterfaceBase::selectivity_objects; +SelectivityInterfaceBase::selectivity_objects; /** * @brief Rcpp interface for logistic selectivity as an S4 object. To * instantiate from R: logistic_selectivity <- new(fims$logistic_selectivity) */ class LogisticSelectivityInterface : public SelectivityInterfaceBase { - public: - Parameter median; /**< the index value at which the response reaches .5 */ - Parameter slope; /**< the width of the curve at the median */ - - LogisticSelectivityInterface() : SelectivityInterfaceBase() {} - - virtual ~LogisticSelectivityInterface() {} - - /** @brief returns the id for the logistic selectivity interface */ - virtual uint32_t get_id() { return this->id; } - - /** @brief evaluate the logistic selectivity function - * @param x The independent variable in the logistic function (e.g., age or - * size in selectivity). - */ - virtual double evaluate(double x) { - fims::LogisticSelectivity LogisticSel; - - LogisticSel.median = this->median.value; - LogisticSel.slope = this->slope.value; - return LogisticSel.evaluate(x); - } - - /** @brief this adds the parameter values and derivatives to the TMB model - * object */ - virtual bool add_to_fims_tmb() { - std::shared_ptr > d0 = - fims::Information::GetInstance(); - - std::shared_ptr > ls0 = - std::make_shared >(); - - // set relative info - ls0->id = this->id; - ls0->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d0->RegisterRandomEffect(ls0->median); - } else { - d0->RegisterParameter(ls0->median); - } - } - ls0->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d0->RegisterRandomEffect(ls0->slope); - } else { - d0->RegisterParameter(ls0->slope); - } +public: + Parameter median; /**< the index value at which the response reaches .5 */ + Parameter slope; /**< the width of the curve at the median */ + + LogisticSelectivityInterface() : SelectivityInterfaceBase() { } - // add to Information - d0->selectivity_models[ls0->id] = ls0; + virtual ~LogisticSelectivityInterface() { + } - std::shared_ptr > d1 = - fims::Information::GetInstance(); + /** @brief returns the id for the logistic selectivity interface */ + virtual uint32_t get_id() { + return this->id; + } - std::shared_ptr > ls1 = - std::make_shared >(); + /** @brief evaluate the logistic selectivity function + * @param x The independent variable in the logistic function (e.g., age or + * size in selectivity). + */ + virtual double evaluate(double x) { + fims::LogisticSelectivity LogisticSel; - // set relative info - ls1->id = this->id; - ls1->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d1->RegisterRandomEffect(ls1->median); - } else { - d1->RegisterParameter(ls1->median); - } - } - ls1->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d1->RegisterRandomEffect(ls1->slope); - } else { - d1->RegisterParameter(ls1->slope); - } + LogisticSel.median = this->median.value; + LogisticSel.slope = this->slope.value; + return LogisticSel.evaluate(x); } - // add to Information - d1->selectivity_models[ls1->id] = ls1; +#ifdef TMB_MODEL - std::shared_ptr > d2 = - fims::Information::GetInstance(); + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > ls2 = - std::make_shared >(); + std::shared_ptr > selectivity = + std::make_shared >(); - // set relative info - ls2->id = this->id; - ls2->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d2->RegisterRandomEffect(ls2->median); - } else { - d2->RegisterParameter(ls2->median); - } - } - ls2->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d2->RegisterRandomEffect(ls2->slope); - } else { - d2->RegisterParameter(ls2->slope); - } - } + // set relative info + selectivity->id = this->id; + selectivity->median = this->median.value; + if (this->median.estimated) { + if (this->median.is_random_effect) { + info->RegisterRandomEffect(selectivity->median); + } else { + info->RegisterParameter(selectivity->median); + } + } + selectivity->slope = this->slope.value; + if (this->slope.estimated) { + if (this->slope.is_random_effect) { + info->RegisterRandomEffect(selectivity->slope); + } else { + info->RegisterParameter(selectivity->slope); + } + } - // add to Information - d2->selectivity_models[ls2->id] = ls2; + // add to Information + info->selectivity_models[selectivity->id] = selectivity; + } - std::shared_ptr > d3 = - fims::Information::GetInstance(); + /** @brief this adds the parameter values and derivatives to the TMB model + * object */ + virtual bool add_to_fims_tmb() { - std::shared_ptr > ls3 = - std::make_shared >(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - // set relative info - ls3->id = this->id; - ls3->median = this->median.value; - if (this->median.estimated) { - if (this->median.is_random_effect) { - d3->RegisterRandomEffect(ls3->median); - } else { - d3->RegisterParameter(ls3->median); - } - } - ls3->slope = this->slope.value; - if (this->slope.estimated) { - if (this->slope.is_random_effect) { - d3->RegisterRandomEffect(ls3->slope); - } else { - d3->RegisterParameter(ls3->slope); - } + return true; } - // add to Information - d3->selectivity_models[ls3->id] = ls3; - - return true; - } +#endif }; /** @@ -202,221 +137,102 @@ class LogisticSelectivityInterface : public SelectivityInterfaceBase { * instantiate from R: logistic_selectivity <- new(fims$logistic_selectivity) */ class DoubleLogisticSelectivityInterface : public SelectivityInterfaceBase { - public: - Parameter median_asc; /**< the index value at which the response reaches .5 */ - Parameter slope_asc; /**< the width of the curve at the median */ - Parameter - median_desc; /**< the index value at which the response reaches .5 */ - Parameter slope_desc; /**< the width of the curve at the median */ - - DoubleLogisticSelectivityInterface() : SelectivityInterfaceBase() {} - - virtual ~DoubleLogisticSelectivityInterface() {} - - /** @brief returns the id for the double logistic selectivity interface */ - virtual uint32_t get_id() { return this->id; } - - /** @brief evaluate the double logistic selectivity function - * @param x The independent variable in the logistic function (e.g., age or - * size in selectivity). - */ - virtual double evaluate(double x) { - fims::DoubleLogisticSelectivity DoubleLogisticSel; - - DoubleLogisticSel.median_asc = this->median_asc.value; - DoubleLogisticSel.slope_asc = this->slope_asc.value; - DoubleLogisticSel.median_desc = this->median_desc.value; - DoubleLogisticSel.slope_desc = this->slope_desc.value; - return DoubleLogisticSel.evaluate(x); - } - - /** @brief this adds the parameter values and derivatives to the TMB model - * object */ - virtual bool add_to_fims_tmb() { - std::shared_ptr > d0 = - fims::Information::GetInstance(); - - std::shared_ptr > ls0 = - std::make_shared< - fims::DoubleLogisticSelectivity >(); - - // set relative info - ls0->id = this->id; - ls0->median_asc = this->median_asc.value; - if (this->median_asc.estimated) { - if (this->median_asc.is_random_effect) { - d0->RegisterRandomEffect(ls0->median_asc); - } else { - d0->RegisterParameter(ls0->median_asc); - } - } - ls0->slope_asc = this->slope_asc.value; - if (this->slope_asc.estimated) { - if (this->slope_asc.is_random_effect) { - d0->RegisterRandomEffect(ls0->slope_asc); - } else { - d0->RegisterParameter(ls0->slope_asc); - } - } - ls0->median_desc = this->median_desc.value; - if (this->median_desc.estimated) { - if (this->median_desc.is_random_effect) { - d0->RegisterRandomEffect(ls0->median_desc); - } else { - d0->RegisterParameter(ls0->median_desc); - } - } - ls0->slope_desc = this->slope_desc.value; - if (this->slope_desc.estimated) { - if (this->slope_desc.is_random_effect) { - d0->RegisterRandomEffect(ls0->slope_desc); - } else { - d0->RegisterParameter(ls0->slope_desc); - } - } - - // add to Information - d0->selectivity_models[ls0->id] = ls0; - - std::shared_ptr > d1 = - fims::Information::GetInstance(); - - std::shared_ptr > - ls1 = std::make_shared< - fims::DoubleLogisticSelectivity >(); - - // set relative info - ls1->id = this->id; - ls1->median_asc = this->median_asc.value; - if (this->median_asc.estimated) { - if (this->median_asc.is_random_effect) { - d1->RegisterRandomEffect(ls1->median_asc); - } else { - d1->RegisterParameter(ls1->median_asc); - } - } - ls1->slope_asc = this->slope_asc.value; - if (this->slope_asc.estimated) { - if (this->slope_asc.is_random_effect) { - d1->RegisterRandomEffect(ls1->slope_asc); - } else { - d1->RegisterParameter(ls1->slope_asc); - } - } - ls1->median_desc = this->median_desc.value; - if (this->median_desc.estimated) { - if (this->median_desc.is_random_effect) { - d1->RegisterRandomEffect(ls1->median_desc); - } else { - d1->RegisterParameter(ls1->median_desc); - } - } - ls1->slope_desc = this->slope_desc.value; - if (this->slope_desc.estimated) { - if (this->slope_desc.is_random_effect) { - d1->RegisterRandomEffect(ls1->slope_desc); - } else { - d1->RegisterParameter(ls1->slope_desc); - } - } - - // add to Information - d1->selectivity_models[ls1->id] = ls1; - - std::shared_ptr > d2 = - fims::Information::GetInstance(); - - std::shared_ptr > - ls2 = std::make_shared< - fims::DoubleLogisticSelectivity >(); - - // set relative info - ls2->id = this->id; - ls2->median_asc = this->median_asc.value; - if (this->median_asc.estimated) { - if (this->median_asc.is_random_effect) { - d2->RegisterRandomEffect(ls2->median_asc); - } else { - d2->RegisterParameter(ls2->median_asc); - } - } - ls2->slope_asc = this->slope_asc.value; - if (this->slope_asc.estimated) { - if (this->slope_asc.is_random_effect) { - d2->RegisterRandomEffect(ls2->slope_asc); - } else { - d2->RegisterParameter(ls2->slope_asc); - } - } - - ls2->median_desc = this->median_desc.value; - if (this->median_desc.estimated) { - if (this->median_desc.is_random_effect) { - d2->RegisterRandomEffect(ls2->median_desc); - } else { - d2->RegisterParameter(ls2->median_desc); - } - } - ls2->slope_desc = this->slope_desc.value; - if (this->slope_desc.estimated) { - if (this->slope_desc.is_random_effect) { - d2->RegisterRandomEffect(ls2->slope_desc); - } else { - d2->RegisterParameter(ls2->slope_desc); - } - } - - // add to Information - d2->selectivity_models[ls2->id] = ls2; - - std::shared_ptr > d3 = - fims::Information::GetInstance(); - - std::shared_ptr > - ls3 = std::make_shared< - fims::DoubleLogisticSelectivity >(); - - // set relative info - ls3->id = this->id; - ls3->median_asc = this->median_asc.value; - if (this->median_asc.estimated) { - if (this->median_asc.is_random_effect) { - d3->RegisterRandomEffect(ls3->median_asc); - } else { - d3->RegisterParameter(ls3->median_asc); - } - } - ls3->slope_asc = this->slope_asc.value; - if (this->slope_asc.estimated) { - if (this->slope_asc.is_random_effect) { - d3->RegisterRandomEffect(ls3->slope_asc); - } else { - d3->RegisterParameter(ls3->slope_asc); - } - } - - ls3->median_desc = this->median_desc.value; - if (this->median_desc.estimated) { - if (this->median_desc.is_random_effect) { - d3->RegisterRandomEffect(ls3->median_desc); - } else { - d3->RegisterParameter(ls3->median_desc); - } - } - ls3->slope_desc = this->slope_desc.value; - if (this->slope_desc.estimated) { - if (this->slope_desc.is_random_effect) { - d3->RegisterRandomEffect(ls3->slope_desc); - } else { - d3->RegisterParameter(ls3->slope_desc); - } - } - - // add to Information - d3->selectivity_models[ls3->id] = ls3; - - return true; - } +public: + Parameter median_asc; /**< the index value at which the response reaches .5 */ + Parameter slope_asc; /**< the width of the curve at the median */ + Parameter + median_desc; /**< the index value at which the response reaches .5 */ + Parameter slope_desc; /**< the width of the curve at the median */ + + DoubleLogisticSelectivityInterface() : SelectivityInterfaceBase() { + } + + virtual ~DoubleLogisticSelectivityInterface() { + } + + /** @brief returns the id for the double logistic selectivity interface */ + virtual uint32_t get_id() { + return this->id; + } + + /** @brief evaluate the double logistic selectivity function + * @param x The independent variable in the logistic function (e.g., age or + * size in selectivity). + */ + virtual double evaluate(double x) { + fims::DoubleLogisticSelectivity DoubleLogisticSel; + + DoubleLogisticSel.median_asc = this->median_asc.value; + DoubleLogisticSel.slope_asc = this->slope_asc.value; + DoubleLogisticSel.median_desc = this->median_desc.value; + DoubleLogisticSel.slope_desc = this->slope_desc.value; + return DoubleLogisticSel.evaluate(x); + } + +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); + + std::shared_ptr > selectivity = + std::make_shared< + fims::DoubleLogisticSelectivity >(); + + // set relative info + selectivity->id = this->id; + selectivity->median_asc = this->median_asc.value; + if (this->median_asc.estimated) { + if (this->median_asc.is_random_effect) { + info->RegisterRandomEffect(selectivity->median_asc); + } else { + info->RegisterParameter(selectivity->median_asc); + } + } + selectivity->slope_asc = this->slope_asc.value; + if (this->slope_asc.estimated) { + if (this->slope_asc.is_random_effect) { + info->RegisterRandomEffect(selectivity->slope_asc); + } else { + info->RegisterParameter(selectivity->slope_asc); + } + } + selectivity->median_desc = this->median_desc.value; + if (this->median_desc.estimated) { + if (this->median_desc.is_random_effect) { + info->RegisterRandomEffect(selectivity->median_desc); + } else { + info->RegisterParameter(selectivity->median_desc); + } + } + selectivity->slope_desc = this->slope_desc.value; + if (this->slope_desc.estimated) { + if (this->slope_desc.is_random_effect) { + info->RegisterRandomEffect(selectivity->slope_desc); + } else { + info->RegisterParameter(selectivity->slope_desc); + } + } + + // add to Information + info->selectivity_models[selectivity->id] = selectivity; + + } + + /** @brief this adds the parameter values and derivatives to the TMB model + * object */ + virtual bool add_to_fims_tmb() { + + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + + return true; + } + +#endif }; #endif \ No newline at end of file diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index e169f148..8baaec16 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -18,37 +18,38 @@ * */ class DistributionsInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t - id_g; /**< static id of the DistributionsInterfaceBase object */ - uint32_t id; /**< local id of the DistributionsInterfaceBase object */ - static std::map live_objects; /**< +public: + static uint32_t + id_g; /**< static id of the DistributionsInterfaceBase object */ + uint32_t id; /**< local id of the DistributionsInterfaceBase object */ + static std::map live_objects; /**< map relating the ID of the DistributionsInterfaceBase to the DistributionsInterfaceBase objects */ - DistributionsInterfaceBase() { - this->id = DistributionsInterfaceBase::id_g++; - DistributionsInterfaceBase::live_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } + DistributionsInterfaceBase() { + this->id = DistributionsInterfaceBase::id_g++; + DistributionsInterfaceBase::live_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } - virtual ~DistributionsInterfaceBase() {} + virtual ~DistributionsInterfaceBase() { + } - /** @brief get_id method for child distribution interface objects to inherit - * **/ - virtual uint32_t get_id() = 0; + /** @brief get_id method for child distribution interface objects to inherit + * **/ + virtual uint32_t get_id() = 0; - /** @brief evaluate method for child distribution interface objects to inherit - * **/ - virtual double evaluate(bool do_log) = 0; + /** @brief evaluate method for child distribution interface objects to inherit + * **/ + virtual double evaluate(bool do_log) = 0; }; uint32_t DistributionsInterfaceBase::id_g = - 1; /**< static id of the DistributionsInterfaceBase object */ + 1; /**< static id of the DistributionsInterfaceBase object */ std::map /**< local id of the DistributionsInterfaceBase object */ - DistributionsInterfaceBase::live_objects; /**< +DistributionsInterfaceBase +*> /**< local id of the DistributionsInterfaceBase object */ +DistributionsInterfaceBase::live_objects; /**< map relating the ID of the DistributionsInterfaceBase to the DistributionsInterfaceBase objects */ @@ -59,95 +60,71 @@ std::mapid; } - - virtual ~DnormDistributionsInterface() {} - - /** - * @brief Evaluate normal probability density function, default returns the - * log of the pdf - * - * @tparam T - * @return log pdf - */ - virtual double evaluate(bool do_log) { - fims::Dnorm dnorm; - dnorm.x = this->x.value; - dnorm.mean = this->mean.value; - dnorm.sd = this->sd.value; - return dnorm.evaluate(do_log); - } - - /** - * @brief adds the dnorm distribution and its parameters to the TMB model - */ - virtual bool add_to_fims_tmb() { - std::shared_ptr> d0 = - fims::Information::GetInstance(); - - std::shared_ptr> model0 = - std::make_shared>(); - - // interface to data/parameter value - model0->id = this->id; - model0->x = this->x.value; - // set relative info - model0->mean = this->mean.value; - model0->sd = this->sd.value; - - d0->distribution_models[model0->id] = model0; - - std::shared_ptr> d1 = - fims::Information::GetInstance(); - - std::shared_ptr> model1 = - std::make_shared>(); - - // interface to data/parameter first derivative - model1->id = this->id; - model1->x = this->x.value; - model1->mean = this->mean.value; - model1->sd = this->sd.value; - - d1->distribution_models[model1->id] = model1; - - std::shared_ptr> d2 = - fims::Information::GetInstance(); - - std::shared_ptr> model2 = - std::make_shared>(); - - // interface to data/parameter second derivative - model2->id = this->id; - model2->x = this->x.value; - model2->mean = this->mean.value; - model2->sd = this->sd.value; - - d2->distribution_models[model2->id] = model2; - - std::shared_ptr> d3 = - fims::Information::GetInstance(); - - std::shared_ptr> model3 = - std::make_shared>(); - - // interface to data/parameter third derivative - model3->id = this->id; - model3->x = this->x.value; - model3->mean = this->mean.value; - model3->sd = this->sd.value; - - d3->distribution_models[model3->id] = model3; - - return true; - } +public: + Parameter x; /**< observed data */ + Parameter mean; /**< mean of x for the normal distribution **/ + Parameter sd; /**< sd of x for the normal distribution **/ + + DnormDistributionsInterface() : DistributionsInterfaceBase() { + } + + virtual uint32_t get_id() { + return this->id; + } + + virtual ~DnormDistributionsInterface() { + } + + /** + * @brief Evaluate normal probability density function, default returns the + * log of the pdf + * + * @tparam T + * @return log pdf + */ + virtual double evaluate(bool do_log) { + fims::Dnorm dnorm; + dnorm.x = this->x.value; + dnorm.mean = this->mean.value; + dnorm.sd = this->sd.value; + return dnorm.evaluate(do_log); + } + +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr> info = + fims::Information::GetInstance(); + + std::shared_ptr> distributiion = + std::make_shared> (); + + // interface to data/parameter value + distributiion->id = this->id; + distributiion->x = this->x.value; + // set relative info + distributiion->mean = this->mean.value; + distributiion->sd = this->sd.value; + + info->distribution_models[distributiion->id] = distributiion; + + } + + /** + * @brief adds the dnorm distribution and its parameters to the TMB model + */ + virtual bool add_to_fims_tmb() { + + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + + return true; + } + +#endif }; /** @@ -157,103 +134,74 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { * */ class DlnormDistributionsInterface : public DistributionsInterfaceBase { - public: - Parameter x; /*!< observation */ - Parameter meanlog; /*!< mean of the distribution of log(x) */ - Parameter sdlog; /*!< standard deviation of the distribution of log(x) */ - bool do_bias_correction; /*!< true if the lognormal should be bias corrected, +public: + Parameter x; /*!< observation */ + Parameter meanlog; /*!< mean of the distribution of log(x) */ + Parameter sdlog; /*!< standard deviation of the distribution of log(x) */ + bool do_bias_correction; /*!< true if the lognormal should be bias corrected, default FALSE */ - DlnormDistributionsInterface() : DistributionsInterfaceBase() {} - - virtual ~DlnormDistributionsInterface() {} - - /** - * @brief get the id of the Dlnorm distributions interface class object - */ - virtual uint32_t get_id() { return this->id; } - - /** - * @brief Evaluate lognormal probability density function, default returns the - * log of the pdf - * - * @tparam T - * @return log pdf - */ - virtual double evaluate(bool do_log) { - fims::Dlnorm dlnorm; - dlnorm.x = this->x.value; - dlnorm.meanlog = this->meanlog.value; - dlnorm.sdlog = this->sdlog.value; - dlnorm.do_bias_correction = this->do_bias_correction; - return dlnorm.evaluate(do_log); - } - - /** - * @brief adds the dlnorm distribution and its parameters to the TMB model - */ - virtual bool add_to_fims_tmb() { - std::shared_ptr> d0 = - fims::Information::GetInstance(); - - std::shared_ptr> model0 = - std::make_shared>(); - - // set relative info - model0->id = this->id; - model0->x = this->x.value; - model0->meanlog = this->meanlog.value; - model0->sdlog = this->sdlog.value; - - d0->distribution_models[model0->id] = model0; - - // base model - std::shared_ptr> d1 = - fims::Information::GetInstance(); - - std::shared_ptr> model1 = - std::make_shared>(); - - // set relative info - model1->id = this->id; - model1->x = this->x.value; - model1->meanlog = this->meanlog.value; - model1->sdlog = this->sdlog.value; - - d1->distribution_models[model1->id] = model1; - - // base model - std::shared_ptr> d2 = - fims::Information::GetInstance(); - - std::shared_ptr> model2 = - std::make_shared>(); - - // set relative info - model2->id = this->id; - model2->x = this->x.value; - model2->meanlog = this->meanlog.value; - model2->sdlog = this->sdlog.value; - - d2->distribution_models[model2->id] = model2; - - // base model - std::shared_ptr> d3 = - fims::Information::GetInstance(); - - std::shared_ptr> model3 = - std::make_shared>(); - - // set relative info - model3->id = this->id; - model3->x = this->x.value; - model3->meanlog = this->meanlog.value; - model3->sdlog = this->sdlog.value; - - d3->distribution_models[model3->id] = model3; - - return true; - } + DlnormDistributionsInterface() : DistributionsInterfaceBase() { + } + + virtual ~DlnormDistributionsInterface() { + } + + /** + * @brief get the id of the Dlnorm distributions interface class object + */ + virtual uint32_t get_id() { + return this->id; + } + + /** + * @brief Evaluate lognormal probability density function, default returns the + * log of the pdf + * + * @tparam T + * @return log pdf + */ + virtual double evaluate(bool do_log) { + fims::Dlnorm dlnorm; + dlnorm.x = this->x.value; + dlnorm.meanlog = this->meanlog.value; + dlnorm.sdlog = this->sdlog.value; + dlnorm.do_bias_correction = this->do_bias_correction; + return dlnorm.evaluate(do_log); + } +#ifdef TMB_MODEL + + template + bool add_to_fims_tmb_internal() { + std::shared_ptr > info = + fims::Information::GetInstance(); + + std::shared_ptr < fims::Dlnorm > distribution = + std::make_shared > (); + + // set relative info + distribution->id = this->id; + distribution->x = this->x.value; + distribution->meanlog = this->meanlog.value; + distribution->sdlog = this->sdlog.value; + + info->distribution_models[distribution->id] = distribution; + } + + /** + * @brief adds the dlnorm distribution and its parameters to the TMB model + */ + virtual bool add_to_fims_tmb() { + + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + + return true; + } + +#endif }; /** @@ -263,116 +211,78 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { * */ // template + class DmultinomDistributionsInterface : public DistributionsInterfaceBase { - public: - Rcpp::NumericVector x; /*!< Vector of length K of integers */ - Rcpp::NumericVector p; /*!< Vector of length K, specifying the probability +public: + Rcpp::NumericVector x; /*!< Vector of length K of integers */ + Rcpp::NumericVector p; /*!< Vector of length K, specifying the probability for the K classes (note, unlike in R these must sum to 1). */ - DmultinomDistributionsInterface() : DistributionsInterfaceBase() {} - - virtual ~DmultinomDistributionsInterface() {} - - virtual uint32_t get_id() { return this->id; } - - /** - * @brief Evaluate multinom probability density function, default returns the - * log of the pdf - * - * @tparam T - * @return log pdf - */ - virtual double evaluate(bool do_log) { - fims::Dmultinom dmultinom; - // Decale TMBVector in this scope - typedef - typename fims::ModelTraits::EigenVector TMBVector; - dmultinom.x = TMBVector(x.size()); // Vector from TMB - dmultinom.p = TMBVector(p.size()); // Vector from TMB - for (int i = 0; i < x.size(); i++) { - dmultinom.x[i] = x[i]; - dmultinom.p[i] = p[i]; + DmultinomDistributionsInterface() : DistributionsInterfaceBase() { } - return dmultinom.evaluate(do_log); - } - - virtual bool add_to_fims_tmb() { - typedef typename fims::ModelTraits::EigenVector Vector0; - std::shared_ptr> d0 = - fims::Information::GetInstance(); - - std::shared_ptr> model0 = - std::make_shared>(); - model0->id = this->id; - model0->x = Vector0(x.size()); - model0->p = Vector0(p.size()); - - for (int i = 0; i < x.size(); i++) { - model0->x[i] = x[i]; - model0->p[i] = p[i]; + virtual ~DmultinomDistributionsInterface() { } - d0->distribution_models[model0->id] = model0; - - typedef - typename fims::ModelTraits::EigenVector Vector1; - std::shared_ptr> d1 = - fims::Information::GetInstance(); - - std::shared_ptr> model1 = - std::make_shared>(); - - model1->id = this->id; - model1->x = Vector1(x.size()); - model1->p = Vector1(p.size()); + virtual uint32_t get_id() { + return this->id; + } - for (int i = 0; i < x.size(); i++) { - model1->x[i] = x[i]; - model1->p[i] = p[i]; + /** + * @brief Evaluate multinom probability density function, default returns the + * log of the pdf + * + * @tparam T + * @return log pdf + */ + virtual double evaluate(bool do_log) { + fims::Dmultinom dmultinom; + // Decale TMBVector in this scope + typedef + typename fims::ModelTraits::EigenVector TMBVector; + dmultinom.x = TMBVector(x.size()); // Vector from TMB + dmultinom.p = TMBVector(p.size()); // Vector from TMB + for (int i = 0; i < x.size(); i++) { + dmultinom.x[i] = x[i]; + dmultinom.p[i] = p[i]; + } + return dmultinom.evaluate(do_log); } - d1->distribution_models[model1->id] = model1; +#ifdef TMB_MODEL - typedef - typename fims::ModelTraits::EigenVector Vector2; - std::shared_ptr> d2 = - fims::Information::GetInstance(); + template + bool add_to_fims_tmb_internal() { + typedef typename fims::ModelTraits::EigenVector Vector0; + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr> model2 = - std::make_shared>(); + std::shared_ptr> distribution = + std::make_shared > (); - model2->id = this->id; - model2->x = Vector2(x.size()); - model2->p = Vector2(p.size()); + distribution->id = this->id; + distribution->x = Vector0(x.size()); + distribution->p = Vector0(p.size()); - for (int i = 0; i < x.size(); i++) { - model2->x[i] = x[i]; - model2->p[i] = p[i]; - } + for (int i = 0; i < x.size(); i++) { + distribution->x[i] = x[i]; + distribution->p[i] = p[i]; + } - d2->distribution_models[model2->id] = model2; + info->distribution_models[distribution->id] = distribution; - typedef - typename fims::ModelTraits::EigenVector Vector3; - std::shared_ptr> d3 = - fims::Information::GetInstance(); + } - std::shared_ptr> model3 = - std::make_shared>(); + virtual bool add_to_fims_tmb() { - model3->id = this->id; - model3->x = Vector3(x.size()); - model3->p = Vector3(p.size()); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); + this->add_to_fims_tmb_internal(); - for (int i = 0; i < x.size(); i++) { - model3->x[i] = x[i]; - model3->p[i] = p[i]; + return true; } - d3->distribution_models[model3->id] = model3; - - return true; - } +#endif }; #endif From e74f9cd903b4da34b31d37e5dbda36130ebcac86 Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Tue, 29 Aug 2023 17:20:07 -0400 Subject: [PATCH 02/11] added return --- .../interface/rcpp/rcpp_objects/rcpp_data.hpp | 150 +++++++++------- .../rcpp/rcpp_objects/rcpp_fleet.hpp | 155 ++++++++-------- .../rcpp/rcpp_objects/rcpp_growth.hpp | 128 ++++++------- .../rcpp/rcpp_objects/rcpp_maturity.hpp | 82 +++++---- .../rcpp/rcpp_objects/rcpp_population.hpp | 142 ++++++++------- .../rcpp/rcpp_objects/rcpp_recruitment.hpp | 168 +++++++++--------- .../rcpp/rcpp_objects/rcpp_selectivity.hpp | 3 + .../rcpp_objects/rcpp_tmb_distribution.hpp | 5 + 8 files changed, 447 insertions(+), 386 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 6168697b..0d5cb9b4 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -18,34 +18,39 @@ * */ class DataInterface : public FIMSRcppInterfaceBase { - public: - Rcpp::NumericVector observed_data; /*!< The data */ - static uint32_t id_g; /**< static id of the DataInterface object */ - uint32_t id; /**< local id of the DataInterface object */ - static std::map - live_objects; /**< map associating the ids of DataInterface to +public: + Rcpp::NumericVector observed_data; /*!< The data */ + static uint32_t id_g; /**< static id of the DataInterface object */ + uint32_t id; /**< local id of the DataInterface object */ + static std::map + live_objects; /**< map associating the ids of DataInterface to the objects */ - /** @brief constructor - */ - DataInterface() { - this->id = DataInterface::id_g++; - DataInterface::live_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } - - /** @brief destructor - */ - virtual ~DataInterface() {} - - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() { return this->id; } - - /**@brief add_to_fims_tmb dummy method - * - */ - virtual bool add_to_fims_tmb() { return true; }; + /** @brief constructor + */ + DataInterface() { + this->id = DataInterface::id_g++; + DataInterface::live_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } + + /** @brief destructor + */ + virtual ~DataInterface() { + } + + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() { + return this->id; + } + + /**@brief add_to_fims_tmb dummy method + * + */ + virtual bool add_to_fims_tmb() { + return true; + }; }; uint32_t DataInterface::id_g = 1; std::map DataInterface::live_objects; @@ -56,31 +61,34 @@ std::map DataInterface::live_objects; * acomp <- new(fims$AgeComp) */ class AgeCompDataInterface : public DataInterface { - public: - int amax; /*!< first dimension of the data */ - int ymax; /*!< second dimension of the data */ - Rcpp::NumericVector age_comp_data; /*!amax = amax; - this->ymax = ymax; - } + /** + * @brief constructor + */ + AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterface() { + this->amax = amax; + this->ymax = ymax; + } - /** - * @brief destructor - */ - virtual ~AgeCompDataInterface() {} + /** + * @brief destructor + */ + virtual ~AgeCompDataInterface() { + } - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() { return this->id; } + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() { + return this->id; + } #ifdef TMB_MODEL - + template bool add_to_fims_tmb_internal() { std::shared_ptr> age_comp_data = @@ -99,6 +107,8 @@ class AgeCompDataInterface : public DataInterface { fims::Information::GetInstance(); info->data_objects[this->id] = age_comp_data; + + return true; } /** @@ -112,8 +122,8 @@ class AgeCompDataInterface : public DataInterface { return true; } - - #endif + +#endif }; /** @@ -122,26 +132,32 @@ class AgeCompDataInterface : public DataInterface { * fleet <- new(fims$Index) */ class IndexDataInterface : public DataInterface { - public: - int ymax; /*!< second dimension of the data */ - Rcpp::NumericVector index_data; /*!ymax = ymax; } - - /** - * @brief destructor - */ - virtual ~IndexDataInterface() {} - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() { return this->id; } - - +public: + int ymax; /*!< second dimension of the data */ + Rcpp::NumericVector index_data; /*!ymax = ymax; + } + + /** + * @brief destructor + */ + virtual ~IndexDataInterface() { + } + + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() { + return this->id; + } + + #ifdef TMB_MODEL - + template bool add_to_fims_tmb_internal() { std::shared_ptr> data = @@ -157,7 +173,7 @@ class IndexDataInterface : public DataInterface { fims::Information::GetInstance(); info->data_objects[this->id] = data; - + return true; } /** diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index a96e7d06..d6c6be74 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -19,81 +19,82 @@ * */ class FleetInterface : public FIMSRcppInterfaceBase { - int agecomp_likelihood_id = -999; /*!< id of agecomp likelihood component*/ - int index_likelihood_id = -999; /*!< id of index likelihood component*/ - int observed_agecomp_data_id = -999; /*!< id of observed agecomp data object*/ - int observed_index_data_id = -999; /*!< id of observed index data object*/ - int selectivity_id = -999; /*!< id of selectivity component*/ - - public: - bool is_survey = false; /*!< whether this is a survey fleet */ - int nages; /*!< number of ages in the fleet data*/ - int nyears; /*!< number of years in the fleet data */ - double log_q; /*!< log of catchability for the fleet*/ - Rcpp::NumericVector - log_Fmort; /*!< log of fishing mortality rate for the fleet*/ - bool estimate_F = false; /*!< whether the parameter F should be estimated*/ - bool estimate_q = false; /*!< whether the parameter q should be estimated*/ - bool random_q = false; /*!< whether q should be a random effect*/ - bool random_F = false; /*!< whether F should be a random effect*/ - Parameter log_obs_error; /*!< the log of the observation error */ - - public: - static uint32_t id_g; /**< static id of the FleetInterface object */ - uint32_t id; /**< local id of the FleetInterface object */ - - FleetInterface() { - this->id = FleetInterface::id_g++; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } - - virtual ~FleetInterface() {} - - /** - * @brief Set the unique id for the Age Comp Likelihood object - * - * @param agecomp_likelihood_id Unique id for the Age Comp Likelihood object - */ - void SetAgeCompLikelihood(int agecomp_likelihood_id) { - this->agecomp_likelihood_id = agecomp_likelihood_id; - } - - /** - * @brief Set the unique id for the Index Likelihood object - * - * @param index_likelihood_id Unique id for the Index Likelihood object - */ - void SetIndexLikelihood(int index_likelihood_id) { - this->index_likelihood_id = index_likelihood_id; - } - - /** - * @brief Set the unique id for the Observed Age Comp Data object - * - * @param observed_agecomp_data_id Unique id for the Observed Age Comp Data - * object - */ - void SetObservedAgeCompData(int observed_agecomp_data_id) { - this->observed_agecomp_data_id = observed_agecomp_data_id; - } - - /** - * @brief Set the unique id for the Observed Index Data object - * - * @param observed_index_data_id Unique id for the Observed Index Data object - */ - void SetObservedIndexData(int observed_index_data_id) { - this->observed_index_data_id = observed_index_data_id; - } - - /** - * @brief Set the unique id for the Selectivity object - * - * @param selectivity_id Unique id for the Selectivity object - */ - void SetSelectivity(int selectivity_id) { - this->selectivity_id = selectivity_id; - } + int agecomp_likelihood_id = -999; /*!< id of agecomp likelihood component*/ + int index_likelihood_id = -999; /*!< id of index likelihood component*/ + int observed_agecomp_data_id = -999; /*!< id of observed agecomp data object*/ + int observed_index_data_id = -999; /*!< id of observed index data object*/ + int selectivity_id = -999; /*!< id of selectivity component*/ + +public: + bool is_survey = false; /*!< whether this is a survey fleet */ + int nages; /*!< number of ages in the fleet data*/ + int nyears; /*!< number of years in the fleet data */ + double log_q; /*!< log of catchability for the fleet*/ + Rcpp::NumericVector + log_Fmort; /*!< log of fishing mortality rate for the fleet*/ + bool estimate_F = false; /*!< whether the parameter F should be estimated*/ + bool estimate_q = false; /*!< whether the parameter q should be estimated*/ + bool random_q = false; /*!< whether q should be a random effect*/ + bool random_F = false; /*!< whether F should be a random effect*/ + Parameter log_obs_error; /*!< the log of the observation error */ + +public: + static uint32_t id_g; /**< static id of the FleetInterface object */ + uint32_t id; /**< local id of the FleetInterface object */ + + FleetInterface() { + this->id = FleetInterface::id_g++; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } + + virtual ~FleetInterface() { + } + + /** + * @brief Set the unique id for the Age Comp Likelihood object + * + * @param agecomp_likelihood_id Unique id for the Age Comp Likelihood object + */ + void SetAgeCompLikelihood(int agecomp_likelihood_id) { + this->agecomp_likelihood_id = agecomp_likelihood_id; + } + + /** + * @brief Set the unique id for the Index Likelihood object + * + * @param index_likelihood_id Unique id for the Index Likelihood object + */ + void SetIndexLikelihood(int index_likelihood_id) { + this->index_likelihood_id = index_likelihood_id; + } + + /** + * @brief Set the unique id for the Observed Age Comp Data object + * + * @param observed_agecomp_data_id Unique id for the Observed Age Comp Data + * object + */ + void SetObservedAgeCompData(int observed_agecomp_data_id) { + this->observed_agecomp_data_id = observed_agecomp_data_id; + } + + /** + * @brief Set the unique id for the Observed Index Data object + * + * @param observed_index_data_id Unique id for the Observed Index Data object + */ + void SetObservedIndexData(int observed_index_data_id) { + this->observed_index_data_id = observed_index_data_id; + } + + /** + * @brief Set the unique id for the Selectivity object + * + * @param selectivity_id Unique id for the Selectivity object + */ + void SetSelectivity(int selectivity_id) { + this->selectivity_id = selectivity_id; + } #ifdef TMB_MODEL @@ -144,6 +145,8 @@ class FleetInterface : public FIMSRcppInterfaceBase { } // add to Information info->fleets[f->id] = f; + + return true; } /** @brief this adds the values to the TMB model object */ @@ -155,7 +158,7 @@ class FleetInterface : public FIMSRcppInterfaceBase { return true; } - + #endif }; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp index 3369e4fd..4999ddc1 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp @@ -14,6 +14,7 @@ /**************************************************************** * Growth Rcpp interface * ***************************************************************/ + /** * @brief Rcpp interface that serves as the parent class for * Rcpp growth interfaces. This type should be inherited and not @@ -21,26 +22,27 @@ * */ class GrowthInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t id_g; /**< static id of the GrowthInterfaceBase object */ - uint32_t id; /**< local id of the GrowthInterfaceBase object */ - static std::map live_objects; /**< +public: + static uint32_t id_g; /**< static id of the GrowthInterfaceBase object */ + uint32_t id; /**< local id of the GrowthInterfaceBase object */ + static std::map live_objects; /**< map relating the ID of the GrowthInterfaceBase to the GrowthInterfaceBase objects */ - GrowthInterfaceBase() { - this->id = GrowthInterfaceBase::id_g++; - GrowthInterfaceBase::live_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } + GrowthInterfaceBase() { + this->id = GrowthInterfaceBase::id_g++; + GrowthInterfaceBase::live_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } - virtual ~GrowthInterfaceBase() {} + virtual ~GrowthInterfaceBase() { + } - /** @brief get_id method for child growth interface objects to inherit **/ - virtual uint32_t get_id() = 0; + /** @brief get_id method for child growth interface objects to inherit **/ + virtual uint32_t get_id() = 0; - /** @brief evaluate method for child growth interface objects to inherit **/ - virtual double evaluate(double age) = 0; + /** @brief evaluate method for child growth interface objects to inherit **/ + virtual double evaluate(double age) = 0; }; uint32_t GrowthInterfaceBase::id_g = 1; @@ -53,57 +55,61 @@ std::map GrowthInterfaceBase::live_objects; * */ class EWAAGrowthInterface : public GrowthInterfaceBase { - public: - std::vector weights; /**< weights for each age class */ - std::vector ages; /**< ages for each age class */ - std::map ewaa; /**< map of ewaa values */ +public: + std::vector weights; /**< weights for each age class */ + std::vector ages; /**< ages for each age class */ + std::map ewaa; /**< map of ewaa values */ - bool initialized = false; /**< boolean tracking if weights and ages + bool initialized = false; /**< boolean tracking if weights and ages vectors have been set */ - EWAAGrowthInterface() : GrowthInterfaceBase() {} - - virtual ~EWAAGrowthInterface() {} - - /** @brief get the id of the GrowthInterfaceBase object */ - virtual uint32_t get_id() { return this->id; } - - /** - * @brief Create a map of input numeric vectors - * @param weights T vector of weights - * @param ages T vector of ages - * @return std::map - * - * */ - inline std::map make_map(std::vector ages, - std::vector weights) { - std::map mymap; - for (uint32_t i = 0; i < ages.size(); i++) { - mymap.insert(std::pair(ages[i], weights[i])); + EWAAGrowthInterface() : GrowthInterfaceBase() { + } + + virtual ~EWAAGrowthInterface() { + } + + /** @brief get the id of the GrowthInterfaceBase object */ + virtual uint32_t get_id() { + return this->id; + } + + /** + * @brief Create a map of input numeric vectors + * @param weights T vector of weights + * @param ages T vector of ages + * @return std::map + * + * */ + inline std::map make_map(std::vector ages, + std::vector weights) { + std::map mymap; + for (uint32_t i = 0; i < ages.size(); i++) { + mymap.insert(std::pair(ages[i], weights[i])); + } + return mymap; } - return mymap; - } - - /** @brief Rcpp interface to the EWAAgrowth evaluate method - * you can call from R using - * ewaagrowth.evaluate(age) - * */ - virtual double evaluate(double age) { - fims::EWAAgrowth EWAAGrowth; - - if (initialized == false) { - this->ewaa = make_map(this->ages, this->weights); - // Check that ages and weights vector are the same length - if (this->ages.size() != this->weights.size()) { - Rcpp::stop("ages and weights must be the same length"); - } - initialized = true; - } else { - Rcpp::stop("this empirical weight at age object is already initialized"); + + /** @brief Rcpp interface to the EWAAgrowth evaluate method + * you can call from R using + * ewaagrowth.evaluate(age) + * */ + virtual double evaluate(double age) { + fims::EWAAgrowth EWAAGrowth; + + if (initialized == false) { + this->ewaa = make_map(this->ages, this->weights); + // Check that ages and weights vector are the same length + if (this->ages.size() != this->weights.size()) { + Rcpp::stop("ages and weights must be the same length"); + } + initialized = true; + } else { + Rcpp::stop("this empirical weight at age object is already initialized"); + } + EWAAGrowth.ewaa = this->ewaa; + return EWAAGrowth.evaluate(age); } - EWAAGrowth.ewaa = this->ewaa; - return EWAAGrowth.evaluate(age); - } #ifdef TMB_MODEL template @@ -119,6 +125,8 @@ class EWAAGrowthInterface : public GrowthInterfaceBase { data->ewaa = make_map(this->ages, this->weights); //this->ewaa; // add to Information info->growth_models[data->id] = data; + + return true; } /** @brief this adds the values to the TMB model object */ diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp index aabec53b..cc72413e 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp @@ -16,68 +16,74 @@ /**************************************************************** * maturity Rcpp interface * ***************************************************************/ + /** * @brief MaturityInterfaceBase class should be inherited to * define different Rcpp interfaces for each possible maturity function * */ class MaturityInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t id_g; /**< static id of the recruitment interface base*/ - uint32_t id; /**< id of the recruitment interface base */ - static std::map - maturity_objects; /**< map associating the ids of +public: + static uint32_t id_g; /**< static id of the recruitment interface base*/ + uint32_t id; /**< id of the recruitment interface base */ + static std::map + maturity_objects; /**< map associating the ids of MaturityInterfaceBase to the objects */ - MaturityInterfaceBase() { - this->id = MaturityInterfaceBase::id_g++; - MaturityInterfaceBase::maturity_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } + MaturityInterfaceBase() { + this->id = MaturityInterfaceBase::id_g++; + MaturityInterfaceBase::maturity_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } - virtual ~MaturityInterfaceBase() {} + virtual ~MaturityInterfaceBase() { + } - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() = 0; + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() = 0; - /** - * @brief evaluate the function - * - */ - virtual double evaluate(double x) = 0; + /** + * @brief evaluate the function + * + */ + virtual double evaluate(double x) = 0; }; uint32_t MaturityInterfaceBase::id_g = 1; std::map - MaturityInterfaceBase::maturity_objects; +MaturityInterfaceBase::maturity_objects; /** * @brief Rcpp interface for logistic maturity as an S4 object. To * instantiate from R: logistic_maturity <- new(fims$logistic_maturity) */ class LogisticMaturityInterface : public MaturityInterfaceBase { - public: - Parameter median; /**< the index value at which the response reaches .5 */ - Parameter slope; /**< the width of the curve at the median */ +public: + Parameter median; /**< the index value at which the response reaches .5 */ + Parameter slope; /**< the width of the curve at the median */ - LogisticMaturityInterface() : MaturityInterfaceBase() {} + LogisticMaturityInterface() : MaturityInterfaceBase() { + } - virtual ~LogisticMaturityInterface() {} + virtual ~LogisticMaturityInterface() { + } - /** @brief returns the id for the logistic maturity interface */ - virtual uint32_t get_id() { return this->id; } + /** @brief returns the id for the logistic maturity interface */ + virtual uint32_t get_id() { + return this->id; + } - /** @brief evaluate the logistic maturity function - * @param x The independent variable in the logistic function (e.g., age or - * size in maturity). - */ - virtual double evaluate(double x) { - fims::LogisticMaturity LogisticMat; + /** @brief evaluate the logistic maturity function + * @param x The independent variable in the logistic function (e.g., age or + * size in maturity). + */ + virtual double evaluate(double x) { + fims::LogisticMaturity LogisticMat; - LogisticMat.median = this->median.value; - LogisticMat.slope = this->slope.value; - return LogisticMat.evaluate(x); - } + LogisticMat.median = this->median.value; + LogisticMat.slope = this->slope.value; + return LogisticMat.evaluate(x); + } #ifdef TMB_MODEL @@ -110,6 +116,8 @@ class LogisticMaturityInterface : public MaturityInterfaceBase { // add to Information info->maturity_models[maturity->id] = maturity; + + return true; } /** @brief this adds the parameter values and derivatives to the TMB model diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index c0109bc5..5c4157d8 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -14,33 +14,35 @@ /**************************************************************** * Population Rcpp interface * ***************************************************************/ + /** * @brief PopulationInterfaceBase class should be inherited to * define different Rcpp interfaces for each possible Population function * */ class PopulationInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t id_g; /**< static id of the population interface base*/ - uint32_t id; /**< id of the population interface base */ - static std::map - live_objects; /**< map associating the ids of PopulationInterfaceBase to +public: + static uint32_t id_g; /**< static id of the population interface base*/ + uint32_t id; /**< id of the population interface base */ + static std::map + live_objects; /**< map associating the ids of PopulationInterfaceBase to the objects */ - PopulationInterfaceBase() { - this->id = PopulationInterfaceBase::id_g++; - PopulationInterfaceBase::live_objects[this->id] = this; - PopulationInterfaceBase::fims_interface_objects.push_back(this); - } + PopulationInterfaceBase() { + this->id = PopulationInterfaceBase::id_g++; + PopulationInterfaceBase::live_objects[this->id] = this; + PopulationInterfaceBase::fims_interface_objects.push_back(this); + } - virtual ~PopulationInterfaceBase() {} + virtual ~PopulationInterfaceBase() { + } - /** @brief get_id method for child classes to inherit */ - virtual uint32_t get_id() = 0; + /** @brief get_id method for child classes to inherit */ + virtual uint32_t get_id() = 0; }; uint32_t PopulationInterfaceBase::id_g = 1; std::map - PopulationInterfaceBase::live_objects; +PopulationInterfaceBase::live_objects; /** * @brief Rcpp interface for a new Population. To instantiate @@ -48,56 +50,64 @@ std::map * population <- new(fims$population) */ class PopulationInterface : public PopulationInterfaceBase { - public: - uint32_t nages; /**< number of ages */ - uint32_t nfleets; /**< number of fleets */ - uint32_t nseasons; /**< number of seasons */ - uint32_t nyears; /**< number of years */ - uint32_t maturity_id; /**< id of the maturity function*/ - uint32_t growth_id; /**< id of the growth function*/ - uint32_t recruitment_id; /**< id of the recruitment function*/ - Rcpp::NumericVector log_M; /**< log of the natural mortality of the stock*/ - Rcpp::NumericVector log_init_naa; /**id; } - - /** - * @brief Set the unique id for the Maturity object - * - * @param maturity_id Unique id for the Maturity object - */ - void SetMaturity(uint32_t maturity_id) { this->maturity_id = maturity_id; } - - /** - * @brief Set the unique id for the growth object - * - * @param growth_id Unique id for the growth object - */ - void SetGrowth(uint32_t growth_id) { this->growth_id = growth_id; } - - /** - * @brief Set the unique id for the Maturity object - * - * @param recruitment_id Unique id for the Maturity object - */ - void SetRecruitment(uint32_t recruitment_id) { - this->recruitment_id = recruitment_id; - } - - /** @brief evaluate the population function */ - virtual void evaluate() { - fims::Population population; - return population.Evaluate(); - } - +public: + uint32_t nages; /**< number of ages */ + uint32_t nfleets; /**< number of fleets */ + uint32_t nseasons; /**< number of seasons */ + uint32_t nyears; /**< number of years */ + uint32_t maturity_id; /**< id of the maturity function*/ + uint32_t growth_id; /**< id of the growth function*/ + uint32_t recruitment_id; /**< id of the recruitment function*/ + Rcpp::NumericVector log_M; /**< log of the natural mortality of the stock*/ + Rcpp::NumericVector log_init_naa; /**id; + } + + /** + * @brief Set the unique id for the Maturity object + * + * @param maturity_id Unique id for the Maturity object + */ + void SetMaturity(uint32_t maturity_id) { + this->maturity_id = maturity_id; + } + + /** + * @brief Set the unique id for the growth object + * + * @param growth_id Unique id for the growth object + */ + void SetGrowth(uint32_t growth_id) { + this->growth_id = growth_id; + } + + /** + * @brief Set the unique id for the Maturity object + * + * @param recruitment_id Unique id for the Maturity object + */ + void SetRecruitment(uint32_t recruitment_id) { + this->recruitment_id = recruitment_id; + } + + /** @brief evaluate the population function */ + virtual void evaluate() { + fims::Population population; + return population.Evaluate(); + } + #ifdef TMB_MODEL template @@ -145,6 +155,8 @@ class PopulationInterface : public PopulationInterfaceBase { // add to Information info->populations[population->id] = population; + + return true; } /** @brief this adds the parameter values and derivatives to the TMB model @@ -158,7 +170,7 @@ class PopulationInterface : public PopulationInterfaceBase { return true; } - + #endif }; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp index 0df6501e..efb2795b 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp @@ -21,46 +21,47 @@ * define different Rcpp interfaces for each possible Recruitment function * */ class RecruitmentInterfaceBase : public FIMSRcppInterfaceBase { - public: - static uint32_t id_g; /**< static id of the recruitment interface base*/ - uint32_t id; /**< id of the recruitment interface base */ - static std::map live_objects; - /**< map associating the ids of RecruitmentInterfaceBase to the objects */ - - // static std::vector recruit_deviations; /**< vector of recruitment - // deviations*/ - /// static bool constrain_deviations; /**< whether or not the rec devs are - /// constrained*/ - // static std::vector rec_bias_adj; /**< a vector of bias adjustment - // values*/ - - RecruitmentInterfaceBase() { - this->id = RecruitmentInterfaceBase::id_g++; - RecruitmentInterfaceBase::live_objects[this->id] = this; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); - } - - virtual ~RecruitmentInterfaceBase() {} - - /** @brief get the ID of the interface base object - **/ - virtual uint32_t get_id() = 0; - - /** @brief evaluate method for child recruitment interface objects to inherit - * **/ - virtual double evaluate(double spawners, double ssbzero) = 0; - - /** - * @brief evaluate recruitment nll - * - * @return double - */ - virtual double evaluate_nll() = 0; +public: + static uint32_t id_g; /**< static id of the recruitment interface base*/ + uint32_t id; /**< id of the recruitment interface base */ + static std::map live_objects; + /**< map associating the ids of RecruitmentInterfaceBase to the objects */ + + // static std::vector recruit_deviations; /**< vector of recruitment + // deviations*/ + /// static bool constrain_deviations; /**< whether or not the rec devs are + /// constrained*/ + // static std::vector rec_bias_adj; /**< a vector of bias adjustment + // values*/ + + RecruitmentInterfaceBase() { + this->id = RecruitmentInterfaceBase::id_g++; + RecruitmentInterfaceBase::live_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } + + virtual ~RecruitmentInterfaceBase() { + } + + /** @brief get the ID of the interface base object + **/ + virtual uint32_t get_id() = 0; + + /** @brief evaluate method for child recruitment interface objects to inherit + * **/ + virtual double evaluate(double spawners, double ssbzero) = 0; + + /** + * @brief evaluate recruitment nll + * + * @return double + */ + virtual double evaluate_nll() = 0; }; uint32_t RecruitmentInterfaceBase::id_g = 1; std::map - RecruitmentInterfaceBase::live_objects; +RecruitmentInterfaceBase::live_objects; /** * @brief Rcpp interface for Beverton-Holt as an S4 object. To instantiate @@ -68,58 +69,62 @@ std::map * beverton_holt <- new(fims$beverton_holt) */ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase { - public: - Parameter logit_steep; /**< steepness or the productivity of the stock*/ - Parameter log_rzero; /**< recruitment at unfished biomass */ - Parameter log_sigma_recruit; /**< the log of the stock recruit deviations */ - Rcpp::NumericVector recruit_bias_adjustment; /**id; } - - virtual double evaluate(double spawners, double ssbzero) { - fims::SRBevertonHolt BevHolt; - - BevHolt.logit_steep = this->logit_steep.value; - if (this->logit_steep.value == 1.0) { - warning( - "Steepness is subject to a logit transformation, so its value is " - "0.7848469. Fixing it at 1.0 is not currently possible."); +public: + Parameter logit_steep; /**< steepness or the productivity of the stock*/ + Parameter log_rzero; /**< recruitment at unfished biomass */ + Parameter log_sigma_recruit; /**< the log of the stock recruit deviations */ + Rcpp::NumericVector recruit_bias_adjustment; /**log_rzero.value; + virtual ~BevertonHoltRecruitmentInterface() { + } - return BevHolt.evaluate(spawners, ssbzero); - } + virtual uint32_t get_id() { + return this->id; + } - virtual double evaluate_nll() { - fims::SRBevertonHolt NLL; + virtual double evaluate(double spawners, double ssbzero) { + fims::SRBevertonHolt BevHolt; - NLL.log_sigma_recruit = this->log_sigma_recruit.value; - NLL.recruit_deviations.resize(deviations.size()); // Vector from TMB - NLL.recruit_bias_adjustment.resize( - recruit_bias_adjustment.size()); // Vector from TMB - for (int i = 0; i < deviations.size(); i++) { - NLL.recruit_deviations[i] = deviations[i]; - NLL.recruit_bias_adjustment[i] = recruit_bias_adjustment[i]; + BevHolt.logit_steep = this->logit_steep.value; + if (this->logit_steep.value == 1.0) { + warning( + "Steepness is subject to a logit transformation, so its value is " + "0.7848469. Fixing it at 1.0 is not currently possible."); + } + + BevHolt.log_rzero = this->log_rzero.value; + + return BevHolt.evaluate(spawners, ssbzero); } - FIMS_LOG << "Rec devs being passed to C++ are " << deviations << std::endl; - Rcout << "Rec bias adj being passed to C++ are " << recruit_bias_adjustment - << std::endl; + virtual double evaluate_nll() { + fims::SRBevertonHolt NLL; + + NLL.log_sigma_recruit = this->log_sigma_recruit.value; + NLL.recruit_deviations.resize(deviations.size()); // Vector from TMB + NLL.recruit_bias_adjustment.resize( + recruit_bias_adjustment.size()); // Vector from TMB + for (int i = 0; i < deviations.size(); i++) { + NLL.recruit_deviations[i] = deviations[i]; + NLL.recruit_bias_adjustment[i] = recruit_bias_adjustment[i]; + } + FIMS_LOG << "Rec devs being passed to C++ are " << deviations << std::endl; + + Rcout << "Rec bias adj being passed to C++ are " << recruit_bias_adjustment + << std::endl; - NLL.use_recruit_bias_adjustment = this->use_bias_correction; - NLL.estimate_recruit_deviations = this->estimate_deviations; - return NLL.evaluate_nll(); - } + NLL.use_recruit_bias_adjustment = this->use_bias_correction; + NLL.estimate_recruit_deviations = this->estimate_deviations; + return NLL.evaluate_nll(); + } #ifdef TMB_MODEL @@ -174,6 +179,7 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase { // add to Information info->recruitment_models[recruitment->id] = recruitment; + return true; } /** @brief this adds the parameter values and derivatives to the TMB model @@ -187,7 +193,7 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase { return true; } - + #endif }; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp index cdb9f118..c51947c5 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp @@ -115,6 +115,8 @@ class LogisticSelectivityInterface : public SelectivityInterfaceBase { // add to Information info->selectivity_models[selectivity->id] = selectivity; + + return true; } /** @brief this adds the parameter values and derivatives to the TMB model @@ -218,6 +220,7 @@ class DoubleLogisticSelectivityInterface : public SelectivityInterfaceBase { // add to Information info->selectivity_models[selectivity->id] = selectivity; + return true; } /** @brief this adds the parameter values and derivatives to the TMB model diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index 8baaec16..fafdb569 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -109,6 +109,8 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { info->distribution_models[distributiion->id] = distributiion; + return true; + } /** @@ -186,6 +188,8 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { distribution->sdlog = this->sdlog.value; info->distribution_models[distribution->id] = distribution; + + return true; } /** @@ -271,6 +275,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { info->distribution_models[distribution->id] = distribution; + return true; } virtual bool add_to_fims_tmb() { From 438d75e02a3aa23b8206bf67b189a7ce9ae05d02 Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Thu, 7 Sep 2023 14:39:04 -0400 Subject: [PATCH 03/11] style fixes --- .../interface/rcpp/rcpp_objects/rcpp_data.hpp | 10 ++-- .../rcpp/rcpp_objects/rcpp_fleet.hpp | 50 +++++++++---------- .../rcpp/rcpp_objects/rcpp_growth.hpp | 16 +++--- .../rcpp/rcpp_objects/rcpp_maturity.hpp | 10 ++-- .../rcpp/rcpp_objects/rcpp_population.hpp | 10 ++-- .../rcpp/rcpp_objects/rcpp_recruitment.hpp | 10 ++-- .../rcpp/rcpp_objects/rcpp_selectivity.hpp | 10 ++-- .../rcpp_objects/rcpp_tmb_distribution.hpp | 10 ++-- 8 files changed, 63 insertions(+), 63 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 0d5cb9b4..7dde3b0c 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -89,10 +89,10 @@ class AgeCompDataInterface : public DataInterface { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr> age_comp_data = - std::make_shared> (this->ymax, + std::shared_ptr> age_comp_data = + std::make_shared> (this->ymax, this->amax); age_comp_data->id = this->id; @@ -103,8 +103,8 @@ class AgeCompDataInterface : public DataInterface { } } - std::shared_ptr> info = - fims::Information::GetInstance(); + std::shared_ptr> info = + fims::Information::GetInstance(); info->data_objects[this->id] = age_comp_data; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index d6c6be74..5466cf3e 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -99,52 +99,52 @@ class FleetInterface : public FIMSRcppInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr> info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr> f = - std::make_shared> (); + std::shared_ptr > fleet = + std::make_shared > (); // set relative info - f->id = this->id; - f->is_survey = this->is_survey; - f->nages = this->nages; - f->nyears = this-> nyears; - f->agecomp_likelihood_id = this->agecomp_likelihood_id; - f->index_likelihood_id = this->index_likelihood_id; - f->observed_agecomp_data_id = this->observed_agecomp_data_id; - f->observed_index_data_id = this->observed_index_data_id; - f->selectivity_id = this->selectivity_id; - - f->log_obs_error = this->log_obs_error.value; + fleet->id = this->id; + fleet->is_survey = this->is_survey; + fleet->nages = this->nages; + fleet->nyears = this-> nyears; + fleet->agecomp_likelihood_id = this->agecomp_likelihood_id; + fleet->index_likelihood_id = this->index_likelihood_id; + fleet->observed_agecomp_data_id = this->observed_agecomp_data_id; + fleet->observed_index_data_id = this->observed_index_data_id; + fleet->selectivity_id = this->selectivity_id; + + fleet->log_obs_error = this->log_obs_error.value; if (this->log_obs_error.estimated) { - info->RegisterParameter(f->log_obs_error); + info->RegisterParameter(fleet->log_obs_error); } - f->log_q = this->log_q; + fleet->log_q = this->log_q; if (this->estimate_q) { if (this->random_q) { - info->RegisterRandomEffect(f->log_q); + info->RegisterRandomEffect(fleet->log_q); } else { - info->RegisterParameter(f->log_q); + info->RegisterParameter(fleet->log_q); } } - f->log_Fmort.resize(this->log_Fmort.size()); + fleet->log_Fmort.resize(this->log_Fmort.size()); for (int i = 0; i < log_Fmort.size(); i++) { - f->log_Fmort[i] = this->log_Fmort[i]; + fleet->log_Fmort[i] = this->log_Fmort[i]; if (this->estimate_F) { if (this->random_F) { - info->RegisterRandomEffect(f->log_Fmort[i]); + info->RegisterRandomEffect(fleet->log_Fmort[i]); } else { - info->RegisterParameter(f->log_Fmort[i]); + info->RegisterParameter(fleet->log_Fmort[i]); } } } // add to Information - info->fleets[f->id] = f; + info->fleets[fleet->id] = fleet; return true; } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp index 4999ddc1..1b6028be 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp @@ -112,19 +112,19 @@ class EWAAGrowthInterface : public GrowthInterfaceBase { } #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > data = - std::make_shared >(); + std::shared_ptr > ewaa_growth = + std::make_shared >(); // set relative info - data->id = this->id; - data->ewaa = make_map(this->ages, this->weights); //this->ewaa; + ewaa_growth->id = this->id; + ewaa_growth->ewaa = make_map(this->ages, this->weights); //this->ewaa; // add to Information - info->growth_models[data->id] = data; + info->growth_models[ewaa_growth->id] = ewaa_growth; return true; } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp index cc72413e..ae5bbe1a 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp @@ -87,13 +87,13 @@ class LogisticMaturityInterface : public MaturityInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > maturity = - std::make_shared >(); + std::shared_ptr > maturity = + std::make_shared >(); // set relative info maturity->id = this->id; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index 5c4157d8..a3955886 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -110,13 +110,13 @@ class PopulationInterface : public PopulationInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > population = - std::make_shared >(); + std::shared_ptr > population = + std::make_shared >(); // set relative info population->id = this->id; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp index efb2795b..9dd87597 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp @@ -128,13 +128,13 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > recruitment = - std::make_shared >(); + std::shared_ptr > recruitment = + std::make_shared >(); // set relative info recruitment->id = this->id; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp index c51947c5..e9d78e83 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp @@ -173,14 +173,14 @@ class DoubleLogisticSelectivityInterface : public SelectivityInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr > selectivity = + std::shared_ptr > selectivity = std::make_shared< - fims::DoubleLogisticSelectivity >(); + fims::DoubleLogisticSelectivity >(); // set relative info selectivity->id = this->id; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index fafdb569..52949d52 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -92,13 +92,13 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr> info = - fims::Information::GetInstance(); + std::shared_ptr> info = + fims::Information::GetInstance(); - std::shared_ptr> distributiion = - std::make_shared> (); + std::shared_ptr> distributiion = + std::make_shared> (); // interface to data/parameter value distributiion->id = this->id; From cc70a6d227d475dc8874cf2be5bc7bc5de2c43dd Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Tue, 12 Sep 2023 05:18:19 -0400 Subject: [PATCH 04/11] Update rcpp_tmb_distribution.hpp --- .../rcpp_objects/rcpp_tmb_distribution.hpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index 52949d52..ac116bc4 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -97,17 +97,17 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { std::shared_ptr> info = fims::Information::GetInstance(); - std::shared_ptr> distributiion = + std::shared_ptr> distribution = std::make_shared> (); // interface to data/parameter value - distributiion->id = this->id; - distributiion->x = this->x.value; + distribution->id = this->id; + distribution->x = this->x.value; // set relative info - distributiion->mean = this->mean.value; - distributiion->sd = this->sd.value; + distribution->mean = this->mean.value; + distribution->sd = this->sd.value; - info->distribution_models[distributiion->id] = distributiion; + info->distribution_models[distribution->id] = distribution; return true; @@ -171,15 +171,16 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { dlnorm.do_bias_correction = this->do_bias_correction; return dlnorm.evaluate(do_log); } + #ifdef TMB_MODEL - template + template bool add_to_fims_tmb_internal() { - std::shared_ptr > info = - fims::Information::GetInstance(); + std::shared_ptr > info = + fims::Information::GetInstance(); - std::shared_ptr < fims::Dlnorm > distribution = - std::make_shared > (); + std::shared_ptr < fims::Dlnorm > distribution = + std::make_shared > (); // set relative info distribution->id = this->id; @@ -257,7 +258,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { template bool add_to_fims_tmb_internal() { - typedef typename fims::ModelTraits::EigenVector Vector0; + std::shared_ptr > info = fims::Information::GetInstance(); From c9f75933c51c113d313c81a610593448309edd07 Mon Sep 17 00:00:00 2001 From: Matthew-Supernaw-NOAA Date: Tue, 12 Sep 2023 07:01:36 -0400 Subject: [PATCH 05/11] Update rcpp_tmb_distribution.hpp --- .../interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index ac116bc4..aac62e27 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -258,7 +258,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { template bool add_to_fims_tmb_internal() { - + typedef typename fims::ModelTraits::EigenVector Vector0; std::shared_ptr > info = fims::Information::GetInstance(); From 0ef6108a1c561716e4221684ab0b84c67558b76d Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:03:21 +0000 Subject: [PATCH 06/11] rename vector object --- .../rcpp/rcpp_objects/rcpp_tmb_distribution.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index e0605d3b..1b7057ae 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -241,9 +241,9 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { fims::Dmultinom dmultinom; // Decale TMBVector in this scope typedef - typename fims::ModelTraits::EigenVector TMBVector; - dmultinom.x = TMBVector(x.size()); // Vector from TMB - dmultinom.p = TMBVector(p.size()); // Vector from TMB + typename fims::ModelTraits::EigenVector Vector; + dmultinom.x = Vector(x.size()); // Vector from TMB + dmultinom.p = Vector(p.size()); // Vector from TMB for (int i = 0; i < x.size(); i++) { dmultinom.x[i] = x[i]; dmultinom.p[i] = p[i]; @@ -255,7 +255,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { template bool add_to_fims_tmb_internal() { - typedef typename fims::ModelTraits::EigenVector Vector0; + typedef typename fims::ModelTraits::EigenVector Vector; std::shared_ptr > info = fims::Information::GetInstance(); @@ -263,8 +263,8 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { std::make_shared > (); distribution->id = this->id; - distribution->x = Vector0(x.size()); - distribution->p = Vector0(p.size()); + distribution->x = Vector(x.size()); + distribution->p = Vector(p.size()); for (int i = 0; i < x.size(); i++) { distribution->x[i] = x[i]; From b3056d792d20370773772ae6d59fffcb85361783 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:22:40 +0000 Subject: [PATCH 07/11] cleanup --- inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index ebac928f..59d2703a 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -26,6 +26,9 @@ class FleetInterface : public FIMSRcppInterfaceBase { int selectivity_id = -999; /*!< id of selectivity component*/ public: + static uint32_t id_g; /**< static id of the FleetInterface object */ + uint32_t id; /**< local id of the FleetInterface object */ + bool is_survey = false; /*!< whether this is a survey fleet */ int nages; /*!< number of ages in the fleet data*/ int nyears; /*!< number of years in the fleet data */ @@ -38,10 +41,6 @@ class FleetInterface : public FIMSRcppInterfaceBase { bool random_F = false; /*!< whether F should be a random effect*/ Parameter log_obs_error; /*!< the log of the observation error */ -public: - static uint32_t id_g; /**< static id of the FleetInterface object */ - uint32_t id; /**< local id of the FleetInterface object */ - FleetInterface() { this->id = FleetInterface::id_g++; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); From 3b08883b3df7ff22e5a79101a1792476e19ef8e2 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Wed, 27 Sep 2023 18:40:19 +0000 Subject: [PATCH 08/11] refactor and doc: rename to live_objects throughout rcpp interface --- inst/include/interface/rcpp/rcpp_interface.hpp | 10 +++++----- inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp | 2 ++ .../interface/rcpp/rcpp_objects/rcpp_growth.hpp | 2 ++ .../interface/rcpp/rcpp_objects/rcpp_maturity.hpp | 8 +++++--- inst/include/interface/rcpp/rcpp_objects/rcpp_nll.hpp | 2 ++ .../interface/rcpp/rcpp_objects/rcpp_population.hpp | 2 ++ .../interface/rcpp/rcpp_objects/rcpp_recruitment.hpp | 2 ++ .../interface/rcpp/rcpp_objects/rcpp_selectivity.hpp | 8 +++++--- .../rcpp/rcpp_objects/rcpp_tmb_distribution.hpp | 2 ++ 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index 06690d81..62f1bea8 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -114,10 +114,10 @@ void clear() { // rcpp_maturity.hpp MaturityInterfaceBase::id_g = 1; - MaturityInterfaceBase::maturity_objects.clear(); + MaturityInterfaceBase::live_objects.clear(); LogisticMaturityInterface::id_g = 1; - LogisticMaturityInterface::maturity_objects.clear(); + LogisticMaturityInterface::live_objects.clear(); // rcpp_population.hpp // PopulationInterfaceBase::id_g = 1; @@ -135,13 +135,13 @@ void clear() { // rcpp_selectivity.hpp SelectivityInterfaceBase::id_g = 1; - SelectivityInterfaceBase::selectivity_objects.clear(); + SelectivityInterfaceBase::live_objects.clear(); LogisticSelectivityInterface::id_g = 1; - LogisticSelectivityInterface::selectivity_objects.clear(); + LogisticSelectivityInterface::live_objects.clear(); DoubleLogisticSelectivityInterface::id_g = 1; - DoubleLogisticSelectivityInterface::selectivity_objects.clear(); + DoubleLogisticSelectivityInterface::live_objects.clear(); // rcpp_tmb_distribution.hpp DistributionsInterfaceBase::id_g = 1; diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 7dde3b0c..77cd3d2c 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -22,6 +22,7 @@ class DataInterface : public FIMSRcppInterfaceBase { Rcpp::NumericVector observed_data; /*!< The data */ static uint32_t id_g; /**< static id of the DataInterface object */ uint32_t id; /**< local id of the DataInterface object */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map associating the ids of DataInterface to the objects */ @@ -30,6 +31,7 @@ class DataInterface : public FIMSRcppInterfaceBase { */ DataInterface() { this->id = DataInterface::id_g++; + //Create instance of map: key is id and value is pointer to DataInterface DataInterface::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp index 1b6028be..5fa70cf4 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_growth.hpp @@ -25,12 +25,14 @@ class GrowthInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the GrowthInterfaceBase object */ uint32_t id; /**< local id of the GrowthInterfaceBase object */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map relating the ID of the GrowthInterfaceBase to the GrowthInterfaceBase objects */ GrowthInterfaceBase() { this->id = GrowthInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to GrowthInterfaceBase GrowthInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp index 9fb91ab8..660b723b 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp @@ -25,13 +25,15 @@ class MaturityInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the recruitment interface base*/ uint32_t id; /**< id of the recruitment interface base */ + //live objects in C++ are objects that have been created and live in memory static std::map - maturity_objects; /**< map associating the ids of + live_objects; /**< map associating the ids of MaturityInterfaceBase to the objects */ MaturityInterfaceBase() { this->id = MaturityInterfaceBase::id_g++; - MaturityInterfaceBase::maturity_objects[this->id] = this; + //Create instance of map: key is id and value is pointer to MaturityInterfaceBase + MaturityInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } @@ -51,7 +53,7 @@ class MaturityInterfaceBase : public FIMSRcppInterfaceBase { uint32_t MaturityInterfaceBase::id_g = 1; std::map -MaturityInterfaceBase::maturity_objects; +MaturityInterfaceBase::live_objects; /** * @brief Rcpp interface for logistic maturity as an S4 object. To diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_nll.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_nll.hpp index d89a2532..70d52791 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_nll.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_nll.hpp @@ -21,11 +21,13 @@ class NLLInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the recruitment interface base*/ uint32_t id; /**< id of the recruitment interface base */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map associating the ids of NLLInterfaceBase to the objects */ NLLInterfaceBase() { this->id = NLLInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to NLLInterfaceBase NLLInterfaceBase::live_objects[this->id] = this; NLLInterfaceBase::fims_interface_objects.push_back(this); } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index a3955886..9ecdbcb1 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -23,12 +23,14 @@ class PopulationInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the population interface base*/ uint32_t id; /**< id of the population interface base */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map associating the ids of PopulationInterfaceBase to the objects */ PopulationInterfaceBase() { this->id = PopulationInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to PopulationInterfaceBase PopulationInterfaceBase::live_objects[this->id] = this; PopulationInterfaceBase::fims_interface_objects.push_back(this); } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp index 2521bc67..86b45267 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp @@ -24,6 +24,7 @@ class RecruitmentInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the recruitment interface base*/ uint32_t id; /**< id of the recruitment interface base */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map associating the ids of RecruitmentInterfaceBase to the objects */ @@ -34,6 +35,7 @@ class RecruitmentInterfaceBase : public FIMSRcppInterfaceBase { RecruitmentInterfaceBase() { this->id = RecruitmentInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to RecruitmentInterfaceBase RecruitmentInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp index d9e4eaa2..909c9bfa 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_selectivity.hpp @@ -24,13 +24,15 @@ class SelectivityInterfaceBase : public FIMSRcppInterfaceBase { public: static uint32_t id_g; /**< static id of the recruitment interface base*/ uint32_t id; /**< id of the recruitment interface base */ + //live objects in C++ are objects that have been created and live in memory static std::map - selectivity_objects; /**< map associating the ids of + live_objects; /**< map associating the ids of SelectivityInterfaceBase to the objects */ SelectivityInterfaceBase() { this->id = SelectivityInterfaceBase::id_g++; - SelectivityInterfaceBase::selectivity_objects[this->id] = this; + //Create instance of map: key is id and value is pointer to SelectivityInterfaceBase + SelectivityInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } @@ -50,7 +52,7 @@ class SelectivityInterfaceBase : public FIMSRcppInterfaceBase { uint32_t SelectivityInterfaceBase::id_g = 1; std::map -SelectivityInterfaceBase::selectivity_objects; +SelectivityInterfaceBase::live_objects; /** * @brief Rcpp interface for logistic selectivity as an S4 object. To diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index 1b7057ae..7928d7f5 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -22,12 +22,14 @@ class DistributionsInterfaceBase : public FIMSRcppInterfaceBase { static uint32_t id_g; /**< static id of the DistributionsInterfaceBase object */ uint32_t id; /**< local id of the DistributionsInterfaceBase object */ + //live objects in C++ are objects that have been created and live in memory static std::map live_objects; /**< map relating the ID of the DistributionsInterfaceBase to the DistributionsInterfaceBase objects */ DistributionsInterfaceBase() { this->id = DistributionsInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to DistributionsInterfaceBase DistributionsInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } From 4f4c74c35060c5425af62aed33a1bfc71a37d190 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:28:34 +0000 Subject: [PATCH 09/11] fix rcpp naming conventions --- .../include/interface/rcpp/rcpp_interface.hpp | 10 +++--- .../interface/rcpp/rcpp_objects/rcpp_data.hpp | 32 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index 62f1bea8..86b3dc02 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -97,8 +97,8 @@ void clear() { FIMSRcppInterfaceBase::fims_interface_objects.clear(); // rcpp_data.hpp - DataInterface::id_g = 1; - DataInterface::fims_interface_objects.clear(); + DataInterfaceBase::id_g = 1; + DataInterfaceBase::fims_interface_objects.clear(); AgeCompDataInterface::id_g = 1; IndexDataInterface::id_g = 1; @@ -211,10 +211,10 @@ RCPP_MODULE(fims) { .method("SetObservedIndexData", &FleetInterface::SetObservedIndexData) .method("SetSelectivity", &FleetInterface::SetSelectivity); - Rcpp::class_("Data") + Rcpp::class_("Data") .constructor() - .field("observed_data", &DataInterface::observed_data) - .method("get_id", &DataInterface::get_id); + .field("observed_data", &DataInterfaceBase::observed_data) + .method("get_id", &DataInterfaceBase::get_id); Rcpp::class_("AgeComp") .constructor() diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 77cd3d2c..83879bd7 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -17,28 +17,28 @@ * fleet <- new(fims$Data) * */ -class DataInterface : public FIMSRcppInterfaceBase { +class DataInterfaceBase : public FIMSRcppInterfaceBase { public: Rcpp::NumericVector observed_data; /*!< The data */ - static uint32_t id_g; /**< static id of the DataInterface object */ - uint32_t id; /**< local id of the DataInterface object */ + static uint32_t id_g; /**< static id of the DataInterfaceBase object */ + uint32_t id; /**< local id of the DataInterfaceBase object */ //live objects in C++ are objects that have been created and live in memory - static std::map - live_objects; /**< map associating the ids of DataInterface to + static std::map + live_objects; /**< map associating the ids of DataInterfaceBase to the objects */ /** @brief constructor */ - DataInterface() { - this->id = DataInterface::id_g++; - //Create instance of map: key is id and value is pointer to DataInterface - DataInterface::live_objects[this->id] = this; + DataInterfaceBase() { + this->id = DataInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to DataInterfaceBase + DataInterfaceBase::live_objects[this->id] = this; FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); } /** @brief destructor */ - virtual ~DataInterface() { + virtual ~DataInterfaceBase() { } /** @brief get the ID of the interface base object @@ -54,15 +54,15 @@ class DataInterface : public FIMSRcppInterfaceBase { return true; }; }; -uint32_t DataInterface::id_g = 1; -std::map DataInterface::live_objects; +uint32_t DataInterfaceBase::id_g = 1; +std::map DataInterfaceBase::live_objects; /** * @brief Rcpp interface for age comp data as an S4 object. To instantiate * from R: * acomp <- new(fims$AgeComp) */ -class AgeCompDataInterface : public DataInterface { +class AgeCompDataInterface : public DataInterfaceBase { public: int amax; /*!< first dimension of the data */ int ymax; /*!< second dimension of the data */ @@ -71,7 +71,7 @@ class AgeCompDataInterface : public DataInterface { /** * @brief constructor */ - AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterface() { + AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterfacBase() { this->amax = amax; this->ymax = ymax; } @@ -133,7 +133,7 @@ class AgeCompDataInterface : public DataInterface { * from R: * fleet <- new(fims$Index) */ -class IndexDataInterface : public DataInterface { +class IndexDataInterface : public DataInterfaceBase { public: int ymax; /*!< second dimension of the data */ Rcpp::NumericVector index_data; /*!ymax = ymax; } From 4cbbbf0a7e8eaa58c7aeebf30ccda00aade36129 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Wed, 27 Sep 2023 20:02:03 +0000 Subject: [PATCH 10/11] add FleetInterfaceBase and fix clear function --- .../include/interface/rcpp/rcpp_interface.hpp | 14 +++-- .../interface/rcpp/rcpp_objects/rcpp_data.hpp | 2 +- .../rcpp/rcpp_objects/rcpp_fleet.hpp | 52 +++++++++++++++---- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index 86b3dc02..85cecb2d 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -95,16 +95,24 @@ void clear_internal() { void clear() { // rcpp_interface_base.hpp FIMSRcppInterfaceBase::fims_interface_objects.clear(); + // rcpp_data.hpp - DataInterfaceBase::id_g = 1; - DataInterfaceBase::fims_interface_objects.clear(); + DataInterfaceBase::live_objects.clear(); + AgeCompDataInterface::id_g = 1; + AgeCompDataInterface::live_objects.clear(); + IndexDataInterface::id_g = 1; + IndexDataInterface::live_objects.clear(); // rcpp_fleets.hpp + FleetInterfaceBase::id_g = 1; + FleetInterfaceBase::live_objects.clear(); + FleetInterface::id_g = 1; - FleetInterface::fims_interface_objects.clear(); + FleetInterface::live_objects.clear(); + // rcpp_growth.hpp GrowthInterfaceBase::id_g = 1; GrowthInterfaceBase::live_objects.clear(); diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp index 83879bd7..10d57e99 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp @@ -71,7 +71,7 @@ class AgeCompDataInterface : public DataInterfaceBase { /** * @brief constructor */ - AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterfacBase() { + AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterfaceBase() { this->amax = amax; this->ymax = ymax; } diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index 59d2703a..f0df1571 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -12,23 +12,53 @@ #include "../../../population_dynamics/fleet/fleet.hpp" #include "rcpp_interface_base.hpp" +/** + * @brief Rcpp interface that serves as the parent class for + * Rcpp fleet interfaces. This type should be inherited and not + * called from R directly. + * + */ +class FleetInterfaceBase : public FIMSRcppInterfaceBase { +public: + static uint32_t id_g; /**< static id of the FleetInterfaceBase object */ + uint32_t id; /**< local id of the FleetInterfaceBase object */ + //live objects in C++ are objects that have been created and live in memory + static std::map live_objects; /**< + map relating the ID of the FleetInterfaceBase to the FleetInterfaceBase + objects */ + + FleetInterfaceBase() { + this->id = FleetInterfaceBase::id_g++; + //Create instance of map: key is id and value is pointer to FleetInterfaceBase + FleetInterfaceBase::live_objects[this->id] = this; + FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + } + + virtual ~FleetInterfaceBase() { + } + + /** @brief get_id method for child fleet interface objects to inherit **/ + virtual uint32_t get_id() = 0; + +}; + +uint32_t FleetInterfaceBase::id_g = 1; +std::map FleetInterfaceBase::live_objects; + /** * @brief Rcpp interface for Fleet as an S4 object. To instantiate * from R: * fleet <- new(fims$Fleet) * */ -class FleetInterface : public FIMSRcppInterfaceBase { +class FleetInterface : public FleetInterfaceBase { int agecomp_likelihood_id = -999; /*!< id of agecomp likelihood component*/ int index_likelihood_id = -999; /*!< id of index likelihood component*/ int observed_agecomp_data_id = -999; /*!< id of observed agecomp data object*/ int observed_index_data_id = -999; /*!< id of observed index data object*/ int selectivity_id = -999; /*!< id of selectivity component*/ -public: - static uint32_t id_g; /**< static id of the FleetInterface object */ - uint32_t id; /**< local id of the FleetInterface object */ - +public: bool is_survey = false; /*!< whether this is a survey fleet */ int nages; /*!< number of ages in the fleet data*/ int nyears; /*!< number of years in the fleet data */ @@ -41,14 +71,18 @@ class FleetInterface : public FIMSRcppInterfaceBase { bool random_F = false; /*!< whether F should be a random effect*/ Parameter log_obs_error; /*!< the log of the observation error */ - FleetInterface() { - this->id = FleetInterface::id_g++; - FIMSRcppInterfaceBase::fims_interface_objects.push_back(this); + FleetInterface() : FleetInterfaceBase() { + } virtual ~FleetInterface() { } + /** @brief returns the id for the fleet interface */ + virtual uint32_t get_id() { + return this->id; + } + /** * @brief Set the unique id for the Age Comp Likelihood object * @@ -159,6 +193,4 @@ class FleetInterface : public FIMSRcppInterfaceBase { #endif }; -uint32_t FleetInterface::id_g = 1; - #endif From 757da5679ff7f12cb60ab1c89b308f8daa1c862d Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:13:45 +0000 Subject: [PATCH 11/11] cleanup rcpp_interface --- inst/include/interface/rcpp/rcpp_interface.hpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index 85cecb2d..ae3e7887 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -128,8 +128,8 @@ void clear() { LogisticMaturityInterface::live_objects.clear(); // rcpp_population.hpp - // PopulationInterfaceBase::id_g = 1; - // PopulationInterfaceBase::live_objects.clear(); + PopulationInterfaceBase::id_g = 1; + PopulationInterfaceBase::live_objects.clear(); PopulationInterface::id_g = 1; PopulationInterface::live_objects.clear(); @@ -164,7 +164,6 @@ void clear() { DmultinomDistributionsInterface::id_g = 1; DmultinomDistributionsInterface::live_objects.clear(); - FIMSRcppInterfaceBase::fims_interface_objects.clear(); clear_internal(); clear_internal(); clear_internal(); @@ -219,11 +218,6 @@ RCPP_MODULE(fims) { .method("SetObservedIndexData", &FleetInterface::SetObservedIndexData) .method("SetSelectivity", &FleetInterface::SetSelectivity); - Rcpp::class_("Data") - .constructor() - .field("observed_data", &DataInterfaceBase::observed_data) - .method("get_id", &DataInterfaceBase::get_id); - Rcpp::class_("AgeComp") .constructor() .field("age_comp_data", &AgeCompDataInterface::age_comp_data)