FIMS  v0.9.3
Loading...
Searching...
No Matches
rcpp_models.hpp
Go to the documentation of this file.
1
9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_MODELS_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_MODELS_HPP
11
12#include <set>
13#include "common/def.hpp"
15#include "../../../models/fisheries_models.hpp"
16#include "common/model.hpp"
17#include "../../../utilities/fims_json.hpp"
18#include "rcpp_population.hpp"
19#include "rcpp_fleet.hpp"
20#include "rcpp_growth.hpp"
21#include "rcpp_distribution.hpp"
22#include "rcpp_data.hpp"
23#include "rcpp_maturity.hpp"
24#include "rcpp_recruitment.hpp"
25#include "rcpp_selectivity.hpp"
26#include <valarray>
27#include <cmath>
28#include <mutex>
29
37 protected:
41 std::shared_ptr<std::set<uint32_t>> population_ids;
45 typedef typename std::set<uint32_t>::iterator population_id_iterator;
46
47 public:
51 static uint32_t id_g;
61 static std::map<uint32_t, std::shared_ptr<FisheryModelInterfaceBase>>
63
69 this->population_ids = std::make_shared<std::set<uint32_t>>();
70 /* Create instance of map: key is id and value is pointer to
71 FleetInterfaceBase */
72 // FisheryModelInterfaceBase::live_objects[this->id] = this;
73 }
74
82
87
101 virtual std::string to_json() {
102 return "std::string to_json() not yet implemented.";
103 }
104
108 virtual uint32_t get_id() = 0;
109
117 Rcpp::NumericVector get_fixed_parameters_vector() {
118 std::shared_ptr<fims_info::Information<double>> info0 =
120
121 Rcpp::NumericVector p;
122
123 for (size_t i = 0; i < info0->fixed_effects_parameters.size(); i++) {
124 p.push_back(*info0->fixed_effects_parameters[i]);
125 }
126
127 return p;
128 }
129
137 Rcpp::NumericVector get_random_parameters_vector() {
138 std::shared_ptr<fims_info::Information<double>> d0 =
140
141 Rcpp::NumericVector p;
142
143 for (size_t i = 0; i < d0->random_effects_parameters.size(); i++) {
144 p.push_back(*d0->random_effects_parameters[i]);
145 }
146
147 return p;
148 }
149
156 double sum(const std::valarray<double> &v) {
157 double sum = 0.0;
158 for (size_t i = 0; i < v.size(); i++) {
159 sum += v[i];
160 }
161 return sum;
162 }
163
170 double sum(const std::vector<double> &v) {
171 double sum = 0.0;
172 for (size_t i = 0; i < v.size(); i++) {
173 sum += v[i];
174 }
175 return sum;
176 }
177
185 double min(const std::valarray<double> &v) {
186 double min_value = v[0];
187 for (size_t i = 1; i < v.size(); i++) {
188 if (v[i] < min_value) {
189 min_value = v[i];
190 }
191 }
192 return min_value;
193 }
194
203 std::valarray<double> fabs(const std::valarray<double> &v) {
204 std::valarray<double> result(v.size());
205 for (size_t i = 0; i < v.size(); i++) {
206 result[i] = std::fabs(v[i]);
207 }
208 return result;
209 }
210};
211
217 public:
222 std::shared_ptr<CatchAtAgeInterface> caa =
223 std::make_shared<CatchAtAgeInterface>(*this);
226 }
227
235
240 this->population_ids->insert(id);
241
242 std::map<uint32_t, std::shared_ptr<PopulationInterfaceBase>>::iterator pit;
245 std::shared_ptr<PopulationInterfaceBase> &pop = (*pit).second;
246 pop->initialize_catch_at_age.set(true);
247 } else {
248 FIMS_ERROR_LOG("Population with id " + fims::to_string(id) +
249 " not found.");
250 }
251 }
252
260 void DoReporting(bool report) {
261#ifdef TMB_MODEL
262 std::shared_ptr<fims_info::Information<double>> info =
265 model_it = info->models_map.find(this->get_id());
266 if (model_it != info->models_map.end()) {
267 std::shared_ptr<fims_popdy::CatchAtAge<double>> model_ptr =
268 std::dynamic_pointer_cast<fims_popdy::CatchAtAge<double>>(
269 (*model_it).second);
270 model_ptr->do_reporting = report;
271 }
272#endif
273 }
274
282 bool IsReporting() {
283#ifdef TMB_MODEL
284 std::shared_ptr<fims_info::Information<double>> info =
287 model_it = info->models_map.find(this->get_id());
288 if (model_it != info->models_map.end()) {
289 std::shared_ptr<fims_popdy::CatchAtAge<double>> model_ptr =
290 std::dynamic_pointer_cast<fims_popdy::CatchAtAge<double>>(
291 (*model_it).second);
292 return model_ptr->do_reporting;
293 }
294 return false;
295#else
296 return false;
297#endif
298 }
299
303 virtual uint32_t get_id() { return this->id; }
304
308 virtual void finalize() {}
309
314 std::stringstream ss;
315
316 typename std::map<uint32_t,
317 std::shared_ptr<PopulationInterfaceBase>>::iterator
318 pi_it; // population interface iterator
320 population_interface->get_id());
322 FIMS_ERROR_LOG("Population with id " +
323 fims::to_string(population_interface->get_id()) +
324 " not found in live objects.");
325 return "{}"; // Return empty JSON
326 }
327
328 std::shared_ptr<PopulationInterface> population_interface_ptr =
329 std::dynamic_pointer_cast<PopulationInterface>((*pi_it).second);
330
331 std::shared_ptr<fims_info::Information<double>> info =
333
335 model_it = info->models_map.find(this->get_id());
336 std::shared_ptr<fims_popdy::CatchAtAge<double>> model_ptr =
337 std::dynamic_pointer_cast<fims_popdy::CatchAtAge<double>>(
338 (*model_it).second);
339
341
342 pit = info->populations.find(population_interface->get_id());
343
344 if (pit != info->populations.end()) {
345 std::shared_ptr<fims_popdy::Population<double>> &pop = (*pit).second;
346 ss << "{\n";
347
348 ss << " \"module_name\": \"Population\",\n";
349 ss << " \"population\": \"" << population_interface->name << "\",\n";
350 ss << " \"module_id\": " << population_interface->id << ",\n";
351 ss << " \"recruitment_id\": " << population_interface->recruitment_id
352 << ",\n";
353 ss << " \"growth_id\": " << population_interface->growth_id << ",\n";
354 ss << " \"maturity_id\": " << population_interface->maturity_id << ",\n";
355
356 ss << " \"parameters\": [\n";
357 for (size_t i = 0; i < pop->log_M.size(); i++) {
358 population_interface_ptr->log_M[i].final_value_m = pop->log_M[i];
359 }
360
361 ss << "{\n \"name\": \"log_M\",\n";
362 ss << " \"id\":" << population_interface->log_M.id_m << ",\n";
363 ss << " \"type\": \"vector\",\n";
364 ss << " \"dimensionality\": {\n";
365 ss << " \"header\": [" << "\"n_years\", \"n_ages\"" << "],\n";
366 ss << " \"dimensions\": [" << population_interface->n_years.get() << ", "
367 << population_interface->n_ages.get() << "]\n},\n";
368 ss << " \"values\": " << population_interface->log_M << "\n\n";
369 ss << "},\n";
370
371 for (size_t i = 0; i < pop->log_f_multiplier.size(); i++) {
372 population_interface_ptr->log_f_multiplier[i].final_value_m =
373 pop->log_f_multiplier[i];
374 }
375
376 ss << "{\n \"name\": \"log_f_multiplier\",\n";
377 ss << " \"id\":" << population_interface->log_f_multiplier.id_m << ",\n";
378 ss << " \"type\": \"vector\",\n";
379 ss << " \"dimensionality\": {\n";
380 ss << " \"header\": [" << "\"n_years\"" << "],\n";
381 ss << " \"dimensions\": [" << population_interface->n_years.get()
382 << "]\n},\n";
383 ss << " \"values\": " << population_interface->log_f_multiplier << "\n\n";
384 ss << "},\n";
385
386 for (size_t i = 0; i < pop->spawning_biomass_ratio.size(); i++) {
387 population_interface_ptr->spawning_biomass_ratio[i].final_value_m =
388 pop->spawning_biomass_ratio[i];
389 }
390
391 ss << "{\n \"name\": \"spawning_biomass_ratio\",\n";
392 ss << " \"id\":" << population_interface->spawning_biomass_ratio.id_m
393 << ",\n";
394 ss << " \"type\": \"vector\",\n";
395 ss << " \"dimensionality\": {\n";
396 ss << " \"header\": [" << "\"n_years\"" << "],\n";
397 ss << " \"dimensions\": [" << (population_interface->n_years.get() + 1)
398 << "]\n},\n";
399 ss << " \"values\": " << population_interface->spawning_biomass_ratio
400 << "\n\n";
401 ss << "},\n";
402
403 for (size_t i = 0; i < pop->log_init_naa.size(); i++) {
404 population_interface_ptr->log_init_naa[i].final_value_m =
405 pop->log_init_naa[i];
406 }
407 ss << " {\n\"name\": \"log_init_naa\",\n";
408 ss << " \"id\":" << population_interface->log_init_naa.id_m << ",\n";
409 ss << " \"type\": \"vector\",\n";
410 ss << " \"dimensionality\": {\n";
411 ss << " \"header\": [" << "\"n_ages\"" << "],\n";
412 ss << " \"dimensions\": [" << population_interface->n_ages.get()
413 << "]\n},\n";
414
415 ss << " \"values\":" << population_interface->log_init_naa << "\n";
416 ss << "},\n";
417
418 for (size_t i = 0; i < population_interface->proportion_female.size();
419 i++) {
420 population_interface_ptr->proportion_female[i].final_value_m =
421 pop->proportion_female.get_force_scalar(i);
422 }
423 ss << " {\n\"name\": \"proportion_female\",\n";
424 ss << " \"id\":" << population_interface->proportion_female.id_m
425 << ",\n";
426 ss << " \"type\": \"vector\",\n";
427 ss << " \"dimensionality\": {\n";
428 ss << " \"header\": [" << "\"n_ages\"" << "],\n";
429 ss << " \"dimensions\": ["
430 << population_interface->proportion_female.size() << "]\n},\n";
431
432 ss << " \"values\":" << population_interface->proportion_female << "\n";
433 ss << "}],\n";
434
435 ss << " \"derived_quantities\": [\n";
436
437 std::map<std::string, fims::Vector<double>> dqs =
438 model_ptr->GetPopulationDerivedQuantities(
439 population_interface->get_id());
440
441 std::map<std::string, fims_popdy::DimensionInfo> dim_info =
442 model_ptr->GetPopulationDimensionInfo(population_interface->get_id());
444 << " ]}\n";
445 } else {
446 ss << "{\n";
447 ss << " \"name\": \"Population\",\n";
448
449 ss << " \"type\": \"population\",\n";
450 ss << " \"tag\": \"" << population_interface->get_id()
451 << " not found in Information.\",\n";
452 ss << " \"id\": " << population_interface->get_id() << ",\n";
453 ss << " \"recruitment_id\": " << population_interface->recruitment_id
454 << ",\n";
455 ss << " \"growth_id\": " << population_interface->growth_id << ",\n";
456 ss << " \"maturity_id\": " << population_interface->maturity_id << ",\n";
457 ss << " \"derived_quantities\": []}\n";
458 }
459
460 return ss.str();
461 }
462
469 std::map<std::string, fims::Vector<double>>::iterator it,
471 std::stringstream ss;
472 fims::Vector<double> &dq = (*it).second;
473 std::stringstream dim_entry;
474 // gather dimension information
475 switch (dim_info.ndims) {
476 case 1:
477 dim_entry << "\"dimensionality\": {\n";
478 dim_entry << " \"header\": [\"" << dim_info.dim_names[0] << "\"],\n";
479 dim_entry << " \"dimensions\": [";
480 for (size_t i = 0; i < dim_info.dims.size(); ++i) {
481 if (i > 0) dim_entry << ", ";
482 dim_entry << dim_info.dims[i];
483 }
484 dim_entry << "]\n";
485 dim_entry << "}";
486 break;
487 case 2:
488 dim_entry << "\"dimensionality\": {\n";
489 dim_entry << " \"header\": [\"" << dim_info.dim_names[0] << "\", \""
490 << dim_info.dim_names[1] << "\"],\n";
491 dim_entry << " \"dimensions\": [";
492 for (size_t i = 0; i < dim_info.dims.size(); ++i) {
493 if (i > 0) dim_entry << ", ";
494 dim_entry << dim_info.dims[i];
495 }
496 dim_entry << "]\n";
497 dim_entry << "}";
498 break;
499 case 3:
500 dim_entry << "\"dimensionality\": {\n";
501 dim_entry << " \"header\": [\"" << dim_info.dim_names[0] << "\", \""
502 << dim_info.dim_names[1] << "\", \"" << dim_info.dim_names[2]
503 << "\"],\n";
504 dim_entry << " \"dimensions\": [";
505 for (size_t i = 0; i < dim_info.dims.size(); ++i) {
506 if (i > 0) dim_entry << ", ";
507 dim_entry << dim_info.dims[i];
508 }
509 dim_entry << "]\n";
510 dim_entry << "}";
511 break;
512 default:
513 dim_entry << "\"dimensionality\": {\n";
514 dim_entry << " \"header\": [],\n";
515 dim_entry << " \"dimensions\": []\n";
516 dim_entry << "}";
517 break;
518 }
519
520 // build JSON string
521 ss << "{\n";
522 ss << "\"name\":\"" << (*it).first << "\",\n";
523 ss << dim_entry.str() << ",\n";
524 ss << "\"value\":[";
525 ss << std::fixed << std::setprecision(10);
526 if (dq.size() > 0) {
527 for (size_t i = 0; i < dq.size() - 1; i++) {
528 if (dq[i] != dq[i]) // check for NaN
529 {
530 ss << "-999" << ", ";
531 } else {
532 ss << dq[i] << ", ";
533 }
534 }
535 if (dq[dq.size() - 1] != dq[dq.size() - 1]) // check for NaN
536 {
537 ss << "-999]" << "\n";
538 } else {
539 ss << dq[dq.size() - 1] << "]\n";
540 }
541 } else {
542 ss << "]\n";
543 }
544 ss << "}";
545
546 return ss.str();
547 }
548
554 std::map<std::string, fims::Vector<double>> &dqs,
555 std::map<std::string, fims_popdy::DimensionInfo> &dim_info) {
556 std::stringstream ss;
557 std::map<std::string, fims_popdy::DimensionInfo>::iterator dim_info_it;
558 std::map<std::string, fims::Vector<double>>::iterator it;
559 std::map<std::string, fims::Vector<double>>::iterator end_it;
560 end_it = dqs.end();
561 typename std::map<std::string, fims::Vector<double>>::iterator
563 second_to_last = dqs.end();
564 if (it != end_it) {
566 }
567
568 it = dqs.begin();
569 for (; it != second_to_last; ++it) {
570 dim_info_it = dim_info.find(it->first);
571 ss << this->derived_quantity_to_json(it, dim_info_it->second) << ",\n";
572 }
573
574 dim_info_it = dim_info.find(second_to_last->first);
575 if (dim_info_it != dim_info.end()) {
576 ss << this->derived_quantity_to_json(second_to_last, dim_info_it->second)
577 << "\n";
578 } else {
579 ss << "{}";
580 // Handle case where dimension info is not found
581 }
582 return ss.str();
583 }
584
589 std::stringstream ss;
590
591 if (!fleet_interface) {
593 "Fleet pointer is null; cannot get id. Not found in live objects.");
594 return "{}"; // Return empty JSON
595 }
596
597 std::shared_ptr<fims_info::Information<double>> info =
599
601 model_it = info->models_map.find(this->get_id());
602 std::shared_ptr<fims_popdy::CatchAtAge<double>> model_ptr =
603 std::dynamic_pointer_cast<fims_popdy::CatchAtAge<double>>(
604 (*model_it).second);
605
607
608 fit = info->fleets.find(fleet_interface->get_id());
609
610 if (fit != info->fleets.end()) {
611 std::shared_ptr<fims_popdy::Fleet<double>> &fleet = (*fit).second;
612
613 ss << "{\n";
614 ss << " \"module_name\": \"Fleet\",\n";
615 ss << " \"fleet\": \"" << fleet_interface->name << "\",\n";
616 ss << " \"module_id\": " << fleet_interface->id << ",\n";
617 ss << " \"n_ages\": " << fleet_interface->n_ages.get() << ",\n";
618 ss << " \"n_years\": " << fleet_interface->n_years.get() << ",\n";
619 ss << " \"n_lengths\": " << fleet_interface->n_lengths.get() << ",\n";
620 ss << "\"data_ids\" : [\n";
621 ss << "{\"agecomp\": " << fleet_interface->GetObservedAgeCompDataID()
622 << "},\n";
623 ss << "{\"lengthcomp\": "
624 << fleet_interface->GetObservedLengthCompDataID() << "},\n";
625 ss << "{\"index\": " << fleet_interface->GetObservedIndexDataID()
626 << "},\n";
627 ss << "{\"landings\": " << fleet_interface->GetObservedLandingsDataID()
628 << "}\n";
629 ss << "],\n";
630 ss << "\"parameters\": [\n";
631 ss << "{\n";
632 for (size_t i = 0; i < fleet_interface->log_Fmort.size(); i++) {
633 fleet_interface->log_Fmort[i].final_value_m = fleet->log_Fmort[i];
634 }
635
636 ss << " \"name\": \"log_Fmort\",\n";
637 ss << " \"id\":" << fleet_interface->log_Fmort.id_m << ",\n";
638 ss << " \"type\": \"vector\",\n";
639 ss << " \"dimensionality\": {\n";
640 ss << " \"header\": [\"" << "n_years" << "\"],\n";
641 ss << " \"dimensions\": [" << fleet_interface->n_years.get()
642 << "]\n},\n";
643 ss << " \"values\": " << fleet_interface->log_Fmort << "},\n";
644
645 ss << " {\n";
646 for (size_t i = 0; i < fleet->log_q.size(); i++) {
647 fleet_interface->log_q[i].final_value_m = fleet->log_q[i];
648 }
649 ss << " \"name\": \"log_q\",\n";
650 ss << " \"id\":" << fleet_interface->log_q.id_m << ",\n";
651 ss << " \"type\": \"vector\",\n";
652 ss << " \"dimensionality\": {\n";
653 ss << " \"header\": [\"" << "na" << "\"],\n";
654 ss << " \"dimensions\": [" << fleet->log_q.size() << "]\n},\n";
655
656 ss << " \"values\": " << fleet_interface->log_q << "}\n";
657
658 ss << "], \"derived_quantities\": [";
659
660 std::map<std::string, fims::Vector<double>> dqs =
661 model_ptr->GetFleetDerivedQuantities(fleet_interface->get_id());
662 std::map<std::string, fims_popdy::DimensionInfo> dim_info =
663 model_ptr->GetFleetDimensionInfo(fleet_interface->get_id());
664 ss << this->derived_quantities_component_to_json(dqs, dim_info) << "]}\n";
665 } else {
666 ss << "{\n";
667 ss << " \"name\": \"Fleet\",\n";
668 ss << " \"type\": \"fleet\",\n";
669 ss << " \"tag\": \"" << fleet_interface->get_id()
670 << " not found in Information.\",\n";
671 ss << " \"derived_quantities\": []}\n";
672 }
673 return ss.str();
674 }
675
679 virtual std::string to_json() {
680 std::set<uint32_t> recruitment_ids;
681 std::set<uint32_t> growth_ids;
682 std::set<uint32_t> maturity_ids;
683 std::set<uint32_t> selectivity_ids;
684 std::set<uint32_t> fleet_ids;
685 // gather sub-module info from population and fleets
686 typename std::set<uint32_t>::iterator module_id_it; // generic
687 typename std::set<uint32_t>::iterator pit;
688 typename std::set<uint32_t>::iterator fids;
689 for (pit = this->population_ids->begin();
690 pit != this->population_ids->end(); pit++) {
691 std::shared_ptr<PopulationInterface> population_interface =
692 std::dynamic_pointer_cast<PopulationInterface>(
695 recruitment_ids.insert(population_interface->recruitment_id.get());
696 growth_ids.insert(population_interface->growth_id.get());
697 maturity_ids.insert(population_interface->maturity_id.get());
698
699 for (fids = population_interface->fleet_ids->begin();
700 fids != population_interface->fleet_ids->end(); fids++) {
701 fleet_ids.insert(*fids);
702 }
703 }
704 }
705
706 for (fids = fleet_ids.begin(); fids != fleet_ids.end(); fids++) {
707 std::shared_ptr<FleetInterface> fleet_interface =
708 std::dynamic_pointer_cast<FleetInterface>(
710 if (fleet_interface) {
711 selectivity_ids.insert(fleet_interface->GetSelectivityID());
712 }
713 }
714
715 std::shared_ptr<fims_info::Information<double>> info =
717
718 std::shared_ptr<fims_popdy::CatchAtAge<double>> model =
719 std::dynamic_pointer_cast<fims_popdy::CatchAtAge<double>>(
720 info->models_map[this->get_id()]);
721
722 std::shared_ptr<fims_model::Model<double>> model_internal =
724
725#ifdef TMB_MODEL
726 model->do_reporting = false;
727#endif
728
729 double value = model_internal->Evaluate();
730
731 std::stringstream ss;
732
733 ss.str("");
734
735 ss << "{\n";
736 ss << " \"name\": \"CatchAtAge\",\n";
737 ss << " \"type\": \"model\",\n";
738 ss << " \"estimation_framework\": ";
739#ifdef TMB_MODEL
740 ss << "\"Template_Model_Builder (TMB)\",";
741#else
742 ss << "\"FIMS\",";
743#endif
744 ss << " \"id\": " << this->get_id() << ",\n";
745 ss << " \"objective_function_value\": " << sanitize_val(value) << ",\n";
746 ss << "\"growth\":[\n";
747 for (module_id_it = growth_ids.begin(); module_id_it != growth_ids.end();
748 module_id_it++) {
749 std::shared_ptr<GrowthInterfaceBase> growth_interface =
751
752 if (growth_interface != NULL) {
753 growth_interface->finalize();
754 ss << growth_interface->to_json();
755 if (std::next(module_id_it) != growth_ids.end()) {
756 ss << ", ";
757 }
758 }
759 }
760
761 ss << "],\n";
762
763 ss << "\"recruitment\": [\n";
764 for (module_id_it = recruitment_ids.begin();
766 std::shared_ptr<RecruitmentInterfaceBase> recruitment_interface =
769 recruitment_interface->finalize();
770 ss << recruitment_interface->to_json();
771 if (std::next(module_id_it) != recruitment_ids.end()) {
772 ss << ", ";
773 }
774 }
775 }
776 ss << "],\n";
777
778 ss << "\"maturity\": [\n";
779 for (module_id_it = maturity_ids.begin();
781 std::shared_ptr<MaturityInterfaceBase> maturity_interface =
783 if (maturity_interface) {
784 maturity_interface->finalize();
785 ss << maturity_interface->to_json();
786 if (std::next(module_id_it) != maturity_ids.end()) {
787 ss << ", ";
788 }
789 }
790 }
791 ss << "],\n";
792
793 ss << "\"selectivity\": [\n";
794 for (module_id_it = selectivity_ids.begin();
796 std::shared_ptr<SelectivityInterfaceBase> selectivity_interface =
799 selectivity_interface->finalize();
800 ss << selectivity_interface->to_json();
801 if (std::next(module_id_it) != selectivity_ids.end()) {
802 ss << ", ";
803 }
804 }
805 }
806 ss << "],\n";
807
808 ss << " \"population_ids\": [";
809 for (pit = this->population_ids->begin();
810 pit != this->population_ids->end(); pit++) {
811 ss << *pit;
812 if (std::next(pit) != this->population_ids->end()) {
813 ss << ", ";
814 }
815 }
816 ss << "],\n";
817 ss << " \"fleet_ids\": [";
818
819 for (fids = fleet_ids.begin(); fids != fleet_ids.end(); fids++) {
820 ss << *fids;
821 if (std::next(fids) != fleet_ids.end()) {
822 ss << ", ";
823 }
824 }
825 ss << "],\n";
826 ss << "\"populations\": [\n";
827 typename std::set<uint32_t>::iterator pop_it;
828 typename std::set<uint32_t>::iterator pop_end_it;
829 pop_end_it = this->population_ids->end();
830 typename std::set<uint32_t>::iterator pop_second_to_last_it;
831 if (pop_end_it != this->population_ids->begin()) {
832 pop_second_to_last_it = std::prev(pop_end_it);
833 } else {
835 }
836 for (pop_it = this->population_ids->begin();
837 pop_it != pop_second_to_last_it; pop_it++) {
838 std::shared_ptr<PopulationInterface> population_interface =
839 std::dynamic_pointer_cast<PopulationInterface>(
842 std::set<uint32_t>::iterator fids;
843 for (fids = population_interface->fleet_ids->begin();
844 fids != population_interface->fleet_ids->end(); fids++) {
845 fleet_ids.insert(*fids);
846 }
847 population_interface->finalize();
848 ss << this->population_to_json(population_interface.get()) << ",";
849 } else {
850 FIMS_ERROR_LOG("Population with id " + fims::to_string(*pop_it) +
851 " not found in live objects.");
852 ss << "{}"; // Return empty JSON for this population
853 }
854 }
855
856 std::shared_ptr<PopulationInterface> population_interface =
857 std::dynamic_pointer_cast<PopulationInterface>(
860 std::set<uint32_t>::iterator fids;
861 for (fids = population_interface->fleet_ids->begin();
862 fids != population_interface->fleet_ids->end(); fids++) {
863 fleet_ids.insert(*fids);
864 }
865 ss << this->population_to_json(population_interface.get());
866 } else {
867 FIMS_ERROR_LOG("Population with id " + fims::to_string(*pop_it) +
868 " not found in live objects.");
869 ss << "{}"; // Return empty JSON for this population
870 }
871
872 ss << "]";
873 ss << ",\n";
874 ss << "\"fleets\": [\n";
875
876 typename std::set<uint32_t>::iterator fleet_it;
877 typename std::set<uint32_t>::iterator fleet_end_it;
878 fleet_end_it = fleet_ids.end();
879 typename std::set<uint32_t>::iterator fleet_second_to_last_it;
880
881 if (fleet_end_it != fleet_ids.begin()) {
883 }
884 for (fleet_it = fleet_ids.begin(); fleet_it != fleet_second_to_last_it;
885 fleet_it++) {
886 std::shared_ptr<FleetInterface> fleet_interface =
887 std::dynamic_pointer_cast<FleetInterface>(
889 if (fleet_interface) {
890 fleet_interface->finalize();
891 ss << this->fleet_to_json(fleet_interface.get()) << ",";
892 } else {
893 FIMS_ERROR_LOG("Fleet with id " + fims::to_string(*fleet_it) +
894 " not found in live objects.");
895 ss << "{}"; // Return empty JSON for this fleet
896 }
897 }
898 std::shared_ptr<FleetInterface> fleet_interface =
899 std::dynamic_pointer_cast<FleetInterface>(
901 if (fleet_interface) {
902 ss << this->fleet_to_json(fleet_interface.get());
903 } else {
904 FIMS_ERROR_LOG("Fleet with id " + fims::to_string(*fleet_it) +
905 " not found in live objects.");
906 ss << "{}"; // Return empty JSON for this fleet
907 }
908
909 ss << "],\n";
910
911 ss << "\"density_components\": [\n";
912
913 typename std::map<
914 uint32_t, std::shared_ptr<DistributionsInterfaceBase>>::iterator dit;
917 std::shared_ptr<DistributionsInterfaceBase> dist_interface =
918 (*dit).second;
919 if (dist_interface) {
920 dist_interface->finalize();
921 ss << dist_interface->to_json();
922 if (std::next(dit) != DistributionsInterfaceBase::live_objects.end()) {
923 ss << ",\n";
924 }
925 }
926 }
927 ss << "\n],\n";
928 ss << "\"data\": [\n";
929 typename std::map<uint32_t, std::shared_ptr<DataInterfaceBase>>::iterator
930 d_it;
933 std::shared_ptr<DataInterfaceBase> data_interface = (*d_it).second;
934 if (data_interface) {
935 data_interface->finalize();
936 ss << data_interface->to_json();
937 if (std::next(d_it) != DataInterfaceBase::live_objects.end()) {
938 ss << ",\n";
939 }
940 }
941 }
942 ss << "\n]\n";
943 ss << "}\n";
944#ifdef TMB_MODEL
945 model->do_reporting = true;
946#endif
948 }
949
950#ifdef TMB_MODEL
951
952 template <typename Type>
954 std::shared_ptr<fims_info::Information<Type>> info =
956
957 std::shared_ptr<fims_popdy::CatchAtAge<Type>> model =
958 std::make_shared<fims_popdy::CatchAtAge<Type>>();
959
961
962 for (it = this->population_ids->begin(); it != this->population_ids->end();
963 ++it) {
964 model->AddPopulation((*it));
965 }
966
967 std::set<uint32_t> fleet_ids; // all fleets in the model
968 typedef typename std::set<uint32_t>::iterator fleet_ids_iterator;
969
970 // add to Information
971 info->models_map[this->get_id()] = model;
972
973 for (it = this->population_ids->begin(); it != this->population_ids->end();
974 ++it) {
979 FIMS_ERROR_LOG("Population with id " + fims::to_string(*it) +
980 " not found in live objects.");
981 continue;
982 }
983
984 std::shared_ptr<PopulationInterface> population_interface =
985 std::dynamic_pointer_cast<PopulationInterface>(
988 FIMS_ERROR_LOG("Population with id " + fims::to_string(*it) +
989 " not found in live objects.");
990 continue;
991 }
992
993 model->InitializePopulationDerivedQuantities(population_interface->id);
994 std::map<std::string, fims::Vector<Type>> &derived_quantities =
995 model->GetPopulationDerivedQuantities(population_interface->id);
996
997 std::map<std::string, fims_popdy::DimensionInfo>
999 model->GetPopulationDimensionInfo(population_interface->id);
1000
1001 std::stringstream ss;
1002
1003 derived_quantities["total_landings_weight"] =
1005
1006 derived_quantities_dim_info["total_landings_weight"] =
1008 "total_landings_weight",
1010 fims::Vector<std::string>{"n_years"});
1011 info->variable_map[population_interface->total_landings_weight.id_m] =
1012 &derived_quantities["total_landings_weight"];
1013
1014 derived_quantities["total_landings_numbers"] =
1016
1017 derived_quantities_dim_info["total_landings_numbers"] =
1019 "total_landings_numbers",
1021 fims::Vector<std::string>{"n_years"});
1022 info->variable_map[population_interface->total_landings_numbers.id_m] =
1023 &derived_quantities["total_landings_numbers"];
1024
1025 derived_quantities["mortality_F"] =
1027 population_interface->n_ages.get());
1029 "mortality_F",
1031 population_interface->n_ages.get()},
1032 fims::Vector<std::string>{"n_years", "n_ages"});
1033 info->variable_map[population_interface->mortality_F.id_m] =
1034 &derived_quantities["mortality_F"];
1035
1036 derived_quantities["mortality_M"] =
1038 population_interface->n_ages.get());
1040 "mortality_M",
1042 population_interface->n_ages.get()},
1043 fims::Vector<std::string>{"n_years", "n_ages"});
1044 info->variable_map[population_interface->mortality_M.id_m] =
1045 &derived_quantities["mortality_M"];
1046
1047 derived_quantities["mortality_Z"] =
1049 population_interface->n_ages.get());
1051 "mortality_Z",
1053 population_interface->n_ages.get()},
1054 fims::Vector<std::string>{"n_years", "n_ages"});
1055 info->variable_map[population_interface->mortality_Z.id_m] =
1056 &derived_quantities["mortality_Z"];
1057
1058 derived_quantities["numbers_at_age"] =
1059 fims::Vector<Type>((population_interface->n_years.get() + 1) *
1060 population_interface->n_ages.get());
1062 "numbers_at_age",
1063 fims::Vector<int>{(population_interface->n_years.get() + 1),
1064 population_interface->n_ages.get()},
1065 fims::Vector<std::string>{"n_years+1", "n_ages"});
1066 info->variable_map[population_interface->numbers_at_age.id_m] =
1067 &derived_quantities["numbers_at_age"];
1068
1069 derived_quantities["unfished_numbers_at_age"] =
1070 fims::Vector<Type>((population_interface->n_years.get() + 1) *
1071 population_interface->n_ages.get());
1072 derived_quantities_dim_info["unfished_numbers_at_age"] =
1074 "unfished_numbers_at_age",
1075 fims::Vector<int>{(population_interface->n_years.get() + 1),
1076 population_interface->n_ages.get()},
1077 fims::Vector<std::string>{"n_years+1", "n_ages"});
1078 info->variable_map[population_interface->unfished_numbers_at_age.id_m] =
1079 &derived_quantities["unfished_numbers_at_age"];
1080
1081 derived_quantities["biomass"] =
1082 fims::Vector<Type>((population_interface->n_years.get() + 1));
1084 "biomass",
1085 fims::Vector<int>{(population_interface->n_years.get() + 1)},
1086 fims::Vector<std::string>{"n_years+1"});
1087 info->variable_map[population_interface->biomass.id_m] =
1088 &derived_quantities["biomass"];
1089
1090 derived_quantities["spawning_biomass"] =
1091 fims::Vector<Type>((population_interface->n_years.get() + 1));
1092 derived_quantities_dim_info["spawning_biomass"] =
1094 "spawning_biomass",
1095 fims::Vector<int>{(population_interface->n_years.get() + 1)},
1096 fims::Vector<std::string>{"n_years+1"});
1097 info->variable_map[population_interface->spawning_biomass.id_m] =
1098 &derived_quantities["spawning_biomass"];
1099
1100 derived_quantities["unfished_biomass"] =
1101 fims::Vector<Type>((population_interface->n_years.get() + 1));
1102 derived_quantities_dim_info["unfished_biomass"] =
1104 "unfished_biomass",
1105 fims::Vector<int>{(population_interface->n_years.get() + 1)},
1106 fims::Vector<std::string>{"n_years+1"});
1107 info->variable_map[population_interface->unfished_biomass.id_m] =
1108 &derived_quantities["unfished_biomass"];
1109
1110 derived_quantities["unfished_spawning_biomass"] =
1111 fims::Vector<Type>((population_interface->n_years.get() + 1));
1112 derived_quantities_dim_info["unfished_spawning_biomass"] =
1114 "unfished_spawning_biomass",
1115 fims::Vector<int>{(population_interface->n_years.get() + 1)},
1116 fims::Vector<std::string>{"n_years+1"});
1117 info->variable_map[population_interface->unfished_spawning_biomass.id_m] =
1118 &derived_quantities["unfished_spawning_biomass"];
1119
1120 derived_quantities["proportion_mature_at_age"] =
1121 fims::Vector<Type>((population_interface->n_years.get() + 1) *
1122 population_interface->n_ages.get());
1123 derived_quantities_dim_info["proportion_mature_at_age"] =
1125 "proportion_mature_at_age",
1126 fims::Vector<int>{(population_interface->n_years.get() + 1),
1127 population_interface->n_ages.get()},
1128 fims::Vector<std::string>{"n_years+1", "n_ages"});
1129 info->variable_map[population_interface->proportion_mature_at_age.id_m] =
1130 &derived_quantities["proportion_mature_at_age"];
1131
1132 derived_quantities["expected_recruitment"] =
1133 fims::Vector<Type>((population_interface->n_years.get() + 1));
1134 derived_quantities_dim_info["expected_recruitment"] =
1136 "expected_recruitment",
1137 fims::Vector<int>{(population_interface->n_years.get() + 1)},
1138 fims::Vector<std::string>{"n_years+1"});
1139 info->variable_map[population_interface->expected_recruitment.id_m] =
1140 &derived_quantities["expected_recruitment"];
1141
1142 derived_quantities["sum_selectivity"] =
1144 population_interface->n_ages.get());
1145 derived_quantities_dim_info["sum_selectivity"] =
1147 "sum_selectivity",
1149 population_interface->n_ages.get()},
1150 fims::Vector<std::string>{"n_years", "n_ages"});
1151 info->variable_map[population_interface->sum_selectivity.id_m] =
1152 &derived_quantities["sum_selectivity"];
1153
1154 // replace elements in the variable map
1155
1156 for (fleet_ids_iterator fit = population_interface->fleet_ids->begin();
1157 fit != population_interface->fleet_ids->end(); ++fit) {
1158 fleet_ids.insert(*fit);
1159 }
1160 }
1161
1162 for (fleet_ids_iterator it = fleet_ids.begin(); it != fleet_ids.end();
1163 ++it) {
1166 FIMS_ERROR_LOG("Fleet with id " + fims::to_string(*it) +
1167 " not found in live objects.");
1168 continue;
1169 }
1170
1171 std::shared_ptr<FleetInterface> fleet_interface =
1172 std::dynamic_pointer_cast<FleetInterface>(fleet_interface_it->second);
1173 if (!fleet_interface) {
1174 FIMS_ERROR_LOG("Fleet with id " + fims::to_string(*it) +
1175 " not found in live objects.");
1176 continue;
1177 }
1178 model->InitializeFleetDerivedQuantities(fleet_interface->id);
1179 std::map<std::string, fims::Vector<Type>> &derived_quantities =
1180 model->GetFleetDerivedQuantities(fleet_interface->id);
1181
1182 std::map<std::string, fims_popdy::DimensionInfo>
1184 model->GetFleetDimensionInfo(fleet_interface->id);
1185
1186 // initialize derive quantities
1187 // landings
1188 derived_quantities["landings_numbers_at_age"] = fims::Vector<Type>(
1189 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1190 derived_quantities_dim_info["landings_numbers_at_age"] =
1192 "landings_numbers_at_age",
1193 fims::Vector<int>{(fleet_interface->n_years.get()),
1194 fleet_interface->n_ages.get()},
1195 fims::Vector<std::string>{"n_years", "n_ages"});
1196 info->variable_map[fleet_interface->landings_numbers_at_age.id_m] =
1197 &derived_quantities["landings_numbers_at_age"];
1198
1199 derived_quantities["landings_weight_at_age"] = fims::Vector<Type>(
1200 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1201 derived_quantities_dim_info["landings_weight_at_age"] =
1203 "landings_weight_at_age",
1204 fims::Vector<int>{(fleet_interface->n_years.get()),
1205 fleet_interface->n_ages.get()},
1206 fims::Vector<std::string>{"n_years", "n_ages"});
1207 info->variable_map[fleet_interface->landings_weight_at_age.id_m] =
1208 &derived_quantities["landings_weight_at_age"];
1209
1210 derived_quantities["landings_numbers_at_length"] = fims::Vector<Type>(
1211 fleet_interface->n_years.get() * fleet_interface->n_lengths.get());
1212 derived_quantities_dim_info["landings_numbers_at_length"] =
1214 "landings_numbers_at_length",
1215 fims::Vector<int>{(fleet_interface->n_years.get()),
1216 fleet_interface->n_lengths.get()},
1217 fims::Vector<std::string>{"n_years", "n_lengths"});
1218 info->variable_map[fleet_interface->landings_numbers_at_length.id_m] =
1219 &derived_quantities["landings_numbers_at_length"];
1220
1221 derived_quantities["landings_weight"] =
1222 fims::Vector<Type>(fleet_interface->n_years.get());
1223 derived_quantities_dim_info["landings_weight"] =
1225 "landings_weight",
1226 fims::Vector<int>{(fleet_interface->n_years.get())},
1227 fims::Vector<std::string>{"n_years"});
1228 info->variable_map[fleet_interface->landings_weight.id_m] =
1229 &derived_quantities["landings_weight"];
1230
1231 derived_quantities["landings_numbers"] =
1232 fims::Vector<Type>(fleet_interface->n_years.get());
1233 derived_quantities_dim_info["landings_numbers"] =
1235 "landings_numbers",
1236 fims::Vector<int>{(fleet_interface->n_years.get())},
1237 fims::Vector<std::string>{"n_years"});
1238 info->variable_map[fleet_interface->landings_numbers.id_m] =
1239 &derived_quantities["landings_numbers"];
1240
1241 derived_quantities["landings_expected"] =
1242 fims::Vector<Type>(fleet_interface->n_years.get());
1243 derived_quantities_dim_info["landings_expected"] =
1245 "landings_expected",
1246 fims::Vector<int>{(fleet_interface->n_years.get())},
1247 fims::Vector<std::string>{"n_years"});
1248 info->variable_map[fleet_interface->landings_expected.id_m] =
1249 &derived_quantities["landings_expected"];
1250
1251 derived_quantities["log_landings_expected"] =
1252 fims::Vector<Type>(fleet_interface->n_years.get());
1253 derived_quantities_dim_info["log_landings_expected"] =
1255 "log_landings_expected",
1256 fims::Vector<int>{(fleet_interface->n_years.get())},
1257 fims::Vector<std::string>{"n_years"});
1258 info->variable_map[fleet_interface->log_landings_expected.id_m] =
1259 &derived_quantities["log_landings_expected"];
1260
1261 derived_quantities["agecomp_proportion"] = fims::Vector<Type>(
1262 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1263 derived_quantities_dim_info["agecomp_proportion"] =
1265 "agecomp_proportion",
1266 fims::Vector<int>{(fleet_interface->n_years.get()),
1267 fleet_interface->n_ages.get()},
1268 fims::Vector<std::string>{"n_years", "n_ages"});
1269 info->variable_map[fleet_interface->agecomp_proportion.id_m] =
1270 &derived_quantities["agecomp_proportion"];
1271
1272 derived_quantities["lengthcomp_proportion"] = fims::Vector<Type>(
1273 fleet_interface->n_years.get() * fleet_interface->n_lengths.get());
1274 derived_quantities_dim_info["lengthcomp_proportion"] =
1276 "lengthcomp_proportion",
1277 fims::Vector<int>{(fleet_interface->n_years.get()),
1278 fleet_interface->n_lengths.get()},
1279 fims::Vector<std::string>{"n_years", "n_lengths"});
1280 info->variable_map[fleet_interface->lengthcomp_proportion.id_m] =
1281 &derived_quantities["lengthcomp_proportion"];
1282
1283 // index
1284 derived_quantities["index_numbers_at_age"] = fims::Vector<Type>(
1285 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1286 derived_quantities_dim_info["index_numbers_at_age"] =
1288 "index_numbers_at_age",
1289 fims::Vector<int>{(fleet_interface->n_years.get()),
1290 fleet_interface->n_ages.get()},
1291 fims::Vector<std::string>{"n_years", "n_ages"});
1292 info->variable_map[fleet_interface->index_numbers_at_age.id_m] =
1293 &derived_quantities["index_numbers_at_age"];
1294
1295 derived_quantities["index_weight_at_age"] = fims::Vector<Type>(
1296 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1297 derived_quantities_dim_info["index_weight_at_age"] =
1299 "index_weight_at_age",
1300 fims::Vector<int>{(fleet_interface->n_years.get()),
1301 fleet_interface->n_ages.get()},
1302 fims::Vector<std::string>{"n_years", "n_ages"});
1303 info->variable_map[fleet_interface->index_weight_at_age.id_m] =
1304 &derived_quantities["index_weight_at_age"];
1305
1306 derived_quantities["index_numbers_at_length"] = fims::Vector<Type>(
1307 fleet_interface->n_years.get() * fleet_interface->n_lengths.get());
1308 derived_quantities_dim_info["index_numbers_at_length"] =
1310 "index_numbers_at_length",
1311 fims::Vector<int>{(fleet_interface->n_years.get()),
1312 fleet_interface->n_lengths.get()},
1313 fims::Vector<std::string>{"n_years", "n_lengths"});
1314 info->variable_map[fleet_interface->index_numbers_at_length.id_m] =
1315 &derived_quantities["index_numbers_at_length"];
1316
1317 derived_quantities["index_weight"] =
1318 fims::Vector<Type>(fleet_interface->n_years.get());
1320 "index_weight", fims::Vector<int>{(fleet_interface->n_years.get())},
1321 fims::Vector<std::string>{"n_years"});
1322 info->variable_map[fleet_interface->index_weight.id_m] =
1323 &derived_quantities["index_weight"];
1324
1325 derived_quantities["index_numbers"] =
1326 fims::Vector<Type>(fleet_interface->n_years.get());
1328 "index_numbers", fims::Vector<int>{(fleet_interface->n_years.get())},
1329 fims::Vector<std::string>{"n_years"});
1330 info->variable_map[fleet_interface->index_numbers.id_m] =
1331 &derived_quantities["index_numbers"];
1332
1333 derived_quantities["index_expected"] =
1334 fims::Vector<Type>(fleet_interface->n_years.get());
1336 "index_expected", fims::Vector<int>{(fleet_interface->n_years.get())},
1337 fims::Vector<std::string>{"n_years"});
1338 info->variable_map[fleet_interface->index_expected.id_m] =
1339 &derived_quantities["index_expected"];
1340
1341 derived_quantities["log_index_expected"] =
1342 fims::Vector<Type>(fleet_interface->n_years.get());
1343 derived_quantities_dim_info["log_index_expected"] =
1345 "log_index_expected",
1346 fims::Vector<int>{(fleet_interface->n_years.get())},
1347 fims::Vector<std::string>{"n_years"});
1348 info->variable_map[fleet_interface->log_index_expected.id_m] =
1349 &derived_quantities["log_index_expected"];
1350
1351 derived_quantities["agecomp_expected"] = fims::Vector<Type>(
1352 fleet_interface->n_years.get() * fleet_interface->n_ages.get());
1353 derived_quantities_dim_info["agecomp_expected"] =
1355 "agecomp_expected",
1356 fims::Vector<int>{(fleet_interface->n_years.get()),
1357 (fleet_interface->n_ages.get())},
1358 fims::Vector<std::string>{"n_years", "n_ages"});
1359 info->variable_map[fleet_interface->agecomp_expected.id_m] =
1360 &derived_quantities["agecomp_expected"];
1361
1362 derived_quantities["lengthcomp_expected"] = fims::Vector<Type>(
1363 fleet_interface->n_years.get() * fleet_interface->n_lengths.get());
1364 derived_quantities_dim_info["lengthcomp_expected"] =
1366 "lengthcomp_expected",
1367 fims::Vector<int>{(fleet_interface->n_years.get()),
1368 (fleet_interface->n_lengths.get())},
1369 fims::Vector<std::string>{"n_years", "n_lengths"});
1370 info->variable_map[fleet_interface->lengthcomp_expected.id_m] =
1371 &derived_quantities["lengthcomp_expected"];
1372 }
1373
1374 return true;
1375 }
1376
1377 virtual bool add_to_fims_tmb() {
1380 return true;
1381 }
1382
1383#endif
1384};
1385
1386#endif
The CatchAtAgeInterface class is used to interface with the CatchAtAge model. It inherits from the Fi...
Definition rcpp_models.hpp:216
virtual std::string to_json()
Serialize the fishery model to a JSON string.
Definition rcpp_models.hpp:679
void AddPopulation(uint32_t id)
Definition rcpp_models.hpp:239
std::string derived_quantity_to_json(std::map< std::string, fims::Vector< double > >::iterator it, const fims_popdy::DimensionInfo &dim_info)
Definition rcpp_models.hpp:468
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_models.hpp:308
CatchAtAgeInterface()
The constructor.
Definition rcpp_models.hpp:221
void DoReporting(bool report)
Enable or disable reporting for the CatchAtAge model.
Definition rcpp_models.hpp:260
virtual uint32_t get_id()
Method to get this id.
Definition rcpp_models.hpp:303
std::string fleet_to_json(FleetInterface *fleet_interface)
Method to convert a fleet to a JSON string.
Definition rcpp_models.hpp:588
std::string derived_quantities_component_to_json(std::map< std::string, fims::Vector< double > > &dqs, std::map< std::string, fims_popdy::DimensionInfo > &dim_info)
Send the fleet-based derived quantities to the json file.
Definition rcpp_models.hpp:553
std::string population_to_json(PopulationInterface *population_interface)
Method to convert a population to a JSON string.
Definition rcpp_models.hpp:313
CatchAtAgeInterface(const CatchAtAgeInterface &other)
Construct a new Catch At Age Interface object.
Definition rcpp_models.hpp:233
bool IsReporting()
Check if reporting is enabled for the CatchAtAge model.
Definition rcpp_models.hpp:282
static std::map< uint32_t, std::shared_ptr< DataInterfaceBase > > live_objects
The map associating the IDs of DataInterfaceBase to the objects. This is a live object,...
Definition rcpp_data.hpp:43
static std::map< uint32_t, std::shared_ptr< DistributionsInterfaceBase > > live_objects
The map associating the ID of the DistributionsInterfaceBase to the DistributionsInterfaceBase object...
Definition rcpp_distribution.hpp:67
Base class for all interface objects.
Definition rcpp_interface_base.hpp:628
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:638
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:643
The FisheryModelInterfaceBase class is the base class for all fishery models in the FIMS Rcpp interfa...
Definition rcpp_models.hpp:36
double min(const std::valarray< double > &v)
Minimum method to calculate the minimum of an array or vector of doubles.
Definition rcpp_models.hpp:185
FisheryModelInterfaceBase(const FisheryModelInterfaceBase &other)
Construct a new Data Interface Base object.
Definition rcpp_models.hpp:80
static uint32_t id_g
The static id of the FleetInterfaceBase object.
Definition rcpp_models.hpp:51
virtual uint32_t get_id()=0
Get the ID for the child fleet interface objects to inherit.
FisheryModelInterfaceBase()
The constructor.
Definition rcpp_models.hpp:67
std::set< uint32_t >::iterator population_id_iterator
Iterator for population ids.
Definition rcpp_models.hpp:45
uint32_t id
The local id of the FleetInterfaceBase object.
Definition rcpp_models.hpp:55
std::valarray< double > fabs(const std::valarray< double > &v)
A function to compute the absolute value of a value array of floating-point values....
Definition rcpp_models.hpp:203
virtual std::string to_json()
Serialize the fishery model to a JSON string.
Definition rcpp_models.hpp:101
static std::map< uint32_t, std::shared_ptr< FisheryModelInterfaceBase > > live_objects
The map associating the IDs of FleetInterfaceBase to the objects. This is a live object,...
Definition rcpp_models.hpp:62
double sum(const std::valarray< double > &v)
Sum method to calculate the sum of an array or vector of doubles.
Definition rcpp_models.hpp:156
Rcpp::NumericVector get_random_parameters_vector()
Get the vector of random effect parameters for the model.
Definition rcpp_models.hpp:137
Rcpp::NumericVector get_fixed_parameters_vector()
Get the vector of fixed effect parameters for the model.
Definition rcpp_models.hpp:117
std::shared_ptr< std::set< uint32_t > > population_ids
The set of population ids that this fishery model operates on.
Definition rcpp_models.hpp:41
virtual ~FisheryModelInterfaceBase()
The destructor.
Definition rcpp_models.hpp:86
double sum(const std::vector< double > &v)
Sum method for a vector of doubles.
Definition rcpp_models.hpp:170
static std::map< uint32_t, std::shared_ptr< FleetInterfaceBase > > live_objects
The map associating the IDs of FleetInterfaceBase to the objects. This is a live object,...
Definition rcpp_fleet.hpp:34
The Rcpp interface for Fleet to instantiate from R: fleet <- methods::new(Fleet)
Definition rcpp_fleet.hpp:68
static std::map< uint32_t, std::shared_ptr< GrowthInterfaceBase > > live_objects
The map associating the IDs of GrowthInterfaceBase to the objects. This is a live object,...
Definition rcpp_growth.hpp:34
static std::map< uint32_t, std::shared_ptr< MaturityInterfaceBase > > live_objects
The map associating the IDs of MaturityInterfaceBase to the objects. This is a live object,...
Definition rcpp_maturity.hpp:35
static std::map< uint32_t, std::shared_ptr< PopulationInterfaceBase > > live_objects
The map associating the IDs of PopulationInterfaceBase to the objects. This is a live object,...
Definition rcpp_population.hpp:35
Rcpp interface for a new Population to instantiate from R: population <- methods::new(population)
Definition rcpp_population.hpp:80
static std::map< uint32_t, std::shared_ptr< RecruitmentInterfaceBase > > live_objects
The map associating the IDs of RecruitmentInterfaceBase to the objects. This is a live object,...
Definition rcpp_recruitment.hpp:40
static std::map< uint32_t, std::shared_ptr< SelectivityInterfaceBase > > live_objects
The map associating the IDs of SelectivityInterfaceBase to the objects. This is a live object,...
Definition rcpp_selectivity.hpp:35
static std::string PrettyFormatJSON(const std::string &json)
Formats a JSON string.
Definition fims_json.hpp:128
Definition fims_vector.hpp:27
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > > models_map
Definition information.hpp:135
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Definition information.hpp:109
std::map< uint32_t, std::shared_ptr< fims_popdy::Population< Type > > >::iterator population_iterator
Definition information.hpp:119
std::unordered_map< uint32_t, std::shared_ptr< fims_popdy::FisheryModelBase< Type > > >::iterator model_map_iterator
Definition information.hpp:139
static std::shared_ptr< Information< Type > > GetInstance()
Returns a singleton Information object for type T.
Definition information.hpp:263
static std::shared_ptr< Model< Type > > GetInstance()
Evaluate. Calculates the joint negative log-likelihood function.
Definition model.hpp:54
Platform macros and the core FIMS logging system.
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
: Loops over model components and returns the negative log-likelihood function.
The Rcpp interface to declare different types of data, e.g., age-composition and index data....
The Rcpp interface to declare different distributions, e.g., normal and log normal....
The Rcpp interface to declare fleets. Allows for the use of methods::new() in R.
The Rcpp interface to declare different types of growth, e.g., empirical weight-at-age data....
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:236
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...
double sanitize_val(double x)
Sanitize a double value by replacing NaN or Inf with -999.0.
Definition rcpp_interface_base.hpp:113
The Rcpp interface to declare different maturity options, e.g., logistic. Allows for the use of metho...
The Rcpp interface to declare different types of populations. Allows for the use of methods::new() in...
The Rcpp interface to declare different types of recruitment, e.g., Beverton–Holt stock–recruitment r...
The Rcpp interface to declare different types of selectivity, e.g., logistic and double logistic....
Structure to hold dimension information for derived quantities.
Definition fishery_model_base.hpp:25