FIMS  v0.9.3
Loading...
Searching...
No Matches
information.hpp
Go to the documentation of this file.
1
11#ifndef FIMS_COMMON_INFORMATION_HPP
12#define FIMS_COMMON_INFORMATION_HPP
13
14#include <algorithm>
15#include <map>
16#include <memory>
17#include <vector>
18
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"
26#include "fims_vector.hpp"
27#include "model_object.hpp"
28
29namespace fims_info {
30
35template <typename Type>
37 public:
38 size_t n_years = 0;
39 size_t n_ages = 0;
41 static std::shared_ptr<Information<Type>>
43 std::vector<Type*> parameters;
44 std::vector<Type*>
46 std::vector<Type*>
48 std::vector<std::string> parameter_names;
50 std::vector<std::string>
54 // data objects
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
61 // life history modules
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>>>
89 typedef
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
103 // fleet modules
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
112 // populations
113 std::map<uint32_t, std::shared_ptr<fims_popdy::Population<Type>>>
116 typedef
117 typename std::map<uint32_t,
118 std::shared_ptr<fims_popdy::Population<Type>>>::iterator
122 // distributions
123 std::map<uint32_t,
124 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>
127 typedef typename std::map<
128 uint32_t,
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
147 Information() {}
148
149 virtual ~Information() {}
150
155 void Clear() {
156 this->data_objects.clear();
157 this->populations.clear();
158 this->fixed_effects_parameters.clear();
159 this->fleets.clear();
160 this->growth_models.clear();
161 this->maturity_models.clear();
162 this->parameter_names.clear();
163 this->parameters.clear();
164 this->random_effects_names.clear();
165 this->random_effects_parameters.clear();
166 this->recruitment_models.clear();
167 this->recruitment_process_models.clear();
168 this->selectivity_models.clear();
169 this->models_map.clear();
170 this->n_years = 0;
171 this->n_ages = 0;
172
174 it != density_components.end(); ++it) {
175 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
176 (*it).second;
177 if ((d->priors)[0] != NULL) {
178 d->priors.clear();
179 }
180 if (d->data_expected_values != NULL) {
181 d->data_expected_values->clear();
182 }
183 if (d->re != NULL) {
184 d->re->clear();
185 }
186 if (d->re_expected_values != NULL) {
187 d->re_expected_values->clear();
188 }
189 }
190 this->density_components.clear();
191 }
192
202 std::string State() {
203 std::stringstream ss;
204 ss << "Information object State:\n";
205 ss << "data_objects: " << this->data_objects.clear();
206 ss << "populations: " << this->populations.size() << std::endl;
207 ss << "fixed_effects_parameters: " << this->fixed_effects_parameters.size()
208 << 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;
214 ss << "random_effects_names: " << this->random_effects_names.size()
215 << std::endl;
216 ss << "random_effects_parameters: "
217 << this->random_effects_parameters.size() << std::endl;
218 ss << "recruitment_models: " << this->recruitment_models.size()
219 << std::endl;
220 ss << "recruitment_process_models: "
221 << this->recruitment_process_models.size() << std::endl;
222 ss << "selectivity_models: " << this->selectivity_models.size()
223 << std::endl;
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;
227 ss << "density_components: " << this->density_components.size()
228 << std::endl;
229 return ss.str();
230 }
231
237 static std::shared_ptr<Information<Type>> GetInstance() {
240 std::make_shared<fims_info::Information<Type>>();
241 }
243 }
244
250 void RegisterParameter(Type& p) {
251 this->fixed_effects_parameters.push_back(&p);
252 }
253
259 void RegisterRandomEffect(Type& re) {
260 this->random_effects_parameters.push_back(&re);
261 }
262
268 void RegisterParameterName(std::string p_name) {
269 this->parameter_names.push_back(p_name);
270 }
271
277 void RegisterRandomEffectName(std::string re_name) {
278 this->random_effects_names.push_back(re_name);
279 }
280
285 void SetupPriors() {
287 it != density_components.end(); ++it) {
288 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
289 (*it).second;
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++) {
297 FIMS_INFO_LOG("Link prior from distribution " +
298 fims::to_string(d->id) + " to parameter " +
299 fims::to_string(d->key[0]));
300 vmit = this->variable_map.find(d->key[i]);
301 d->priors[i] = (*vmit).second;
302 }
303 FIMS_INFO_LOG("Prior size for distribution " + fims::to_string(d->id) +
304 "is: " + fims::to_string(d->observed_values.size()));
305 }
306 }
307 }
308
314 for (density_components_iterator it = this->density_components.begin();
315 it != this->density_components.end(); ++it) {
316 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
317 (*it).second;
318 if (d->input_type == "random_effects") {
319 FIMS_INFO_LOG("Setup random effects for distribution " +
320 fims::to_string(d->id));
322 FIMS_INFO_LOG("Link random effects from distribution " +
323 fims::to_string(d->id) + " to derived value " +
324 fims::to_string(d->key[0]));
325 vmit = this->variable_map.find(d->key[0]);
326 d->re = (*vmit).second;
327 if (d->key.size() == 2) {
328 vmit = this->variable_map.find(d->key[1]);
329 d->re_expected_values = (*vmit).second;
330 } else {
331 d->re_expected_values = &d->expected_values;
332 }
333 FIMS_INFO_LOG("Random effect size for distribution " +
334 fims::to_string(d->id) +
335 " is: " + fims::to_string(d->observed_values.size()));
336 }
337 }
338 }
339
344 void SetupData() {
345 for (density_components_iterator it = this->density_components.begin();
346 it != this->density_components.end(); ++it) {
347 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
348 (*it).second;
349 if (d->input_type == "data") {
350 FIMS_INFO_LOG("Setup expected value for data distribution " +
351 fims::to_string(d->id));
353 FIMS_INFO_LOG("Link expected value from distribution " +
354 fims::to_string(d->id) + " to derived value " +
355 fims::to_string(d->key[0]));
356 vmit = this->variable_map.find(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()));
361 }
362 }
363 }
364
372 void SetFleetLandingsData(bool& valid_model,
373 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
377 data_iterator it = this->data_objects.find(observed_landings_id);
378 if (it != this->data_objects.end()) {
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)));
383 } else {
384 valid_model = false;
385 FIMS_ERROR_LOG("Expected landings data not defined for fleet " +
386 fims::to_string(f->id) + ", index " +
387 fims::to_string(observed_landings_id));
388 }
389 }
390 }
391
399 void SetFleetIndexData(bool& valid_model,
400 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
404 data_iterator it = this->data_objects.find(observed_index_id);
405 if (it != this->data_objects.end()) {
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)));
410 } else {
411 valid_model = false;
412 FIMS_ERROR_LOG("Expected index data not defined for fleet " +
413 fims::to_string(f->id) + ", index " +
414 fims::to_string(observed_index_id));
415 }
416 }
417 }
418
426 void SetAgeCompositionData(bool& valid_model,
427 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
431 data_iterator it = this->data_objects.find(observed_agecomp_id);
432 if (it != this->data_objects.end()) {
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)));
437 } else {
438 valid_model = false;
440 "Expected age-composition observations not defined for fleet " +
441 fims::to_string(f->id));
442 }
443 }
444 }
445
453 void SetLengthCompositionData(bool& valid_model,
454 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
458 data_iterator it = this->data_objects.find(observed_lengthcomp_id);
459 if (it != this->data_objects.end()) {
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)));
464 } else {
465 valid_model = false;
467 "Expected length-composition observations not defined for fleet " +
468 fims::to_string(f->id));
469 }
470 }
471 }
472
481 void SetFleetSelectivityModel(bool& valid_model,
482 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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); // cast as unsigned integer
487 sel_id); // if find, set it, otherwise invalid
488
489 if (it != this->selectivity_models.end()) {
490 f->selectivity = (*it).second; // elements in container held in pair
491 FIMS_INFO_LOG("Selectivity model " +
492 fims::to_string(f->fleet_selectivity_id_m) +
493 " successfully set to fleet " + fims::to_string(f->id));
494 } else {
495 valid_model = false;
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));
499 }
500 } else {
501 FIMS_WARNING_LOG("Warning: No selectivity pattern defined for fleet " +
502 fims::to_string(f->id) +
503 ". FIMS requires selectivity be defined for all fleets "
504 "when running a catch at age model.");
505 }
506 }
507
516 void SetRecruitment(bool& valid_model,
517 std::shared_ptr<fims_popdy::Population<Type>> p) {
518 if (p->recruitment_id != static_cast<Type>(-999)) {
519 uint32_t recruitment_uint = static_cast<uint32_t>(p->recruitment_id);
520
522 this->recruitment_models.find(recruitment_uint);
523
524 if (it != this->recruitment_models.end()) {
525 p->recruitment = (*it).second; // recruitment defined in population.hpp
526 FIMS_INFO_LOG("Recruitment model " + fims::to_string(recruitment_uint) +
527 " successfully set to population " +
528 fims::to_string(p->id));
529 } else {
530 valid_model = false;
532 "Expected recruitment function not defined for "
533 "population " +
534 fims::to_string(p->id) + ", recruitment function " +
535 fims::to_string(recruitment_uint));
536 }
537 } else {
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.");
543 }
544 }
545
554 void SetRecruitmentProcess(bool& valid_model,
555 std::shared_ptr<fims_popdy::Population<Type>> p) {
556 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r = p->recruitment;
557 // if recruitment is defined
558 if (r) {
559 if (r->process_id != static_cast<Type>(-999)) {
560 uint32_t process_uint = static_cast<uint32_t>(r->process_id);
562 this->recruitment_process_models.find(process_uint);
563
564 if (it != this->recruitment_process_models.end()) {
565 r->process = (*it).second; // recruitment process
567 "Recruitment Process model " + fims::to_string(process_uint) +
568 " successfully set to population " + fims::to_string(p->id));
569 (*it).second->recruitment = r;
570 } else {
571 valid_model = false;
573 "Expected recruitment process function not defined for "
574 "population " +
575 fims::to_string(p->id) + ", recruitment process function " +
576 fims::to_string(process_uint));
577 }
578 } else {
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.");
584 }
585 }
586 }
587
596 void SetGrowth(bool& valid_model,
597 std::shared_ptr<fims_popdy::Population<Type>> p) {
598 if (p->growth_id != static_cast<Type>(-999)) {
599 uint32_t growth_uint = static_cast<uint32_t>(p->growth_id);
601 growth_uint); // growth_models is specified in information.hpp
602 // and used in rcpp
603 // at the head of information.hpp; are the
604 // dimensions of ages defined in rcpp or where?
605 if (it != this->growth_models.end()) {
606 p->growth =
607 (*it).second; // growth defined in population.hpp (the object
608 // is called p, growth is within p)
609 FIMS_INFO_LOG("Growth model " + fims::to_string(growth_uint) +
610 " successfully set to population " +
611 fims::to_string(p->id));
612 } else {
613 valid_model = false;
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));
617 }
618 } else {
619 FIMS_WARNING_LOG("Growth function undefined for population " +
620 fims::to_string(p->id) +
621 ". FIMS requires growth functions be defined for all "
622 "populations when running a catch at age model.");
623 }
624 }
625
634 void SetMaturity(bool& valid_model,
635 std::shared_ptr<fims_popdy::Population<Type>> p) {
636 if (p->maturity_id != static_cast<Type>(-999)) {
637 uint32_t maturity_uint = static_cast<uint32_t>(p->maturity_id);
639 maturity_uint); // >maturity_models is specified in
640 // information.hpp and used in rcpp
641 if (it != this->maturity_models.end()) {
642 p->maturity = (*it).second; // >maturity defined in population.hpp
643 FIMS_INFO_LOG("Maturity model " + fims::to_string(maturity_uint) +
644 " successfully set to population " +
645 fims::to_string(p->id));
646 } else {
647 valid_model = false;
649 "Expected maturity function not defined for population " +
650 fims::to_string(p->id) + ", maturity function " +
651 fims::to_string(maturity_uint));
652 }
653 } else {
654 FIMS_WARNING_LOG("Maturity function undefined for population " +
655 fims::to_string(p->id) +
656 ". FIMS requires maturity functions be defined for all "
657 "populations when running a catch at age model.");
658 }
659 }
660
667 void CreateFleetObjects(bool& valid_model) {
668 for (fleet_iterator it = this->fleets.begin(); it != this->fleets.end();
669 ++it) {
670 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
671 FIMS_INFO_LOG("Initializing fleet " + fims::to_string(f->id));
672
673 SetFleetLandingsData(valid_model, f);
674
675 SetFleetIndexData(valid_model, f);
676
677 SetAgeCompositionData(valid_model, f);
678
679 SetLengthCompositionData(valid_model, f);
680
681 SetFleetSelectivityModel(valid_model, f);
682 }
683 }
684
691 void SetDataObjects(bool& valid_model) {
692 for (density_components_iterator it = this->density_components.begin();
693 it != this->density_components.end(); ++it) {
694 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
695 (*it).second;
696
697 // set data objects if distribution is a data type
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);
702 data_iterator it = this->data_objects.find(observed_data_id);
703
704 if (it != this->data_objects.end()) {
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));
709 } else {
710 valid_model = false;
712 "Expected data observations not defined for density "
713 "component " +
714 fims::to_string(d->id) + ", observed data " +
715 fims::to_string(observed_data_id));
716 }
717 } else {
718 valid_model = false;
719 FIMS_ERROR_LOG("No data input for density component" +
720 fims::to_string(d->id));
721 }
722 }
723 }
724 }
725
732 void CreatePopulationObjects(bool& valid_model) {
733 for (population_iterator it = this->populations.begin();
734 it != this->populations.end(); ++it) {
735 std::shared_ptr<fims_popdy::Population<Type>> p = (*it).second;
736
737 FIMS_INFO_LOG("Initializing population " + fims::to_string(p->id));
738 // check if population has fleets
739 typename std::set<uint32_t>::iterator fleet_ids_it;
740
741 for (fleet_ids_it = p->fleet_ids.begin();
742 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
743 // error check and set population elements
744 // check me - add another fleet iterator to push information from
745 // for (fleet_iterator it = this->fleets.begin(); it !=
746 // this->fleets.end();
747 // ++it) {
748
749 fleet_iterator it = this->fleets.find(*fleet_ids_it);
750
751 if (it != this->fleets.end()) {
752 // Initialize fleet object
753 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
754 // population to the individual fleets This is to pass catch at age
755 // from population to fleets?
756 // any shared member in p (population is pushed into fleets)
757 p->fleets.push_back(f);
758 } else {
759 valid_model = false;
760 FIMS_ERROR_LOG("Fleet \"" + fims::to_string(*fleet_ids_it) +
761 "\" undefined, not found for Population \"" +
762 fims::to_string(p->id) + "\". ");
763 }
764 }
765
766 // set information dimensions
767 this->n_years = std::max(this->n_years, p->n_years);
768 this->n_ages = std::max(this->n_ages, p->n_ages);
769
770 SetRecruitment(valid_model, p);
771
772 SetRecruitmentProcess(valid_model, p);
773
774 SetGrowth(valid_model, p);
775
776 SetMaturity(valid_model, p);
777 }
778 }
779
783 void CreateModelingObjects(bool& valid_model) {
784 for (model_map_iterator it = this->models_map.begin();
785 it != this->models_map.end(); ++it) {
786 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
787 std::set<uint32_t>::iterator jt;
788
789 for (jt = model->population_ids.begin();
790 jt != model->population_ids.end(); ++jt) {
791 population_iterator pt = this->populations.find((*jt));
792
793 if (pt != this->populations.end()) {
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];
799 FIMS_INFO_LOG(std::string("Linked fleet id ") +
800 fims::to_string(local_fleet_id) +
801 std::string(" into model id ") +
802 fims::to_string(model->GetId()));
803 }
804 } else {
805 valid_model = false;
806 FIMS_ERROR_LOG("No population object defined for model " +
807 fims::to_string(model->GetId()));
808 }
809 }
810 model->Initialize();
811 }
812 }
813
824 bool CreateModel() {
825 FIMS_INFO_LOG("Creating model and checking for required components...");
826 bool valid_model = true;
827
828 CreateFleetObjects(valid_model);
829
830 SetDataObjects(valid_model);
831
832 CreatePopulationObjects(valid_model);
833
834 CreateModelingObjects(valid_model);
835
836 // setup priors, random effect, and data density components
837 SetupPriors();
839 SetupData();
840
841 if (valid_model) {
842 FIMS_INFO_LOG("Model successfully created.");
843 } else {
844 FIMS_ERROR_LOG("Model creation failed.");
845 }
846
847 return valid_model;
848 }
849
855 size_t GetNages() const { return n_ages; }
856
862 void SetNages(size_t n_ages) { this->n_ages = n_ages; }
863
869 size_t GetNyears() const { return n_years; }
870
876 void SetNyears(size_t n_years) { this->n_years = n_years; }
877
883 std::vector<Type*>& GetParameters() { return parameters; }
884
890 std::vector<Type*>& GetFixedEffectsParameters() {
892 }
893
899 std::vector<Type*>& GetRandomEffectsParameters() {
901 }
902
910 bool CheckModel() {
911 bool valid_model = true;
912 for (model_map_iterator it = this->models_map.begin();
913 it != this->models_map.end(); ++it) {
914 std::shared_ptr<fims_popdy::FisheryModelBase<Type>>& model = (*it).second;
915 std::set<uint32_t>::iterator jt;
916
917 for (jt = model->population_ids.begin();
918 jt != model->population_ids.end(); ++jt) {
919 population_iterator pt = this->populations.find((*jt));
920
921 if (pt != this->populations.end()) {
922 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
923
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) {
928 fleet_iterator it = this->fleets.find(*fleet_ids_it);
929
930 if (it != this->fleets.end()) {
931 // Initialize fleet object
932 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
933
934 if (f->fleet_selectivity_id_m == static_cast<Type>(-999)) {
935 valid_model = false;
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.");
941 }
942 }
943 }
944
945 if (p->recruitment_id == static_cast<Type>(-999)) {
946 valid_model = false;
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.");
952 }
953
954 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r =
955 p->recruitment;
956 r = p->recruitment;
957 if (r->process_id == static_cast<Type>(-999)) {
958 valid_model = false;
960 "No recruitment process function defined for population " +
961 fims::to_string(p->id) +
962 ". FIMS requires recruitment process functions be defined "
963 "for all "
964 "recruitments when running a catch at age model.");
965 }
966
967 if (p->growth_id == static_cast<Type>(-999)) {
968 valid_model = false;
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.");
974 }
975
976 if (p->maturity_id == static_cast<Type>(-999)) {
977 valid_model = false;
978
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.");
984 }
985 }
986 }
987 }
988 }
989 return valid_model;
990 }
991};
992
993template <typename Type>
994std::shared_ptr<Information<Type>> Information<Type>::fims_information =
995 nullptr;
997} // namespace fims_info
998
999#endif /* FIMS_COMMON_INFORMATION_HPP */
Stores FIMS model information and creates model. Contains all objects and data pre-model construction...
Definition information.hpp:36
std::map< uint32_t, std::shared_ptr< fims_popdy::GrowthBase< Type > > >::iterator growth_models_iterator
Definition information.hpp:92
void SetupRandomEffects()
Loop over distributions and set links to distribution x value if distribution is a random effects typ...
Definition information.hpp:313
std::map< uint32_t, std::shared_ptr< fims_popdy::Population< Type > > > populations
Definition information.hpp:114
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > > models_map
Definition information.hpp:135
void RegisterRandomEffectName(std::string re_name)
Register a random effects name.
Definition information.hpp:277
std::map< uint32_t, std::shared_ptr< fims_data_object::DataObject< Type > > >::iterator data_iterator
Definition information.hpp:59
std::vector< Type * > & GetFixedEffectsParameters()
Get the Fixed Effects Parameters object.
Definition information.hpp:890
std::vector< Type * > random_effects_parameters
Definition information.hpp:45
void SetFleetLandingsData(bool &valid_model, std::shared_ptr< fims_popdy::Fleet< Type > > f)
Set pointers to landings data in the fleet module.
Definition information.hpp:372
void SetFleetIndexData(bool &valid_model, std::shared_ptr< fims_popdy::Fleet< Type > > f)
Set pointers to index data in the fleet module.
Definition information.hpp:399
void SetGrowth(bool &valid_model, std::shared_ptr< fims_popdy::Population< Type > > p)
Set pointers to the growth module referenced in the population module.
Definition information.hpp:596
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > > recruitment_process_models
Definition information.hpp:71
void SetMaturity(bool &valid_model, std::shared_ptr< fims_popdy::Population< Type > > p)
Set pointers to the maturity module referenced in the population module.
Definition information.hpp:634
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Definition information.hpp:109
void SetDataObjects(bool &valid_model)
Loop over all density components and set pointers to data objects.
Definition information.hpp:691
size_t n_years
Definition information.hpp:38
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > > fleets
Definition information.hpp:105
void CreatePopulationObjects(bool &valid_model)
Loop over all populations and set pointers to population objects.
Definition information.hpp:732
std::map< uint32_t, std::shared_ptr< fims_popdy::GrowthBase< Type > > > growth_models
Definition information.hpp:87
void SetLengthCompositionData(bool &valid_model, std::shared_ptr< fims_popdy::Fleet< Type > > f)
Set pointers to length composition data in the fleet module.
Definition information.hpp:453
void SetFleetSelectivityModel(bool &valid_model, std::shared_ptr< fims_popdy::Fleet< Type > > f)
Set pointers to the selectivity module referenced in the fleet module.
Definition information.hpp:481
std::map< uint32_t, std::shared_ptr< fims_popdy::Population< Type > > >::iterator population_iterator
Definition information.hpp:119
void RegisterParameter(Type &p)
Register a parameter as estimable.
Definition information.hpp:250
std::map< uint32_t, std::shared_ptr< fims_distributions::DensityComponentBase< Type > > > density_components
Definition information.hpp:125
void RegisterRandomEffect(Type &re)
Register a random effect as estimable.
Definition information.hpp:259
void SetRecruitment(bool &valid_model, std::shared_ptr< fims_popdy::Population< Type > > p)
Set pointers to the recruitment module referenced in the population module.
Definition information.hpp:516
void SetNages(size_t n_ages)
Set the Nages object.
Definition information.hpp:862
size_t GetNages() const
Get the Nages object.
Definition information.hpp:855
std::unordered_map< uint32_t, fims::Vector< Type > * > variable_map
Definition information.hpp:142
void SetNyears(size_t n_years)
Set the n_years object.
Definition information.hpp:876
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > >::iterator recruitment_models_iterator
Definition information.hpp:67
void SetRecruitmentProcess(bool &valid_model, std::shared_ptr< fims_popdy::Population< Type > > p)
Set pointers to the recruitment process module referenced in the population module.
Definition information.hpp:554
bool CheckModel()
Checks to make sure all required modules are present for specified model.
Definition information.hpp:910
std::map< uint32_t, std::shared_ptr< fims_popdy::SelectivityBase< Type > > > selectivity_models
Definition information.hpp:79
bool CreateModel()
Create the generalized stock assessment model that will evaluate the objective function....
Definition information.hpp:824
void Clear()
Clears all containers.
Definition information.hpp:155
size_t n_ages
Definition information.hpp:39
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > >::iterator model_map_iterator
Definition information.hpp:139
std::map< uint32_t, std::shared_ptr< fims_distributions::DensityComponentBase< Type > > >::iterator density_components_iterator
Definition information.hpp:130
void SetAgeCompositionData(bool &valid_model, std::shared_ptr< fims_popdy::Fleet< Type > > f)
Set pointers to age composition data in the fleet module.
Definition information.hpp:426
std::vector< Type * > parameters
Definition information.hpp:43
void CreateFleetObjects(bool &valid_model)
Loop over all fleets and set pointers to fleet objects.
Definition information.hpp:667
std::vector< std::string > parameter_names
Definition information.hpp:48
std::map< uint32_t, std::shared_ptr< fims_popdy::MaturityBase< Type > > > maturity_models
Definition information.hpp:96
std::vector< Type * > & GetRandomEffectsParameters()
Get the Random Effects Parameters object.
Definition information.hpp:899
std::vector< std::string > random_effects_names
Definition information.hpp:51
std::vector< Type * > & GetParameters()
Get the Parameters object.
Definition information.hpp:883
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > >::iterator recruitment_process_iterator
Definition information.hpp:75
void SetupPriors()
Loop over distributions and set links to distribution x value if distribution is a prior type.
Definition information.hpp:285
size_t GetNyears() const
Get the n_years object.
Definition information.hpp:869
std::unordered_map< uint32_t, fims::Vector< Type > * >::iterator variable_map_iterator
Definition information.hpp:145
std::map< uint32_t, std::shared_ptr< fims_popdy::SelectivityBase< Type > > >::iterator selectivity_models_iterator
Definition information.hpp:83
void RegisterParameterName(std::string p_name)
Register a parameter name.
Definition information.hpp:268
void SetupData()
Loop over distributions and set links to distribution expected value if distribution is a data type.
Definition information.hpp:344
std::map< uint32_t, std::shared_ptr< fims_popdy::MaturityBase< Type > > >::iterator maturity_models_iterator
Definition information.hpp:100
std::string State()
Get a summary string of the Information object state.
Definition information.hpp:202
static std::shared_ptr< Information< Type > > GetInstance()
Returns a singleton Information object for type T.
Definition information.hpp:237
void CreateModelingObjects(bool &valid_model)
Loop over all models and set pointers to population objects.
Definition information.hpp:783
static std::shared_ptr< Information< Type > > fims_information
Definition information.hpp:42
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > > recruitment_models
Definition information.hpp:63
std::vector< Type * > fixed_effects_parameters
Definition information.hpp:47
std::map< uint32_t, std::shared_ptr< fims_data_object::DataObject< Type > > > data_objects
Definition information.hpp:56
#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