diff --git a/inst/include/common/data_object.hpp b/inst/include/common/data_object.hpp index 19eb4a774..35defd6dd 100644 --- a/inst/include/common/data_object.hpp +++ b/inst/include/common/data_object.hpp @@ -36,6 +36,7 @@ #include #include "model_object.hpp" +#include "fims_vector.hpp" namespace fims_data_object { diff --git a/inst/include/common/information.hpp b/inst/include/common/information.hpp index 1b976ab4b..fe407c21d 100644 --- a/inst/include/common/information.hpp +++ b/inst/include/common/information.hpp @@ -173,7 +173,7 @@ class Information { } void setup_random_effects(){ for(density_components_iterator it = this->density_components.begin(); it!= this->density_components.end(); ++it){ - std::shared_ptr > n = (*it).second; + std::shared_ptr > d = (*it).second; if(d->input_type == "re"){ variable_map_iterator vmit; vmit = this->variable_map.find(d->key[0]); @@ -188,7 +188,7 @@ class Information { } void setup_data(){ for(density_components_iterator it = this->density_components.begin(); it!= this->density_components.end(); ++it){ - std::shared_ptr > n = (*it).second; + std::shared_ptr > d = (*it).second; if(d->input_type == "data"){ variable_map_iterator vmit; vmit = this->variable_map.find(d->key[0]); diff --git a/inst/include/distributions/functors/lognormal_lpdf.hpp b/inst/include/distributions/functors/lognormal_lpdf.hpp index 1822599c4..89e6eeae0 100644 --- a/inst/include/distributions/functors/lognormal_lpdf.hpp +++ b/inst/include/distributions/functors/lognormal_lpdf.hpp @@ -46,16 +46,16 @@ namespace fims_distributions */ virtual const Type evaluate() { - this->logmu.resize(this->x.size()); - this->logsd.resize(this->x.size()); - this->lpdf_vec.resize(this->x.size()); - for (size_t i = 0; i < this->x.size(); i++) + this->logmu.resize(this->x->size()); + this->logsd.resize(this->x->size()); + this->lpdf_vec.resize(this->x->size()); + for (size_t i = 0; i < this->x->size(); i++) { if (this->expected_values.size() == 1) { this->logmu[i] = this->expected_values[0]; } else { - if(this->x.size() != this->expected_values.size()){ + if(this->x->size() != this->expected_values.size()){ /* move error handling to CreateModel in information so not to crash R Rcpp::stop("the dimensions of the observed and expected values from lognormal negative log likelihood do not match"); */ @@ -67,7 +67,7 @@ namespace fims_distributions { logsd[i] = fims_math::exp(log_logsd[0]); } else { - if(this->x.size() != this->log_logsd.size()){ + if(this->x->size() != this->log_logsd.size()){ /* move error handling to CreateModel in information so not to crash R Rcpp::stop("the dimensions of the observed and log logsd values from lognormal negative log likelihood do not match"); */ @@ -94,7 +94,7 @@ namespace fims_distributions FIMS_SIMULATE_F(this->of) { // preprocessor definition in interface.hpp // this simulates data that is mean biased - this->x[i] = fims_math::exp(rnorm(logmu[i], logsd[i])); + this->x->at(i) = fims_math::exp(rnorm(logmu[i], logsd[i])); } } #endif diff --git a/inst/include/distributions/functors/normal_lpdf.hpp b/inst/include/distributions/functors/normal_lpdf.hpp index 615441eef..3eda05a25 100644 --- a/inst/include/distributions/functors/normal_lpdf.hpp +++ b/inst/include/distributions/functors/normal_lpdf.hpp @@ -45,14 +45,14 @@ struct NormalLPDF : public DensityComponentBase { * @brief Evaluates the normal probability density function */ virtual const Type evaluate(){ - this->mu.resize(this->x.size()); - this->sd.resize(this->x.size()); - this->lpdf_vec.resize(this->x.size()); - for(size_t i=0; ix.size(); i++){ + this->mu.resize(this->x->size()); + this->sd.resize(this->x->size()); + this->lpdf_vec.resize(this->x->size()); + for(size_t i=0; ix->size(); i++){ if(this->expected_values.size() == 1){ this->mu[i] = this->expected_values[0]; } else { - if(this->x.size() != this->expected_values.size()){ + if(this->x->size() != this->expected_values.size()){ /* move error handling to CreateModel in information so not to crash R Rcpp::stop("the dimensions of the observed and expected values from normal negative log likelihood do not match"); */ @@ -63,7 +63,7 @@ struct NormalLPDF : public DensityComponentBase { if(log_sd.size() == 1){ sd[i] = fims_math::exp(log_sd[0]); } else { - if(this->x.size() != this->log_sd.size()){ + if(this->x->size() != this->log_sd.size()){ /* move error handling to CreateModel in information so not to crash R Rcpp::stop("the dimensions of the observed and log sd values from normal negative log likelihood do not match"); */ @@ -86,7 +86,7 @@ struct NormalLPDF : public DensityComponentBase { lpdf += this->lpdf_vec[i]; if(this->simulate_flag){ FIMS_SIMULATE_F(this->of){ - this->x[i] = rnorm(mu[i], sd[i]); + this->x->at(i) = rnorm(mu[i], sd[i]); } } #endif 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 3badbd178..50694e9b3 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -97,7 +97,7 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { virtual double evaluate() { fims_distributions::NormalLPDF dnorm; - dnorm.x.resize(this->x.size()); + dnorm.x->resize(this->x.size()); dnorm.expected_values.resize(this->expected_values.size()); dnorm.log_sd.resize(this->log_sd.size()); for(int i=0; iid = this->id_m; - distribution->x.resize(this->x.size()); + distribution->x->resize(this->x.size()); for(int i=0; ix.size(); i++){ distribution->x->at(i) = this->x[i].value_m; } @@ -138,7 +138,7 @@ class DnormDistributionsInterface : public DistributionsInterfaceBase { distribution->log_sd[i] = this->log_sd[i].value_m; } - info->distribution_models[distribution->id] = distribution; + info->density_components[distribution->id] = distribution; return true; } @@ -190,7 +190,7 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { virtual double evaluate() { fims_distributions::LogNormalLPDF dlnorm; dlnorm.input_type = this->input_type; - dlnorm.x.resize(this->x.size()); + dlnorm.x->resize(this->x.size()); dlnorm.expected_values.resize(this->expected_values.size()); dlnorm.log_logsd.resize(this->log_logsd.size()); for(int i=0; iid = this->id_m; distribution->input_type = this->input_type; - distribution->x.resize(this->x.size()); + distribution->x->resize(this->x.size()); for(int i=0; ix.size(); i++){ distribution->x->at(i) = this->x[i].value_m; } @@ -232,7 +232,7 @@ class DlnormDistributionsInterface : public DistributionsInterfaceBase { distribution->log_logsd[i] = this->log_logsd[i].value_m; } - info->distribution_models[distribution->id] = distribution; + info->density_components[distribution->id] = distribution; return true; } @@ -283,7 +283,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { virtual double evaluate() { fims_distributions::MultinomialLPMF dmultinom; // Declare TMBVector in this scope - dmultinom.x.resize(this->x.size()); + dmultinom.x->resize(this->x.size()); dmultinom.expected_values.resize(this->expected_values.size()); for(int i=0; iat(i) = this->x[i].value_m; @@ -308,7 +308,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { std::make_shared>(); distribution->id = this->id_m; - distribution->x.resize(this->x.size()); + distribution->x->resize(this->x.size()); for(int i=0; ix.size(); i++){ distribution->x->at(i) = this->x[i].value_m; } @@ -321,7 +321,7 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { distribution->dims[0] = this->dims[0]; distribution->dims[1] = this->dims[1]; - info->distribution_models[distribution->id] = distribution; + info->density_components[distribution->id] = distribution; return true; } diff --git a/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp b/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp index 28345cb76..9ea8a4bc7 100644 --- a/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp +++ b/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp @@ -66,29 +66,6 @@ struct RecruitmentBase : public fims_model_object::FIMSObject { const Type &spawners, const Type &ssbzero) = 0; // need to add input parameter values - /** @brief Calculates the negative log likelihood of recruitment deviations. - * - */ - virtual const Type evaluate_lpdf() { - Type lpdf = 0.0; /**< The log probability density function value */ - - if (!this->estimate_log_recruit_devs) { - return lpdf; - } else { -#ifdef TMB_MODEL - fims_distributions::NormalLPDF dnorm; - dnorm.x = this->log_recruit_devs; - dnorm.expected_values.resize(this->log_recruit_devs.size()); - dnorm.log_sd.resize(this->log_recruit_devs.size()); - for (size_t i = 0; i < this->log_recruit_devs.size(); i++) { - dnorm.expected_values[i] = 0.0; - dnorm.log_sd[i] = this->log_sigma_recruit[0]; - } - lpdf += dnorm.evaluate(); -#endif - return lpdf; - } - } /** @brief Prepare constrained recruitment deviations. * Based on ADMB sum-to-zero constraint implementation. We still