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();
173 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> recruitment =
175 if (recruitment->process) {
176 recruitment->process.reset();
178 if (recruitment->recruitment) {
179 recruitment->recruitment.reset();
184 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> recruitment =
186 if (recruitment->process) {
187 recruitment->process.reset();
189 if (recruitment->recruitment) {
190 recruitment->recruitment.reset();
198 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
200 if ((d->priors)[0]) {
203 if (d->data_observed_values) {
204 d->data_observed_values.reset();
206 if (d->data_expected_values) {
207 d->data_expected_values->clear();
212 if (d->re_expected_values) {
213 d->re_expected_values->clear();
229 std::stringstream ss;
230 ss <<
"Information object State:\n";
232 ss <<
"populations: " << this->
populations.size() << std::endl;
235 ss <<
"fleets: " << this->
fleets.size() << std::endl;
236 ss <<
"growth_models: " << this->
growth_models.size() << std::endl;
237 ss <<
"maturity_models: " << this->
maturity_models.size() << std::endl;
238 ss <<
"parameter_names: " << this->parameter_names.size() << std::endl;
239 ss <<
"parameters: " << this->parameters.size() << std::endl;
242 ss <<
"random_effects_parameters: "
246 ss <<
"recruitment_process_models: "
250 ss <<
"models_map: " << this->
models_map.size() << std::endl;
251 ss <<
"n_years: " << this->n_years << std::endl;
252 ss <<
"n_ages: " << this->n_ages << std::endl;
266 std::make_shared<fims_info::Information<Type>>();
295 this->parameter_names.push_back(p_name);
314 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
316 if (d->input_type ==
"prior") {
317 FIMS_INFO_LOG(
"Setup prior for distribution " + fims::to_string(d->id));
319 FIMS_INFO_LOG(
"Link prior from distribution " + fims::to_string(d->id) +
320 " to parameter " + fims::to_string(d->key[0]));
321 d->priors.resize(d->key.size());
322 for (
size_t i = 0; i < d->key.size(); i++) {
324 fims::to_string(d->id) +
" to parameter " +
325 fims::to_string(d->key[0]));
327 d->priors[i] = (*vmit).second;
329 FIMS_INFO_LOG(
"Prior size for distribution " + fims::to_string(d->id) +
330 "is: " + fims::to_string(d->observed_values.size()));
342 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
344 if (d->input_type ==
"random_effects") {
346 fims::to_string(d->id));
349 fims::to_string(d->id) +
" to derived value " +
350 fims::to_string(d->key[0]));
352 d->re = (*vmit).second;
353 if (d->key.size() == 2) {
355 d->re_expected_values = (*vmit).second;
357 d->re_expected_values = &d->expected_values;
360 fims::to_string(d->id) +
361 " is: " + fims::to_string(d->observed_values.size()));
373 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
375 if (d->input_type ==
"data") {
376 FIMS_INFO_LOG(
"Setup expected value for data distribution " +
377 fims::to_string(d->id));
380 fims::to_string(d->id) +
" to derived value " +
381 fims::to_string(d->key[0]));
383 d->data_expected_values = (*vmit).second;
385 "Expected value size for distribution " + fims::to_string(d->id) +
386 " is: " + fims::to_string((*d->data_expected_values).size()));
400 if (f->fleet_observed_landings_data_id_m !=
static_cast<Type
>(-999)) {
401 uint32_t observed_landings_id =
402 static_cast<uint32_t
>(f->fleet_observed_landings_data_id_m);
405 f->observed_landings_data = (*it).second;
406 FIMS_INFO_LOG(
"Landings data for fleet " + fims::to_string(f->id) +
407 " successfully set to " +
408 fims::to_string(f->observed_landings_data->at(1)));
412 fims::to_string(f->id) +
", index " +
413 fims::to_string(observed_landings_id));
427 if (f->fleet_observed_index_data_id_m !=
static_cast<Type
>(-999)) {
428 uint32_t observed_index_id =
429 static_cast<uint32_t
>(f->fleet_observed_index_data_id_m);
432 f->observed_index_data = (*it).second;
433 FIMS_INFO_LOG(
"Index data for fleet " + fims::to_string(f->id) +
434 " successfully set to " +
435 fims::to_string(f->observed_index_data->at(1)));
439 fims::to_string(f->id) +
", index " +
440 fims::to_string(observed_index_id));
454 if (f->fleet_observed_agecomp_data_id_m !=
static_cast<Type
>(-999)) {
455 uint32_t observed_agecomp_id =
456 static_cast<uint32_t
>(f->fleet_observed_agecomp_data_id_m);
459 f->observed_agecomp_data = (*it).second;
460 FIMS_INFO_LOG(
"Observed input age-composition data for fleet " +
461 fims::to_string(f->id) +
" successfully set to " +
462 fims::to_string(f->observed_agecomp_data->at(1)));
466 "Expected age-composition observations not defined for fleet " +
467 fims::to_string(f->id));
481 if (f->fleet_observed_lengthcomp_data_id_m !=
static_cast<Type
>(-999)) {
482 uint32_t observed_lengthcomp_id =
483 static_cast<uint32_t
>(f->fleet_observed_lengthcomp_data_id_m);
486 f->observed_lengthcomp_data = (*it).second;
487 FIMS_INFO_LOG(
"Observed input length-composition data for fleet " +
488 fims::to_string(f->id) +
" successfully set to " +
489 fims::to_string(f->observed_lengthcomp_data->at(1)));
493 "Expected length-composition observations not defined for fleet " +
494 fims::to_string(f->id));
509 if (f->fleet_selectivity_id_m !=
static_cast<Type
>(-999)) {
510 uint32_t sel_id =
static_cast<uint32_t
>(
511 f->fleet_selectivity_id_m);
516 f->selectivity = (*it).second;
518 fims::to_string(f->fleet_selectivity_id_m) +
519 " successfully set to fleet " + fims::to_string(f->id));
522 FIMS_ERROR_LOG(
"Expected selectivity pattern not defined for fleet " +
523 fims::to_string(f->id) +
", selectivity pattern " +
524 fims::to_string(sel_id));
528 fims::to_string(f->id) +
529 ". FIMS requires selectivity be defined for all fleets "
530 "when running a catch at age model.");
544 if (p->recruitment_id !=
static_cast<Type
>(-999)) {
545 uint32_t recruitment_uint =
static_cast<uint32_t
>(p->recruitment_id);
551 p->recruitment = (*it).second;
552 FIMS_INFO_LOG(
"Recruitment model " + fims::to_string(recruitment_uint) +
553 " successfully set to population " +
554 fims::to_string(p->id));
558 "Expected recruitment function not defined for "
560 fims::to_string(p->id) +
", recruitment function " +
561 fims::to_string(recruitment_uint));
565 "No recruitment function defined for population " +
566 fims::to_string(p->id) +
567 ". FIMS requires recruitment functions be defined for all "
568 "populations when running a catch at age model.");
582 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r = p->recruitment;
585 if (r->process_id !=
static_cast<Type
>(-999)) {
586 uint32_t process_uint =
static_cast<uint32_t
>(r->process_id);
591 r->process = (*it).second;
593 "Recruitment Process model " + fims::to_string(process_uint) +
594 " successfully set to population " + fims::to_string(p->id));
595 (*it).second->recruitment = r;
599 "Expected recruitment process function not defined for "
601 fims::to_string(p->id) +
", recruitment process function " +
602 fims::to_string(process_uint));
606 "No recruitment process function defined for population " +
607 fims::to_string(p->id) +
608 ". FIMS requires recruitment process functions be defined for all "
609 "recruitments when running a catch at age model.");
624 if (p->growth_id !=
static_cast<Type
>(-999)) {
625 uint32_t growth_uint =
static_cast<uint32_t
>(p->growth_id);
635 FIMS_INFO_LOG(
"Growth model " + fims::to_string(growth_uint) +
636 " successfully set to population " +
637 fims::to_string(p->id));
640 FIMS_ERROR_LOG(
"Expected growth function not defined for population " +
641 fims::to_string(p->id) +
", growth function " +
642 fims::to_string(growth_uint));
646 fims::to_string(p->id) +
647 ". FIMS requires growth functions be defined for all "
648 "populations when running a catch at age model.");
662 if (p->maturity_id !=
static_cast<Type
>(-999)) {
663 uint32_t maturity_uint =
static_cast<uint32_t
>(p->maturity_id);
668 p->maturity = (*it).second;
669 FIMS_INFO_LOG(
"Maturity model " + fims::to_string(maturity_uint) +
670 " successfully set to population " +
671 fims::to_string(p->id));
675 "Expected maturity function not defined for population " +
676 fims::to_string(p->id) +
", maturity function " +
677 fims::to_string(maturity_uint));
681 fims::to_string(p->id) +
682 ". FIMS requires maturity functions be defined for all "
683 "populations when running a catch at age model.");
696 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
697 FIMS_INFO_LOG(
"Initializing fleet " + fims::to_string(f->id));
720 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
724 if (d->input_type ==
"data") {
725 if (d->observed_data_id_m !=
static_cast<Type
>(-999)) {
726 uint32_t observed_data_id =
727 static_cast<uint32_t
>(d->observed_data_id_m);
731 d->data_observed_values = (*it).second;
732 FIMS_INFO_LOG(
"Observed data " + fims::to_string(observed_data_id) +
733 " successfully set to density component " +
734 fims::to_string(d->id));
738 "Expected data observations not defined for density "
740 fims::to_string(d->id) +
", observed data " +
741 fims::to_string(observed_data_id));
746 fims::to_string(d->id));
761 std::shared_ptr<fims_popdy::Population<Type>> p = (*it).second;
763 FIMS_INFO_LOG(
"Initializing population " + fims::to_string(p->id));
765 typename std::set<uint32_t>::iterator fleet_ids_it;
767 for (fleet_ids_it = p->fleet_ids.begin();
768 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
777 if (it != this->
fleets.end()) {
779 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
783 p->fleets.push_back(f);
787 "\" undefined, not found for Population \"" +
788 fims::to_string(p->id) +
"\". ");
793 this->n_years = std::max(this->n_years, p->n_years);
794 this->n_ages = std::max(this->n_ages, p->n_ages);
812 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
813 std::set<uint32_t>::iterator jt;
815 for (jt = model->population_ids.begin();
816 jt != model->population_ids.end(); ++jt) {
820 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
821 model->populations.push_back(p);
822 for (
size_t i = 0; i < p->fleets.size(); i++) {
823 uint32_t local_fleet_id = p->fleets[i]->GetId();
824 model->fleets[local_fleet_id] = p->fleets[i];
826 fims::to_string(local_fleet_id) +
827 std::string(
" into model id ") +
828 fims::to_string(model->GetId()));
833 fims::to_string(model->GetId()));
851 FIMS_INFO_LOG(
"Creating model and checking for required components...");
852 bool valid_model =
true;
937 bool valid_model =
true;
940 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
941 std::set<uint32_t>::iterator jt;
943 for (jt = model->population_ids.begin();
944 jt != model->population_ids.end(); ++jt) {
948 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
950 if (model->model_type_m ==
"caa") {
951 typename std::set<uint32_t>::iterator fleet_ids_it;
952 for (fleet_ids_it = p->fleet_ids.begin();
953 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
956 if (it != this->
fleets.end()) {
958 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
960 if (f->fleet_selectivity_id_m ==
static_cast<Type
>(-999)) {
963 "No selectivity pattern defined for fleet " +
964 fims::to_string(f->id) +
965 ". FIMS requires selectivity be defined for all fleets "
966 "when running a catch at age model.");
971 if (p->recruitment_id ==
static_cast<Type
>(-999)) {
974 "No recruitment function defined for population " +
975 fims::to_string(p->id) +
976 ". FIMS requires recruitment functions be defined for all "
977 "populations when running a catch at age model.");
980 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r =
983 if (r->process_id ==
static_cast<Type
>(-999)) {
986 "No recruitment process function defined for population " +
987 fims::to_string(p->id) +
988 ". FIMS requires recruitment process functions be defined "
990 "recruitments when running a catch at age model.");
993 if (p->growth_id ==
static_cast<Type
>(-999)) {
996 "No growth function defined for population " +
997 fims::to_string(p->id) +
998 ". FIMS requires growth functions be defined for all "
999 "populations when running a catch at age model.");
1002 if (p->maturity_id ==
static_cast<Type
>(-999)) {
1003 valid_model =
false;
1006 "No maturity function defined for population " +
1007 fims::to_string(p->id) +
1008 ". FIMS requires maturity functions be defined for all "
1009 "populations when running a catch at age model.");
1019template <
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