diff --git a/inst/include/common/information.hpp b/inst/include/common/information.hpp index 5ece7f5a..e0b599c4 100644 --- a/inst/include/common/information.hpp +++ b/inst/include/common/information.hpp @@ -116,10 +116,10 @@ class Information { density_components_iterator; /**< iterator for distribution objects>*/ - std::unordered_map* > - variable_map; /*** > + variable_map; /*** >::iterator + typedef typename std::unordered_map* >::iterator variable_map_iterator; /**< iterator for variable map>*/ Information() {} @@ -166,7 +166,9 @@ class Information { this->parameter_names.push_back(p_name); } - + /** + * Loop over distributions and set links to distribution x value if distribution is a prior type. + */ void setup_priors(){ for(density_components_iterator it = density_components.begin(); it!= density_components.end(); ++it){ std::shared_ptr > d = (*it).second; @@ -174,18 +176,22 @@ class Information { INFO_LOG << "Setup prior for distribution " << d->id << std::endl; variable_map_iterator vmit; INFO_LOG << "Link prior from distribution " << d->id << " to parameter " << d->key[0] << std::endl; - vmit = this->variable_map.find(d->key[0]); + vmit = this->variable_map.find(d->key[0]); d->x = *(*vmit).second; for(size_t i=1; ikey.size(); i++){ INFO_LOG << "Link prior from distribution " << d->id << " to parameter " << d->key[i] << std::endl; - vmit = this->variable_map.find(d->key[i]); - d->x.insert(std::end(d->x), + vmit = this->variable_map.find(d->key[i]); + d->x.insert(std::end(d->x), std::begin(*(*vmit).second), std::end(*(*vmit).second)); - } + } INFO_LOG << "Prior size for distribution " << d->id << "is: " << d->x.size() << std::endl; } } } + + /** + * Loop over distributions and set links to distribution x value if distribution is a random effects type. + */ void setup_random_effects(){ for(density_components_iterator it = this->density_components.begin(); it!= this->density_components.end(); ++it){ std::shared_ptr > d = (*it).second; @@ -193,18 +199,22 @@ class Information { INFO_LOG << "Setup random effects for distribution " << d->id << std::endl; variable_map_iterator vmit; INFO_LOG << "Link random effects from distribution " << d->id << " to derived value " << d->key[0] << std::endl; - vmit = this->variable_map.find(d->key[0]); + vmit = this->variable_map.find(d->key[0]); d->x = *(*vmit).second; for(size_t i=1; ikey.size(); i++){ INFO_LOG << "Link random effects from distribution " << d->id << " to derived value " << d->key[i] << std::endl; - vmit = this->variable_map.find(d->key[i]); - d->x.insert(std::end(d->x), + vmit = this->variable_map.find(d->key[i]); + d->x.insert(std::end(d->x), std::begin(*(*vmit).second), std::end(*(*vmit).second)); - } + } INFO_LOG << "Random effect size for distribution " << d->id << "is: " << d->x.size() << std::endl; } } } + + /** + * Loop over distributions and set links to distribution expected value if distribution is a data type. + */ void setup_data(){ for(density_components_iterator it = this->density_components.begin(); it!= this->density_components.end(); ++it){ std::shared_ptr > d = (*it).second; @@ -212,20 +222,20 @@ class Information { INFO_LOG << "Setup expected value for data distribution " << d->id << std::endl; variable_map_iterator vmit; INFO_LOG << "Link expected value from distribution " << d->id << " to derived value " << d->key[0] << std::endl; - vmit = this->variable_map.find(d->key[0]); + vmit = this->variable_map.find(d->key[0]); d->expected_values = *(*vmit).second; - + for(size_t i=1; ikey.size(); i++){ vmit = this->variable_map.find(d->key[i]); - INFO_LOG << "Link expected value from distribution " << d->id << " to derived value " << d->key[i] << std::endl; - d->expected_values.insert(std::end(d->expected_values), + INFO_LOG << "Link expected value from distribution " << d->id << " to derived value " << d->key[i] << std::endl; + d->expected_values.insert(std::end(d->expected_values), std::begin(*(*vmit).second), std::end(*(*vmit).second)); - } + } INFO_LOG << "Expected value size for distribution " << d->id << "is: " << d->expected_values.size() << std::endl; } } } - + /** @@ -289,7 +299,7 @@ class Information { } INFO_LOG << "Expecting to import " << this->data_objects.size() << " data objects." << std::endl; - for(density_components_iterator it = this->density_components.begin(); + for(density_components_iterator it = this->density_components.begin(); it!= this->density_components.end(); ++it){ std::shared_ptr > d = (*it).second; INFO_LOG << "Checking for available density components data objects." @@ -320,7 +330,7 @@ class Information { } // end set data } - + INFO_LOG << "Initializing population objects for " << this->populations.size() << " populations." << std::endl; for (population_iterator it = this->populations.begin(); @@ -446,7 +456,7 @@ class Information { //setup priors, random effect, and data density components INFO_LOG << "Setup priors." << std::endl; setup_priors(); - + INFO_LOG << "Completed FIMS model creation." << std::endl; return valid_model; } diff --git a/inst/include/population_dynamics/fleet/fleet.hpp b/inst/include/population_dynamics/fleet/fleet.hpp index 29fec90b..9ca0db58 100644 --- a/inst/include/population_dynamics/fleet/fleet.hpp +++ b/inst/include/population_dynamics/fleet/fleet.hpp @@ -47,16 +47,16 @@ struct Fleet : public fims_model_object::FIMSObject { fims::Vector age_composition; /*! observed_catch_lpdf; /*! observed_catch_lpdf; /*! observed_index_lpdf; /*! observed_index_lpdf; /*! expected_catch; /*! expected_index; /*! log_expected_index; /*! expected_catch_lpdf; /*! expected_catch_lpdf; /*! expected_index_lpdf; /*! expected_index_lpdf; /*! catch_numbers_at_age; /*! proportion_catch_numbers_at_age; /*! { } } + /** + * Evaluate the proportion of catch numbers at age. + */ void evaluate_age_comp() { for (size_t y = 0; y < this->nyears; y++) { Type sum = 0.0; @@ -143,11 +146,14 @@ struct Fleet : public fims_model_object::FIMSObject { for (size_t a = 0; a < this->nages; a++) { size_t i_age_year = y * this->nages + a; this->proportion_catch_numbers_at_age[i_age_year] = this->catch_numbers_at_age[i_age_year] / sum; - + } - } + } } + /** + * Evaluate the log of the expected index. + */ void evaluate_index() { for(size_t i=0; iexpected_index.size(); i++){ log_expected_index[i] = log(this->expected_index[i]);