FIMS  v0.8.0
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 <map>
15#include <memory>
16#include <vector>
17#include <algorithm>
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 "def.hpp"
27#include "fims_vector.hpp"
28#include "model_object.hpp"
29
30namespace fims_info {
31
36template <typename Type>
38 public:
39 size_t n_years = 0;
40 size_t n_ages = 0;
42 static std::shared_ptr<Information<Type>>
44 std::vector<Type *> parameters;
45 std::vector<Type *>
47 std::vector<Type *>
49 std::vector<std::string> parameter_names;
51 std::vector<std::string>
55 // data objects
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
62 // life history modules
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>>>
90 typedef
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
104 // fleet modules
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
113 // populations
114 std::map<uint32_t, std::shared_ptr<fims_popdy::Population<Type>>>
117 typedef
118 typename std::map<uint32_t,
119 std::shared_ptr<fims_popdy::Population<Type>>>::iterator
123 // distributions
124 std::map<uint32_t,
125 std::shared_ptr<fims_distributions::DensityComponentBase<Type>>>
128 typedef typename std::map<
129 uint32_t,
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
148 Information() {}
149
150 virtual ~Information() {}
151
156 void Clear() {
157 this->data_objects.clear();
158 this->populations.clear();
159 this->fixed_effects_parameters.clear();
160 this->fleets.clear();
161 this->growth_models.clear();
162 this->maturity_models.clear();
163 this->parameter_names.clear();
164 this->parameters.clear();
165 this->random_effects_names.clear();
166 this->random_effects_parameters.clear();
167 this->recruitment_models.clear();
168 this->recruitment_process_models.clear();
169 this->selectivity_models.clear();
170 this->models_map.clear();
171 this->n_years = 0;
172 this->n_ages = 0;
173
175 it != density_components.end(); ++it) {
176 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
177 (*it).second;
178 if ((d->priors)[0] != NULL) {
179 d->priors.clear();
180 }
181 if (d->data_expected_values != NULL) {
182 d->data_expected_values->clear();
183 }
184 if (d->re != NULL) {
185 d->re->clear();
186 }
187 if (d->re_expected_values != NULL) {
188 d->re_expected_values->clear();
189 }
190 }
191 this->density_components.clear();
192 }
193
203 std::string State() {
204 std::stringstream ss;
205 ss << "Information object State:\n";
206 ss << "data_objects: " << this->data_objects.clear();
207 ss << "populations: " << this->populations.size() << std::endl;
208 ss << "fixed_effects_parameters: " << this->fixed_effects_parameters.size()
209 << 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;
215 ss << "random_effects_names: " << this->random_effects_names.size()
216 << std::endl;
217 ss << "random_effects_parameters: "
218 << this->random_effects_parameters.size() << std::endl;
219 ss << "recruitment_models: " << this->recruitment_models.size()
220 << std::endl;
221 ss << "recruitment_process_models: "
222 << this->recruitment_process_models.size() << std::endl;
223 ss << "selectivity_models: " << this->selectivity_models.size()
224 << std::endl;
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;
228 ss << "density_components: " << this->density_components.size()
229 << std::endl;
230 return ss.str();
231 }
232
238 static std::shared_ptr<Information<Type>> GetInstance() {
241 std::make_shared<fims_info::Information<Type>>();
242 }
244 }
245
251 void RegisterParameter(Type &p) {
252 this->fixed_effects_parameters.push_back(&p);
253 }
254
260 void RegisterRandomEffect(Type &re) {
261 this->random_effects_parameters.push_back(&re);
262 }
263
269 void RegisterParameterName(std::string p_name) {
270 this->parameter_names.push_back(p_name);
271 }
272
278 void RegisterRandomEffectName(std::string re_name) {
279 this->random_effects_names.push_back(re_name);
280 }
281
286 void SetupPriors() {
288 it != density_components.end(); ++it) {
289 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
290 (*it).second;
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++) {
298 FIMS_INFO_LOG("Link prior from distribution " +
299 fims::to_string(d->id) + " to parameter " +
300 fims::to_string(d->key[0]));
301 vmit = this->variable_map.find(d->key[i]);
302 d->priors[i] = (*vmit).second;
303 }
304 FIMS_INFO_LOG("Prior size for distribution " + fims::to_string(d->id) +
305 "is: " + fims::to_string(d->x.size()));
306 }
307 }
308 }
309
315 for (density_components_iterator it = this->density_components.begin();
316 it != this->density_components.end(); ++it) {
317 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
318 (*it).second;
319 if (d->input_type == "random_effects") {
320 FIMS_INFO_LOG("Setup random effects for distribution " +
321 fims::to_string(d->id));
323 FIMS_INFO_LOG("Link random effects from distribution " +
324 fims::to_string(d->id) + " to derived value " +
325 fims::to_string(d->key[0]));
326 vmit = this->variable_map.find(d->key[0]);
327 d->re = (*vmit).second;
328 if (d->key.size() == 2) {
329 vmit = this->variable_map.find(d->key[1]);
330 d->re_expected_values = (*vmit).second;
331 } else {
332 d->re_expected_values = &d->expected_values;
333 }
334 FIMS_INFO_LOG("Random effect size for distribution " +
335 fims::to_string(d->id) +
336 " is: " + fims::to_string(d->x.size()));
337 }
338 }
339 }
340
345 void SetupData() {
346 for (density_components_iterator it = this->density_components.begin();
347 it != this->density_components.end(); ++it) {
348 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
349 (*it).second;
350 if (d->input_type == "data") {
351 FIMS_INFO_LOG("Setup expected value for data distribution " +
352 fims::to_string(d->id));
354 FIMS_INFO_LOG("Link expected value from distribution " +
355 fims::to_string(d->id) + " to derived value " +
356 fims::to_string(d->key[0]));
357 vmit = this->variable_map.find(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()));
362 }
363 }
364 }
365
373 void SetFleetLandingsData(bool &valid_model,
374 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
378 data_iterator it = this->data_objects.find(observed_landings_id);
379 if (it != this->data_objects.end()) {
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)));
384 } else {
385 valid_model = false;
386 FIMS_ERROR_LOG("Expected landings data not defined for fleet " +
387 fims::to_string(f->id) + ", index " +
388 fims::to_string(observed_landings_id));
389 }
390 }
391 }
392
400 void SetFleetIndexData(bool &valid_model,
401 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
405 data_iterator it = this->data_objects.find(observed_index_id);
406 if (it != this->data_objects.end()) {
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)));
411 } else {
412 valid_model = false;
413 FIMS_ERROR_LOG("Expected index data not defined for fleet " +
414 fims::to_string(f->id) + ", index " +
415 fims::to_string(observed_index_id));
416 }
417 }
418 }
419
427 void SetAgeCompositionData(bool &valid_model,
428 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
432 data_iterator it = this->data_objects.find(observed_agecomp_id);
433 if (it != this->data_objects.end()) {
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)));
438 } else {
439 valid_model = false;
441 "Expected age-composition observations not defined for fleet " +
442 fims::to_string(f->id));
443 }
444 }
445 }
446
454 void SetLengthCompositionData(bool &valid_model,
455 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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);
459 data_iterator it = this->data_objects.find(observed_lengthcomp_id);
460 if (it != this->data_objects.end()) {
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)));
465 } else {
466 valid_model = false;
468 "Expected length-composition observations not defined for fleet " +
469 fims::to_string(f->id));
470 }
471 }
472 }
473
482 void SetFleetSelectivityModel(bool &valid_model,
483 std::shared_ptr<fims_popdy::Fleet<Type>> f) {
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); // cast as unsigned integer
488 sel_id); // if find, set it, otherwise invalid
489
490 if (it != this->selectivity_models.end()) {
491 f->selectivity = (*it).second; // elements in container held in pair
492 FIMS_INFO_LOG("Selectivity model " +
493 fims::to_string(f->fleet_selectivity_id_m) +
494 " successfully set to fleet " + fims::to_string(f->id));
495 } else {
496 valid_model = false;
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));
500 }
501 } else {
502 FIMS_WARNING_LOG("Warning: No selectivity pattern defined for fleet " +
503 fims::to_string(f->id) +
504 ". FIMS requires selectivity be defined for all fleets "
505 "when running a catch at age model.");
506 }
507 }
508
517 void SetRecruitment(bool &valid_model,
518 std::shared_ptr<fims_popdy::Population<Type>> p) {
519 if (p->recruitment_id != static_cast<Type>(-999)) {
520 uint32_t recruitment_uint = static_cast<uint32_t>(p->recruitment_id);
521 FIMS_INFO_LOG("searching for recruitment model " +
522 fims::to_string(recruitment_uint));
524 this->recruitment_models.find(recruitment_uint);
525
526 if (it != this->recruitment_models.end()) {
527 p->recruitment = (*it).second; // recruitment defined in population.hpp
528 FIMS_INFO_LOG("Recruitment model " + fims::to_string(recruitment_uint) +
529 " successfully set to population " +
530 fims::to_string(p->id));
531 } else {
532 valid_model = false;
534 "Expected recruitment function not defined for "
535 "population " +
536 fims::to_string(p->id) + ", recruitment function " +
537 fims::to_string(recruitment_uint));
538 }
539 } else {
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.");
545 }
546 }
547
556 void SetRecruitmentProcess(bool &valid_model,
557 std::shared_ptr<fims_popdy::Population<Type>> p) {
558 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r = p->recruitment;
559 // if recruitment is defined
560 if (r) {
561 if (r->process_id != -999) {
562 uint32_t process_uint = static_cast<uint32_t>(r->process_id);
564 this->recruitment_process_models.find(process_uint);
565
566 if (it != this->recruitment_process_models.end()) {
567 r->process = (*it).second; // recruitment process
569 "Recruitment Process model " + fims::to_string(process_uint) +
570 " successfully set to population " + fims::to_string(p->id));
571 (*it).second->recruitment = r;
572 } else {
573 valid_model = false;
575 "Expected recruitment process function not defined for "
576 "population " +
577 fims::to_string(p->id) + ", recruitment process function " +
578 fims::to_string(process_uint));
579 }
580 } else {
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.");
586 }
587 }
588 }
589
598 void SetGrowth(bool &valid_model,
599 std::shared_ptr<fims_popdy::Population<Type>> p) {
600 if (p->growth_id != static_cast<Type>(-999)) {
601 uint32_t growth_uint = static_cast<uint32_t>(p->growth_id);
603 growth_uint); // growth_models is specified in information.hpp
604 // and used in rcpp
605 // at the head of information.hpp; are the
606 // dimensions of ages defined in rcpp or where?
607 if (it != this->growth_models.end()) {
608 p->growth =
609 (*it).second; // growth defined in population.hpp (the object
610 // is called p, growth is within p)
611 FIMS_INFO_LOG("Growth model " + fims::to_string(growth_uint) +
612 " successfully set to population " +
613 fims::to_string(p->id));
614 } else {
615 valid_model = false;
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));
619 }
620 } else {
621 FIMS_WARNING_LOG("No growth function defined for population " +
622 fims::to_string(p->id) +
623 ". FIMS requires growth functions be defined for all "
624 "populations when running a catch at age model.");
625 }
626 }
627
636 void SetMaturity(bool &valid_model,
637 std::shared_ptr<fims_popdy::Population<Type>> p) {
638 if (p->maturity_id != static_cast<Type>(-999)) {
639 uint32_t maturity_uint = static_cast<uint32_t>(p->maturity_id);
641 maturity_uint); // >maturity_models is specified in
642 // information.hpp and used in rcpp
643 if (it != this->maturity_models.end()) {
644 p->maturity = (*it).second; // >maturity defined in population.hpp
645 FIMS_INFO_LOG("Maturity model " + fims::to_string(maturity_uint) +
646 " successfully set to population " +
647 fims::to_string(p->id));
648 } else {
649 valid_model = false;
651 "Expected maturity function not defined for population " +
652 fims::to_string(p->id) + ", maturity function " +
653 fims::to_string(maturity_uint));
654 }
655 } else {
656 FIMS_WARNING_LOG("No maturity function defined for population " +
657 fims::to_string(p->id) +
658 ". FIMS requires maturity functions be defined for all "
659 "populations when running a catch at age model.");
660 }
661 }
662
669 void CreateFleetObjects(bool &valid_model) {
670 for (fleet_iterator it = this->fleets.begin(); it != this->fleets.end();
671 ++it) {
672 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
673 FIMS_INFO_LOG("Initializing fleet " + fims::to_string(f->id));
674
675 SetFleetLandingsData(valid_model, f);
676
677 SetFleetIndexData(valid_model, f);
678
679 SetAgeCompositionData(valid_model, f);
680
681 SetLengthCompositionData(valid_model, f);
682
683 SetFleetSelectivityModel(valid_model, f);
684 }
685 }
686
693 void SetDataObjects(bool &valid_model) {
694 for (density_components_iterator it = this->density_components.begin();
695 it != this->density_components.end(); ++it) {
696 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
697 (*it).second;
698
699 // set data objects if distribution is a data type
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);
704 data_iterator it = this->data_objects.find(observed_data_id);
705
706 if (it != this->data_objects.end()) {
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));
711 } else {
712 valid_model = false;
714 "Expected data observations not defined for density "
715 "component " +
716 fims::to_string(d->id) + ", observed data " +
717 fims::to_string(observed_data_id));
718 }
719 } else {
720 valid_model = false;
721 FIMS_ERROR_LOG("No data input for density component" +
722 fims::to_string(d->id));
723 }
724 }
725 }
726 }
727
734 void CreatePopulationObjects(bool &valid_model) {
735 for (population_iterator it = this->populations.begin();
736 it != this->populations.end(); ++it) {
737 std::shared_ptr<fims_popdy::Population<Type>> p = (*it).second;
738
739 FIMS_INFO_LOG("Initializing population " + fims::to_string(p->id));
740 // check if population has fleets
741 typename std::set<uint32_t>::iterator fleet_ids_it;
742
743 for (fleet_ids_it = p->fleet_ids.begin();
744 fleet_ids_it != p->fleet_ids.end(); ++fleet_ids_it) {
745 // error check and set population elements
746 // check me - add another fleet iterator to push information from
747 // for (fleet_iterator it = this->fleets.begin(); it !=
748 // this->fleets.end();
749 // ++it) {
750
751 fleet_iterator it = this->fleets.find(*fleet_ids_it);
752
753 if (it != this->fleets.end()) {
754 // Initialize fleet object
755 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
756 // population to the individual fleets This is to pass catch at age
757 // from population to fleets?
758 // any shared member in p (population is pushed into fleets)
759 p->fleets.push_back(f);
760 } else {
761 valid_model = false;
762 FIMS_ERROR_LOG("Fleet \"" + fims::to_string(*fleet_ids_it) +
763 "\" undefined, not found for Population \"" +
764 fims::to_string(p->id) + "\". ");
765 }
766 // // error check and set population elements
767 // // check me - add another fleet iterator to push information from
768 // for (fleet_iterator it = this->fleets.begin(); it !=
769 // this->fleets.end();
770 // ++it)
771 // {
772 // // Initialize fleet object
773 // std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
774 // // population to the individual fleets This is to pass landings
775 // at age
776 // // from population to fleets?
777 // // any shared member in p (population is pushed into fleets)
778 // p->fleets.push_back(f);
779 // }
780 }
781
782 // set information dimensions
783 this->n_years = std::max(this->n_years, p->n_years);
784 this->n_ages = std::max(this->n_ages, p->n_ages);
785
786 SetRecruitment(valid_model, p);
787
788 SetRecruitmentProcess(valid_model, p);
789
790 SetGrowth(valid_model, p);
791
792 SetMaturity(valid_model, p);
793 }
794 }
795
799 void CreateModelingObjects(bool &valid_model) {
800 for (model_map_iterator it = this->models_map.begin();
801 it != this->models_map.end(); ++it) {
802 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> &model = (*it).second;
803 std::set<uint32_t>::iterator jt;
804
805 for (jt = model->population_ids.begin();
806 jt != model->population_ids.end(); ++jt) {
807 population_iterator pt = this->populations.find((*jt));
808
809 if (pt != this->populations.end()) {
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];
814 }
815 } else {
816 valid_model = false;
817 FIMS_ERROR_LOG("No population object defined for model " +
818 fims::to_string(model->GetId()));
819 }
820 }
821 model->Initialize();
822 }
823 }
824
835 bool CreateModel() {
836 bool valid_model = true;
837
838 CreateFleetObjects(valid_model);
839
840 SetDataObjects(valid_model);
841
842 CreatePopulationObjects(valid_model);
843
844 CreateModelingObjects(valid_model);
845
846 // setup priors, random effect, and data density components
847 SetupPriors();
849 SetupData();
850
851 return valid_model;
852 }
853
859 size_t GetNages() const { return n_ages; }
860
866 void SetNages(size_t n_ages) { this->n_ages = n_ages; }
867
873 size_t GetNyears() const { return n_years; }
874
880 void SetNyears(size_t n_years) { this->n_years = n_years; }
881
887 std::vector<Type *> &GetParameters() { return parameters; }
888
894 std::vector<Type *> &GetFixedEffectsParameters() {
896 }
897
903 std::vector<Type *> &GetRandomEffectsParameters() {
905 }
906
914 bool CheckModel() {
915 bool valid_model = true;
916 for (model_map_iterator it = this->models_map.begin();
917 it != this->models_map.end(); ++it) {
918 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> &model = (*it).second;
919 std::set<uint32_t>::iterator jt;
920
921 for (jt = model->population_ids.begin();
922 jt != model->population_ids.end(); ++jt) {
923 population_iterator pt = this->populations.find((*jt));
924
925 if (pt != this->populations.end()) {
926 std::shared_ptr<fims_popdy::Population<Type>> p = (*pt).second;
927
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) {
932 fleet_iterator it = this->fleets.find(*fleet_ids_it);
933
934 if (it != this->fleets.end()) {
935 // Initialize fleet object
936 std::shared_ptr<fims_popdy::Fleet<Type>> f = (*it).second;
937
938 if (f->fleet_selectivity_id_m == -999) {
939 valid_model = false;
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.");
945 }
946 }
947 }
948
949 if (p->recruitment_id == -999) {
950 valid_model = false;
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.");
956 }
957
958 std::shared_ptr<fims_popdy::RecruitmentBase<Type>> r =
959 p->recruitment;
960 r = p->recruitment;
961 if (r->process_id == -999) {
962 valid_model = false;
964 "No recruitment process function defined for population " +
965 fims::to_string(p->id) +
966 ". FIMS requires recruitment process functions be defined "
967 "for all "
968 "recruitments when running a catch at age model.");
969 }
970
971 if (p->growth_id == -999) {
972 valid_model = false;
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.");
978 }
979
980 if (p->maturity_id == -999) {
981 valid_model = false;
982
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.");
988 }
989 }
990 }
991 }
992 }
993 return valid_model;
994 }
995};
996
997template <typename Type>
998std::shared_ptr<Information<Type>> Information<Type>::fims_information =
999 nullptr; // singleton instance
1000
1001} // namespace fims_info
1002
1003#endif /* FIMS_COMMON_INFORMATION_HPP */
Stores FIMS model information and creates model. Contains all objects and data pre-model construction...
Definition information.hpp:37
std::map< uint32_t, std::shared_ptr< fims_popdy::GrowthBase< Type > > >::iterator growth_models_iterator
Definition information.hpp:93
void SetupRandomEffects()
Loop over distributions and set links to distribution x value if distribution is a random effects typ...
Definition information.hpp:314
std::map< uint32_t, std::shared_ptr< fims_popdy::Population< Type > > > populations
Definition information.hpp:115
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > > models_map
Definition information.hpp:136
void RegisterRandomEffectName(std::string re_name)
Register a random effects name.
Definition information.hpp:278
std::map< uint32_t, std::shared_ptr< fims_data_object::DataObject< Type > > >::iterator data_iterator
Definition information.hpp:60
std::vector< Type * > & GetFixedEffectsParameters()
Get the Fixed Effects Parameters object.
Definition information.hpp:894
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:373
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:400
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:598
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > > recruitment_process_models
Definition information.hpp:72
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:636
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Definition information.hpp:110
void SetDataObjects(bool &valid_model)
Loop over all density components and set pointers to data objects.
Definition information.hpp:693
size_t n_years
Definition information.hpp:39
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > > fleets
Definition information.hpp:106
void CreatePopulationObjects(bool &valid_model)
Loop over all populations and set pointers to population objects.
Definition information.hpp:734
std::vector< Type * > parameters
Definition information.hpp:44
std::map< uint32_t, std::shared_ptr< fims_popdy::GrowthBase< Type > > > growth_models
Definition information.hpp:88
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:454
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:482
std::map< uint32_t, std::shared_ptr< fims_popdy::Population< Type > > >::iterator population_iterator
Definition information.hpp:120
void RegisterParameter(Type &p)
Register a parameter as estimable.
Definition information.hpp:251
std::map< uint32_t, std::shared_ptr< fims_distributions::DensityComponentBase< Type > > > density_components
Definition information.hpp:126
void RegisterRandomEffect(Type &re)
Register a random effect as estimable.
Definition information.hpp:260
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:517
void SetNages(size_t n_ages)
Set the Nages object.
Definition information.hpp:866
size_t GetNages() const
Get the Nages object.
Definition information.hpp:859
void SetNyears(size_t n_years)
Set the n_years object.
Definition information.hpp:880
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > >::iterator recruitment_models_iterator
Definition information.hpp:68
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:556
bool CheckModel()
Checks to make sure all required modules are present for specified model.
Definition information.hpp:914
std::map< uint32_t, std::shared_ptr< fims_popdy::SelectivityBase< Type > > > selectivity_models
Definition information.hpp:80
bool CreateModel()
Create the generalized stock assessment model that will evaluate the objective function....
Definition information.hpp:835
void Clear()
Clears all containers.
Definition information.hpp:156
size_t n_ages
Definition information.hpp:40
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > >::iterator model_map_iterator
Definition information.hpp:140
std::unordered_map< uint32_t, fims::Vector< Type > * > variable_map
Definition information.hpp:143
std::map< uint32_t, std::shared_ptr< fims_distributions::DensityComponentBase< Type > > >::iterator density_components_iterator
Definition information.hpp:131
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:427
void CreateFleetObjects(bool &valid_model)
Loop over all fleets and set pointers to fleet objects.
Definition information.hpp:669
std::vector< std::string > parameter_names
Definition information.hpp:49
std::map< uint32_t, std::shared_ptr< fims_popdy::MaturityBase< Type > > > maturity_models
Definition information.hpp:97
std::vector< Type * > & GetRandomEffectsParameters()
Get the Random Effects Parameters object.
Definition information.hpp:903
std::vector< std::string > random_effects_names
Definition information.hpp:52
std::vector< Type * > & GetParameters()
Get the Parameters object.
Definition information.hpp:887
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > >::iterator recruitment_process_iterator
Definition information.hpp:76
void SetupPriors()
Loop over distributions and set links to distribution x value if distribution is a prior type.
Definition information.hpp:286
size_t GetNyears() const
Get the n_years object.
Definition information.hpp:873
std::unordered_map< uint32_t, fims::Vector< Type > * >::iterator variable_map_iterator
Definition information.hpp:146
std::vector< Type * > fixed_effects_parameters
Definition information.hpp:48
std::map< uint32_t, std::shared_ptr< fims_popdy::SelectivityBase< Type > > >::iterator selectivity_models_iterator
Definition information.hpp:84
void RegisterParameterName(std::string p_name)
Register a parameter name.
Definition information.hpp:269
void SetupData()
Loop over distributions and set links to distribution expected value if distribution is a data type.
Definition information.hpp:345
std::map< uint32_t, std::shared_ptr< fims_popdy::MaturityBase< Type > > >::iterator maturity_models_iterator
Definition information.hpp:101
std::string State()
Get a summary string of the Information object state.
Definition information.hpp:203
static std::shared_ptr< Information< Type > > GetInstance()
Returns a singleton Information object for type T.
Definition information.hpp:238
void CreateModelingObjects(bool &valid_model)
Loop over all models and set pointers to population objects.
Definition information.hpp:799
static std::shared_ptr< Information< Type > > fims_information
Definition information.hpp:43
std::vector< Type * > random_effects_parameters
Definition information.hpp:46
std::map< uint32_t, std::shared_ptr< fims_popdy::RecruitmentBase< Type > > > recruitment_models
Definition information.hpp:64
std::map< uint32_t, std::shared_ptr< fims_data_object::DataObject< Type > > > data_objects
Definition information.hpp:57
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