11#ifndef FIMS_COMMON_INFORMATION_HPP
12#define FIMS_COMMON_INFORMATION_HPP
19#include "../distributions/distributions.hpp"
20#include "../models/functors/fishery_model_base.hpp"
21#include "../population_dynamics/fleet/fleet.hpp"
22#include "../population_dynamics/growth/growth.hpp"
23#include "../population_dynamics/population/population.hpp"
24#include "../population_dynamics/recruitment/recruitment.hpp"
25#include "../population_dynamics/selectivity/selectivity.hpp"
36template <
typename Type>
42 static std::shared_ptr<Information<Type>>
51 std::vector<std::string>
56 std::map<uint32_t, std::shared_ptr<fims_data_object::DataObject<Type>>>
58 typedef typename std::map<
59 uint32_t, std::shared_ptr<fims_data_object::DataObject<Type>>>::iterator
63 std::map<uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>
66 typedef typename std::map<
67 uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>::iterator
71 std::map<uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>
74 typedef typename std::map<
75 uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>::iterator
79 std::map<uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type>>>
82 typedef typename std::map<
83 uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type>>>::iterator
87 std::map<uint32_t, std::shared_ptr<fims_popdy::GrowthBase<Type>>>
91 typename std::map<uint32_t,
92 std::shared_ptr<fims_popdy::GrowthBase<Type>>>::iterator
96 std::map<uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type>>>
99 typedef typename std::map<
100 uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type>>>::iterator
105 std::map<uint32_t, std::shared_ptr<fims_popdy::Fleet<Type>>>
108 typedef typename std::map<uint32_t,
109 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
114 std::map<uint32_t, std::shared_ptr<fims_popdy::Population<Type>>>
118 typename std::map<uint32_t,
119 std::shared_ptr<fims_popdy::Population<Type>>>::iterator
125 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>
128 typedef typename std::map<
130 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>::iterator
134 std::unordered_map<uint32_t,
135 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>>
138 typedef typename std::unordered_map<
139 uint32_t, std::shared_ptr<fims_popdy::FisheryModelBase<Type>>>::iterator
142 std::unordered_map<uint32_t, fims::Vector<Type> *>
145 typedef typename std::unordered_map<uint32_t, fims::Vector<Type> *>::iterator
163 this->parameter_names.clear();
164 this->parameters.clear();
176 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
178 if ((d->priors)[0] != NULL) {
181 if (d->data_expected_values != NULL) {
182 d->data_expected_values->clear();
187 if (d->re_expected_values != NULL) {
188 d->re_expected_values->clear();
204 std::stringstream ss;
205 ss <<
"Information object State:\n";
207 ss <<
"populations: " << this->
populations.size() << std::endl;
210 ss <<
"fleets: " << this->
fleets.size() << std::endl;
211 ss <<
"growth_models: " << this->
growth_models.size() << std::endl;
212 ss <<
"maturity_models: " << this->
maturity_models.size() << std::endl;
213 ss <<
"parameter_names: " << this->parameter_names.size() << std::endl;
214 ss <<
"parameters: " << this->parameters.size() << std::endl;
217 ss <<
"random_effects_parameters: "
221 ss <<
"recruitment_process_models: "
225 ss <<
"models_map: " << this->
models_map.size() << std::endl;
226 ss <<
"n_years: " << this->n_years << std::endl;
227 ss <<
"n_ages: " << this->n_ages << std::endl;
241 std::make_shared<fims_info::Information<Type>>();
270 this->parameter_names.push_back(p_name);
289 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
291 if (d->input_type ==
"prior") {
292 FIMS_INFO_LOG(
"Setup prior for distribution " + fims::to_string(d->id));
294 FIMS_INFO_LOG(
"Link prior from distribution " + fims::to_string(d->id) +
295 " to parameter " + fims::to_string(d->key[0]));
296 d->priors.resize(d->key.size());
297 for (
size_t i = 0; i < d->key.size(); i++) {
299 fims::to_string(d->id) +
" to parameter " +
300 fims::to_string(d->key[0]));
302 d->priors[i] = (*vmit).second;
304 FIMS_INFO_LOG(
"Prior size for distribution " + fims::to_string(d->id) +
305 "is: " + fims::to_string(d->x.size()));
317 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
319 if (d->input_type ==
"random_effects") {
321 fims::to_string(d->id));
324 fims::to_string(d->id) +
" to derived value " +
325 fims::to_string(d->key[0]));
327 d->re = (*vmit).second;
328 if (d->key.size() == 2) {
330 d->re_expected_values = (*vmit).second;
332 d->re_expected_values = &d->expected_values;
335 fims::to_string(d->id) +
336 " is: " + fims::to_string(d->x.size()));
348 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
350 if (d->input_type ==
"data") {
351 FIMS_INFO_LOG(
"Setup expected value for data distribution " +
352 fims::to_string(d->id));
355 fims::to_string(d->id) +
" to derived value " +
356 fims::to_string(d->key[0]));
358 d->data_expected_values = (*vmit).second;
360 "Expected value size for distribution " + fims::to_string(d->id) +
361 " is: " + fims::to_string((*d->data_expected_values).size()));
375 if (f->fleet_observed_landings_data_id_m != -999) {
376 uint32_t observed_landings_id =
377 static_cast<uint32_t
>(f->fleet_observed_landings_data_id_m);
380 f->observed_landings_data = (*it).second;
381 FIMS_INFO_LOG(
"Landings data for fleet " + fims::to_string(f->id) +
382 " successfully set to " +
383 fims::to_string(f->observed_landings_data->at(1)));
387 fims::to_string(f->id) +
", index " +
388 fims::to_string(observed_landings_id));
402 if (f->fleet_observed_index_data_id_m !=
static_cast<Type
>(-999)) {
403 uint32_t observed_index_id =
404 static_cast<uint32_t
>(f->fleet_observed_index_data_id_m);
407 f->observed_index_data = (*it).second;
408 FIMS_INFO_LOG(
"Index data for fleet " + fims::to_string(f->id) +
409 " successfully set to " +
410 fims::to_string(f->observed_index_data->at(1)));
414 fims::to_string(f->id) +
", index " +
415 fims::to_string(observed_index_id));
429 if (f->fleet_observed_agecomp_data_id_m !=
static_cast<Type
>(-999)) {
430 uint32_t observed_agecomp_id =
431 static_cast<uint32_t
>(f->fleet_observed_agecomp_data_id_m);
434 f->observed_agecomp_data = (*it).second;
435 FIMS_INFO_LOG(
"Observed input age-composition data for fleet " +
436 fims::to_string(f->id) +
" successfully set to " +
437 fims::to_string(f->observed_agecomp_data->at(1)));
441 "Expected age-composition observations not defined for fleet " +
442 fims::to_string(f->id));
456 if (f->fleet_observed_lengthcomp_data_id_m !=
static_cast<Type
>(-999)) {
457 uint32_t observed_lengthcomp_id =
458 static_cast<uint32_t
>(f->fleet_observed_lengthcomp_data_id_m);
461 f->observed_lengthcomp_data = (*it).second;
462 FIMS_INFO_LOG(
"Observed input length-composition data for fleet " +
463 fims::to_string(f->id) +
" successfully set to " +
464 fims::to_string(f->observed_lengthcomp_data->at(1)));
468 "Expected length-composition observations not defined for fleet " +
469 fims::to_string(f->id));
484 if (f->fleet_selectivity_id_m !=
static_cast<Type
>(-999)) {
485 uint32_t sel_id =
static_cast<uint32_t
>(
486 f->fleet_selectivity_id_m);
491 f->selectivity = (*it).second;
493 fims::to_string(f->fleet_selectivity_id_m) +
494 " successfully set to fleet " + fims::to_string(f->id));
497 FIMS_ERROR_LOG(
"Expected selectivity pattern not defined for fleet " +
498 fims::to_string(f->id) +
", selectivity pattern " +
499 fims::to_string(sel_id));
503 fims::to_string(f->id) +
504 ". FIMS requires selectivity be defined for all fleets "
505 "when running a catch at age model.");
519 if (p->recruitment_id !=
static_cast<Type
>(-999)) {
520 uint32_t recruitment_uint =
static_cast<uint32_t
>(p->recruitment_id);
522 fims::to_string(recruitment_uint));
527 p->recruitment = (*it).second;
528 FIMS_INFO_LOG(
"Recruitment model " + fims::to_string(recruitment_uint) +
529 " successfully set to population " +
530 fims::to_string(p->id));
534 "Expected recruitment function not defined for "
536 fims::to_string(p->id) +
", recruitment function " +
537 fims::to_string(recruitment_uint));
541 "No recruitment function defined for population " +
542 fims::to_string(p->id) +
543 ". FIMS requires recruitment functions be defined for all "
544 "populations when running a catch at age model.");
558 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r = p->recruitment;
561 if (r->process_id != -999) {
562 uint32_t process_uint =
static_cast<uint32_t
>(r->process_id);
567 r->process = (*it).second;
569 "Recruitment Process model " + fims::to_string(process_uint) +
570 " successfully set to population " + fims::to_string(p->id));
571 (*it).second->recruitment = r;
575 "Expected recruitment process function not defined for "
577 fims::to_string(p->id) +
", recruitment process function " +
578 fims::to_string(process_uint));
582 "No recruitment process function defined for population " +
583 fims::to_string(p->id) +
584 ". FIMS requires recruitment process functions be defined for all "
585 "recruitments when running a catch at age model.");
600 if (p->growth_id !=
static_cast<Type
>(-999)) {
601 uint32_t growth_uint =
static_cast<uint32_t
>(p->growth_id);
611 FIMS_INFO_LOG(
"Growth model " + fims::to_string(growth_uint) +
612 " successfully set to population " +
613 fims::to_string(p->id));
616 FIMS_ERROR_LOG(
"Expected growth function not defined for population " +
617 fims::to_string(p->id) +
", growth function " +
618 fims::to_string(growth_uint));
622 fims::to_string(p->id) +
623 ". FIMS requires growth functions be defined for all "
624 "populations when running a catch at age model.");
638 if (p->maturity_id !=
static_cast<Type
>(-999)) {
639 uint32_t maturity_uint =
static_cast<uint32_t
>(p->maturity_id);
644 p->maturity = (*it).second;
645 FIMS_INFO_LOG(
"Maturity model " + fims::to_string(maturity_uint) +
646 " successfully set to population " +
647 fims::to_string(p->id));
651 "Expected maturity function not defined for population " +
652 fims::to_string(p->id) +
", maturity function " +
653 fims::to_string(maturity_uint));
657 fims::to_string(p->id) +
658 ". FIMS requires maturity functions be defined for all "
659 "populations when running a catch at age model.");
672 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
673 FIMS_INFO_LOG(
"Initializing fleet " + fims::to_string(f->id));
696 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
700 if (d->input_type ==
"data") {
701 if (d->observed_data_id_m !=
static_cast<Type
>(-999)) {
702 uint32_t observed_data_id =
703 static_cast<uint32_t
>(d->observed_data_id_m);
707 d->observed_values = (*it).second;
708 FIMS_INFO_LOG(
"Observed data " + fims::to_string(observed_data_id) +
709 " successfully set to density component " +
710 fims::to_string(d->id));
714 "Expected data observations not defined for density "
716 fims::to_string(d->id) +
", observed data " +
717 fims::to_string(observed_data_id));
722 fims::to_string(d->id));
737 std::shared_ptr<fims_popdy::Population<Type>> p = (*it).second;
739 FIMS_INFO_LOG(
"Initializing population " + fims::to_string(p->id));
741 typename std::set<uint32_t>::iterator fleet_ids_it;
743 for (fleet_ids_it = p->fleet_ids.begin();
744 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
753 if (it != this->
fleets.end()) {
755 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
759 p->fleets.push_back(f);
763 "\" undefined, not found for Population \"" +
764 fims::to_string(p->id) +
"\". ");
783 this->n_years = std::max(this->n_years, p->n_years);
784 this->n_ages = std::max(this->n_ages, p->n_ages);
802 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> &model = (*it).second;
803 std::set<uint32_t>::iterator jt;
805 for (jt = model->population_ids.begin();
806 jt != model->population_ids.end(); ++jt) {
810 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
811 model->populations.push_back(p);
812 for (
size_t i = 0; i < p->fleets.size(); i++) {
813 model->fleets[p->fleets[i]->GetId()] = p->fleets[i];
818 fims::to_string(model->GetId()));
836 bool valid_model =
true;
915 bool valid_model =
true;
918 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> &model = (*it).second;
919 std::set<uint32_t>::iterator jt;
921 for (jt = model->population_ids.begin();
922 jt != model->population_ids.end(); ++jt) {
926 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
928 if (model->model_type_m ==
"caa") {
929 typename std::set<uint32_t>::iterator fleet_ids_it;
930 for (fleet_ids_it = p->fleet_ids.begin();
931 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
934 if (it != this->
fleets.end()) {
936 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
938 if (f->fleet_selectivity_id_m == -999) {
941 "No selectivity pattern defined for fleet " +
942 fims::to_string(f->id) +
943 ". FIMS requires selectivity be defined for all fleets "
944 "when running a catch at age model.");
949 if (p->recruitment_id == -999) {
952 "No recruitment function defined for population " +
953 fims::to_string(p->id) +
954 ". FIMS requires recruitment functions be defined for all "
955 "populations when running a catch at age model.");
958 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r =
961 if (r->process_id == -999) {
964 "No recruitment process function defined for population " +
965 fims::to_string(p->id) +
966 ". FIMS requires recruitment process functions be defined "
968 "recruitments when running a catch at age model.");
971 if (p->growth_id == -999) {
974 "No growth function defined for population " +
975 fims::to_string(p->id) +
976 ". FIMS requires growth functions be defined for all "
977 "populations when running a catch at age model.");
980 if (p->maturity_id == -999) {
984 "No maturity function defined for population " +
985 fims::to_string(p->id) +
986 ". FIMS requires maturity functions be defined for all "
987 "populations when running a catch at age model.");
997template <
typename Type>
Creates pre-processing macros such as what type of machine you are on and creates the log information...
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:598
#define FIMS_INFO_LOG(MESSAGE)
Definition def.hpp:590
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:606
Establishes the FIMS Vector class.
Definition of the FIMSObject structure.
Base class for all fleets.
Definition fleet.hpp:25
Population class. Contains subpopulations that are divided into generic partitions (e....
Definition population.hpp:25