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"
35template <
typename Type>
41 static std::shared_ptr<Information<Type>>
50 std::vector<std::string>
55 std::map<uint32_t, std::shared_ptr<fims_data_object::DataObject<Type>>>
57 typedef typename std::map<
58 uint32_t, std::shared_ptr<fims_data_object::DataObject<Type>>>::iterator
62 std::map<uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>
65 typedef typename std::map<
66 uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>::iterator
70 std::map<uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>
73 typedef typename std::map<
74 uint32_t, std::shared_ptr<fims_popdy::RecruitmentBase<Type>>>::iterator
78 std::map<uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type>>>
81 typedef typename std::map<
82 uint32_t, std::shared_ptr<fims_popdy::SelectivityBase<Type>>>::iterator
86 std::map<uint32_t, std::shared_ptr<fims_popdy::GrowthBase<Type>>>
90 typename std::map<uint32_t,
91 std::shared_ptr<fims_popdy::GrowthBase<Type>>>::iterator
95 std::map<uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type>>>
98 typedef typename std::map<
99 uint32_t, std::shared_ptr<fims_popdy::MaturityBase<Type>>>::iterator
104 std::map<uint32_t, std::shared_ptr<fims_popdy::Fleet<Type>>>
107 typedef typename std::map<uint32_t,
108 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
113 std::map<uint32_t, std::shared_ptr<fims_popdy::Population<Type>>>
117 typename std::map<uint32_t,
118 std::shared_ptr<fims_popdy::Population<Type>>>::iterator
124 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>
127 typedef typename std::map<
129 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>::iterator
133 std::unordered_map<uint32_t,
134 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>>
137 typedef typename std::unordered_map<
138 uint32_t, std::shared_ptr<fims_popdy::FisheryModelBase<Type>>>::iterator
141 std::unordered_map<uint32_t, fims::Vector<Type>*>
144 typedef typename std::unordered_map<uint32_t, fims::Vector<Type>*>::iterator
162 this->parameter_names.clear();
163 this->parameters.clear();
175 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
177 if ((d->priors)[0] != NULL) {
180 if (d->data_expected_values != NULL) {
181 d->data_expected_values->clear();
186 if (d->re_expected_values != NULL) {
187 d->re_expected_values->clear();
203 std::stringstream ss;
204 ss <<
"Information object State:\n";
206 ss <<
"populations: " << this->
populations.size() << std::endl;
209 ss <<
"fleets: " << this->
fleets.size() << std::endl;
210 ss <<
"growth_models: " << this->
growth_models.size() << std::endl;
211 ss <<
"maturity_models: " << this->
maturity_models.size() << std::endl;
212 ss <<
"parameter_names: " << this->parameter_names.size() << std::endl;
213 ss <<
"parameters: " << this->parameters.size() << std::endl;
216 ss <<
"random_effects_parameters: "
220 ss <<
"recruitment_process_models: "
224 ss <<
"models_map: " << this->
models_map.size() << std::endl;
225 ss <<
"n_years: " << this->n_years << std::endl;
226 ss <<
"n_ages: " << this->n_ages << std::endl;
240 std::make_shared<fims_info::Information<Type>>();
269 this->parameter_names.push_back(p_name);
288 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
290 if (d->input_type ==
"prior") {
291 FIMS_INFO_LOG(
"Setup prior for distribution " + fims::to_string(d->id));
293 FIMS_INFO_LOG(
"Link prior from distribution " + fims::to_string(d->id) +
294 " to parameter " + fims::to_string(d->key[0]));
295 d->priors.resize(d->key.size());
296 for (
size_t i = 0; i < d->key.size(); i++) {
298 fims::to_string(d->id) +
" to parameter " +
299 fims::to_string(d->key[0]));
301 d->priors[i] = (*vmit).second;
303 FIMS_INFO_LOG(
"Prior size for distribution " + fims::to_string(d->id) +
304 "is: " + fims::to_string(d->observed_values.size()));
316 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
318 if (d->input_type ==
"random_effects") {
320 fims::to_string(d->id));
323 fims::to_string(d->id) +
" to derived value " +
324 fims::to_string(d->key[0]));
326 d->re = (*vmit).second;
327 if (d->key.size() == 2) {
329 d->re_expected_values = (*vmit).second;
331 d->re_expected_values = &d->expected_values;
334 fims::to_string(d->id) +
335 " is: " + fims::to_string(d->observed_values.size()));
347 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
349 if (d->input_type ==
"data") {
350 FIMS_INFO_LOG(
"Setup expected value for data distribution " +
351 fims::to_string(d->id));
354 fims::to_string(d->id) +
" to derived value " +
355 fims::to_string(d->key[0]));
357 d->data_expected_values = (*vmit).second;
359 "Expected value size for distribution " + fims::to_string(d->id) +
360 " is: " + fims::to_string((*d->data_expected_values).size()));
374 if (f->fleet_observed_landings_data_id_m !=
static_cast<Type
>(-999)) {
375 uint32_t observed_landings_id =
376 static_cast<uint32_t
>(f->fleet_observed_landings_data_id_m);
379 f->observed_landings_data = (*it).second;
380 FIMS_INFO_LOG(
"Landings data for fleet " + fims::to_string(f->id) +
381 " successfully set to " +
382 fims::to_string(f->observed_landings_data->at(1)));
386 fims::to_string(f->id) +
", index " +
387 fims::to_string(observed_landings_id));
401 if (f->fleet_observed_index_data_id_m !=
static_cast<Type
>(-999)) {
402 uint32_t observed_index_id =
403 static_cast<uint32_t
>(f->fleet_observed_index_data_id_m);
406 f->observed_index_data = (*it).second;
407 FIMS_INFO_LOG(
"Index data for fleet " + fims::to_string(f->id) +
408 " successfully set to " +
409 fims::to_string(f->observed_index_data->at(1)));
413 fims::to_string(f->id) +
", index " +
414 fims::to_string(observed_index_id));
428 if (f->fleet_observed_agecomp_data_id_m !=
static_cast<Type
>(-999)) {
429 uint32_t observed_agecomp_id =
430 static_cast<uint32_t
>(f->fleet_observed_agecomp_data_id_m);
433 f->observed_agecomp_data = (*it).second;
434 FIMS_INFO_LOG(
"Observed input age-composition data for fleet " +
435 fims::to_string(f->id) +
" successfully set to " +
436 fims::to_string(f->observed_agecomp_data->at(1)));
440 "Expected age-composition observations not defined for fleet " +
441 fims::to_string(f->id));
455 if (f->fleet_observed_lengthcomp_data_id_m !=
static_cast<Type
>(-999)) {
456 uint32_t observed_lengthcomp_id =
457 static_cast<uint32_t
>(f->fleet_observed_lengthcomp_data_id_m);
460 f->observed_lengthcomp_data = (*it).second;
461 FIMS_INFO_LOG(
"Observed input length-composition data for fleet " +
462 fims::to_string(f->id) +
" successfully set to " +
463 fims::to_string(f->observed_lengthcomp_data->at(1)));
467 "Expected length-composition observations not defined for fleet " +
468 fims::to_string(f->id));
483 if (f->fleet_selectivity_id_m !=
static_cast<Type
>(-999)) {
484 uint32_t sel_id =
static_cast<uint32_t
>(
485 f->fleet_selectivity_id_m);
490 f->selectivity = (*it).second;
492 fims::to_string(f->fleet_selectivity_id_m) +
493 " successfully set to fleet " + fims::to_string(f->id));
496 FIMS_ERROR_LOG(
"Expected selectivity pattern not defined for fleet " +
497 fims::to_string(f->id) +
", selectivity pattern " +
498 fims::to_string(sel_id));
502 fims::to_string(f->id) +
503 ". FIMS requires selectivity be defined for all fleets "
504 "when running a catch at age model.");
518 if (p->recruitment_id !=
static_cast<Type
>(-999)) {
519 uint32_t recruitment_uint =
static_cast<uint32_t
>(p->recruitment_id);
525 p->recruitment = (*it).second;
526 FIMS_INFO_LOG(
"Recruitment model " + fims::to_string(recruitment_uint) +
527 " successfully set to population " +
528 fims::to_string(p->id));
532 "Expected recruitment function not defined for "
534 fims::to_string(p->id) +
", recruitment function " +
535 fims::to_string(recruitment_uint));
539 "No recruitment function defined for population " +
540 fims::to_string(p->id) +
541 ". FIMS requires recruitment functions be defined for all "
542 "populations when running a catch at age model.");
556 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r = p->recruitment;
559 if (r->process_id !=
static_cast<Type
>(-999)) {
560 uint32_t process_uint =
static_cast<uint32_t
>(r->process_id);
565 r->process = (*it).second;
567 "Recruitment Process model " + fims::to_string(process_uint) +
568 " successfully set to population " + fims::to_string(p->id));
569 (*it).second->recruitment = r;
573 "Expected recruitment process function not defined for "
575 fims::to_string(p->id) +
", recruitment process function " +
576 fims::to_string(process_uint));
580 "No recruitment process function defined for population " +
581 fims::to_string(p->id) +
582 ". FIMS requires recruitment process functions be defined for all "
583 "recruitments when running a catch at age model.");
598 if (p->growth_id !=
static_cast<Type
>(-999)) {
599 uint32_t growth_uint =
static_cast<uint32_t
>(p->growth_id);
609 FIMS_INFO_LOG(
"Growth model " + fims::to_string(growth_uint) +
610 " successfully set to population " +
611 fims::to_string(p->id));
614 FIMS_ERROR_LOG(
"Expected growth function not defined for population " +
615 fims::to_string(p->id) +
", growth function " +
616 fims::to_string(growth_uint));
620 fims::to_string(p->id) +
621 ". FIMS requires growth functions be defined for all "
622 "populations when running a catch at age model.");
636 if (p->maturity_id !=
static_cast<Type
>(-999)) {
637 uint32_t maturity_uint =
static_cast<uint32_t
>(p->maturity_id);
642 p->maturity = (*it).second;
643 FIMS_INFO_LOG(
"Maturity model " + fims::to_string(maturity_uint) +
644 " successfully set to population " +
645 fims::to_string(p->id));
649 "Expected maturity function not defined for population " +
650 fims::to_string(p->id) +
", maturity function " +
651 fims::to_string(maturity_uint));
655 fims::to_string(p->id) +
656 ". FIMS requires maturity functions be defined for all "
657 "populations when running a catch at age model.");
670 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
671 FIMS_INFO_LOG(
"Initializing fleet " + fims::to_string(f->id));
694 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
698 if (d->input_type ==
"data") {
699 if (d->observed_data_id_m !=
static_cast<Type
>(-999)) {
700 uint32_t observed_data_id =
701 static_cast<uint32_t
>(d->observed_data_id_m);
705 d->data_observed_values = (*it).second;
706 FIMS_INFO_LOG(
"Observed data " + fims::to_string(observed_data_id) +
707 " successfully set to density component " +
708 fims::to_string(d->id));
712 "Expected data observations not defined for density "
714 fims::to_string(d->id) +
", observed data " +
715 fims::to_string(observed_data_id));
720 fims::to_string(d->id));
735 std::shared_ptr<fims_popdy::Population<Type>> p = (*it).second;
737 FIMS_INFO_LOG(
"Initializing population " + fims::to_string(p->id));
739 typename std::set<uint32_t>::iterator fleet_ids_it;
741 for (fleet_ids_it = p->fleet_ids.begin();
742 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
751 if (it != this->
fleets.end()) {
753 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
757 p->fleets.push_back(f);
761 "\" undefined, not found for Population \"" +
762 fims::to_string(p->id) +
"\". ");
767 this->n_years = std::max(this->n_years, p->n_years);
768 this->n_ages = std::max(this->n_ages, p->n_ages);
786 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
787 std::set<uint32_t>::iterator jt;
789 for (jt = model->population_ids.begin();
790 jt != model->population_ids.end(); ++jt) {
794 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
795 model->populations.push_back(p);
796 for (
size_t i = 0; i < p->fleets.size(); i++) {
797 uint32_t local_fleet_id = p->fleets[i]->GetId();
798 model->fleets[local_fleet_id] = p->fleets[i];
800 fims::to_string(local_fleet_id) +
801 std::string(
" into model id ") +
802 fims::to_string(model->GetId()));
807 fims::to_string(model->GetId()));
825 FIMS_INFO_LOG(
"Creating model and checking for required components...");
826 bool valid_model =
true;
911 bool valid_model =
true;
914 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
915 std::set<uint32_t>::iterator jt;
917 for (jt = model->population_ids.begin();
918 jt != model->population_ids.end(); ++jt) {
922 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
924 if (model->model_type_m ==
"caa") {
925 typename std::set<uint32_t>::iterator fleet_ids_it;
926 for (fleet_ids_it = p->fleet_ids.begin();
927 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
930 if (it != this->
fleets.end()) {
932 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
934 if (f->fleet_selectivity_id_m ==
static_cast<Type
>(-999)) {
937 "No selectivity pattern defined for fleet " +
938 fims::to_string(f->id) +
939 ". FIMS requires selectivity be defined for all fleets "
940 "when running a catch at age model.");
945 if (p->recruitment_id ==
static_cast<Type
>(-999)) {
948 "No recruitment function defined for population " +
949 fims::to_string(p->id) +
950 ". FIMS requires recruitment functions be defined for all "
951 "populations when running a catch at age model.");
954 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r =
957 if (r->process_id ==
static_cast<Type
>(-999)) {
960 "No recruitment process function defined for population " +
961 fims::to_string(p->id) +
962 ". FIMS requires recruitment process functions be defined "
964 "recruitments when running a catch at age model.");
967 if (p->growth_id ==
static_cast<Type
>(-999)) {
970 "No growth function defined for population " +
971 fims::to_string(p->id) +
972 ". FIMS requires growth functions be defined for all "
973 "populations when running a catch at age model.");
976 if (p->maturity_id ==
static_cast<Type
>(-999)) {
980 "No maturity function defined for population " +
981 fims::to_string(p->id) +
982 ". FIMS requires maturity functions be defined for all "
983 "populations when running a catch at age model.");
993template <
typename Type>
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
#define FIMS_INFO_LOG(MESSAGE)
Record an info-log entry with metadata.
Definition def.hpp:636
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
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