9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_SELECTIVITY_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_SELECTIVITY_HPP
12#include "../../../population_dynamics/selectivity/selectivity.hpp"
34 static std::map<uint32_t, std::shared_ptr<SelectivityInterfaceBase>>
93 std::make_shared<LogisticSelectivityInterface>(*
this);
127 LogisticSel.inflection_point[0] = this->inflection_point[0].initial_value_m;
129 LogisticSel.slope[0] = this->slope[0].initial_value_m;
141 " has been finalized already.");
146 std::shared_ptr<fims_info::Information<double>>
info =
152 it =
info->selectivity_models.find(this->
id);
156 " not found in Information.");
159 std::shared_ptr<fims_popdy::LogisticSelectivity<double>>
sel =
160 std::dynamic_pointer_cast<fims_popdy::LogisticSelectivity<double>>(
164 if (this->inflection_point[
i].estimation_type_m.
get() ==
"constant") {
165 this->inflection_point[
i].final_value_m =
166 this->inflection_point[
i].initial_value_m;
168 this->inflection_point[
i].final_value_m =
sel->inflection_point[
i];
173 if (this->slope[
i].estimation_type_m.
get() ==
"constant") {
174 this->slope[
i].final_value_m = this->slope[
i].initial_value_m;
176 this->slope[
i].final_value_m =
sel->slope[
i];
189 std::stringstream
ss;
192 ss <<
" \"module_name\":\"Selectivity\",\n";
193 ss <<
" \"module_type\": \"Logistic\",\n";
194 ss <<
" \"module_id\": " << this->
id <<
",\n";
196 ss <<
" \"parameters\": [\n{\n";
197 ss <<
" \"name\": \"inflection_point\",\n";
198 ss <<
" \"id\":" << this->inflection_point.
id_m <<
",\n";
199 ss <<
" \"type\": \"vector\",\n";
200 ss <<
" \"dimensionality\": {\n";
201 ss <<
" \"header\": [null],\n";
202 ss <<
" \"dimensions\": [1]\n},\n";
203 ss <<
" \"values\":" << this->inflection_point <<
"},\n ";
206 ss <<
" \"name\": \"slope\",\n";
207 ss <<
" \"id\":" << this->slope.
id_m <<
",\n";
208 ss <<
" \"type\": \"vector\",\n";
209 ss <<
" \"dimensionality\": {\n";
210 ss <<
" \"header\": [null],\n";
211 ss <<
" \"dimensions\": [1]\n},\n";
212 ss <<
" \"values\":" << this->slope <<
"}]\n";
221 template <
typename Type>
223 std::shared_ptr<fims_info::Information<Type>>
info =
226 std::shared_ptr<fims_popdy::LogisticSelectivity<Type>> selectivity =
227 std::make_shared<fims_popdy::LogisticSelectivity<Type>>();
228 std::stringstream
ss;
230 selectivity->id = this->
id;
231 selectivity->inflection_point.resize(this->inflection_point.
size());
232 for (
size_t i = 0;
i < this->inflection_point.
size();
i++) {
233 selectivity->inflection_point[
i] =
234 this->inflection_point[
i].initial_value_m;
235 if (this->inflection_point[
i].estimation_type_m.
get() ==
238 ss <<
"Selectivity." << this->
id <<
".inflection_point."
239 << this->inflection_point[
i].
id_m;
240 info->RegisterParameterName(
ss.str());
241 info->RegisterParameter(selectivity->inflection_point[
i]);
243 if (this->inflection_point[
i].estimation_type_m.
get() ==
246 ss <<
"Selectivity." << this->
id <<
".inflection_point."
247 << this->inflection_point[
i].
id_m;
248 info->RegisterRandomEffect(selectivity->inflection_point[
i]);
249 info->RegisterRandomEffectName(
ss.str());
252 info->variable_map[this->inflection_point.
id_m] =
255 selectivity->slope.
resize(this->slope.
size());
256 for (
size_t i = 0;
i < this->slope.
size();
i++) {
257 selectivity->slope[
i] = this->slope[
i].initial_value_m;
258 if (this->slope[
i].estimation_type_m.
get() ==
"fixed_effects") {
260 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
261 info->RegisterParameterName(
ss.str());
262 info->RegisterParameter(selectivity->slope[
i]);
264 if (this->slope[
i].estimation_type_m.
get() ==
"random_effects") {
266 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
267 info->RegisterRandomEffectName(
ss.str());
268 info->RegisterRandomEffect(selectivity->slope[
i]);
271 info->variable_map[this->slope.
id_m] = &(selectivity)->
slope;
274 info->selectivity_models[selectivity->id] = selectivity;
311 std::make_shared<DoubleLogisticSelectivityInterface>(*
this);
342 this->inflection_point_asc[0].initial_value_m;
347 this->inflection_point_desc[0].initial_value_m;
360 fims::to_string(this->
id) +
361 " has been finalized already.");
366 std::shared_ptr<fims_info::Information<double>>
info =
372 it =
info->selectivity_models.find(this->
id);
376 fims::to_string(this->
id) +
377 " not found in Information.");
380 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<double>>
sel =
381 std::dynamic_pointer_cast<
385 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
387 this->inflection_point_asc[
i].final_value_m =
388 this->inflection_point_asc[
i].initial_value_m;
390 this->inflection_point_asc[
i].final_value_m =
391 sel->inflection_point_asc[
i];
396 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"constant") {
399 this->
slope_asc[
i].final_value_m = sel->slope_asc[
i];
404 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
406 this->inflection_point_desc[
i].final_value_m =
407 this->inflection_point_desc[
i].initial_value_m;
409 this->inflection_point_desc[
i].final_value_m =
410 sel->inflection_point_desc[
i];
429 std::stringstream
ss;
432 ss <<
" \"module_name\": \"Selectivity\",\n";
433 ss <<
" \"module_type\": \"DoubleLogistic\",\n";
434 ss <<
" \"module_id\": " << this->
id <<
",\n";
436 ss <<
" \"parameters\":[\n{\n";
437 ss <<
" \"name\": \"inflection_point_asc\",\n";
438 ss <<
" \"id\":" << this->inflection_point_asc.
id_m <<
",\n";
439 ss <<
" \"type\": \"vector\",\n";
440 ss <<
" \"dimensionality\": {\n";
441 ss <<
" \"header\": [null],\n";
442 ss <<
" \"dimensions\": [1]\n},\n";
443 ss <<
" \"values\":" << this->inflection_point_asc <<
"},\n";
446 ss <<
" \"name\": \"slope_asc\",\n";
448 ss <<
" \"type\": \"vector\",\n";
449 ss <<
" \"dimensionality\": {\n";
450 ss <<
" \"header\": [null],\n";
451 ss <<
" \"dimensions\": [1]\n},\n";
455 ss <<
" \"name\": \"inflection_point_desc\",\n";
456 ss <<
" \"id\":" << this->inflection_point_desc.
id_m <<
",\n";
457 ss <<
" \"type\": \"vector\",\n";
458 ss <<
" \"dimensionality\": {\n";
459 ss <<
" \"header\": [null],\n";
460 ss <<
" \"dimensions\": [1]\n},\n";
461 ss <<
" \"values\":" << this->inflection_point_desc <<
"},\n";
464 ss <<
" \"name\": \"slope_desc\",\n";
466 ss <<
" \"type\": \"vector\",\n";
467 ss <<
" \"dimensionality\": {\n";
468 ss <<
" \"header\": [null],\n";
469 ss <<
" \"dimensions\": [1]\n},\n";
479 template <
typename Type>
481 std::shared_ptr<fims_info::Information<Type>>
info =
484 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<Type>> selectivity =
485 std::make_shared<fims_popdy::DoubleLogisticSelectivity<Type>>();
487 std::stringstream
ss;
489 selectivity->id = this->
id;
490 selectivity->inflection_point_asc.resize(this->inflection_point_asc.
size());
491 for (
size_t i = 0;
i < this->inflection_point_asc.
size();
i++) {
492 selectivity->inflection_point_asc[
i] =
493 this->inflection_point_asc[
i].initial_value_m;
494 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
497 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
498 << this->inflection_point_asc[
i].
id_m;
499 info->RegisterParameterName(
ss.str());
500 info->RegisterParameter(selectivity->inflection_point_asc[
i]);
502 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
505 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
506 << this->inflection_point_asc[
i].
id_m;
507 info->RegisterRandomEffectName(
ss.str());
508 info->RegisterRandomEffect(selectivity->inflection_point_asc[
i]);
511 info->variable_map[this->inflection_point_asc.
id_m] =
516 selectivity->slope_asc[
i] = this->
slope_asc[
i].initial_value_m;
518 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"fixed_effects") {
520 ss <<
"Selectivity." << this->
id <<
".slope_asc."
522 info->RegisterParameterName(
ss.str());
523 info->RegisterParameter(selectivity->slope_asc[
i]);
525 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"random_effects") {
527 ss <<
"Selectivity." << this->
id <<
".slope_asc."
529 info->RegisterRandomEffectName(
ss.str());
530 info->RegisterRandomEffect(selectivity->slope_asc[
i]);
535 selectivity->inflection_point_desc.
resize(
536 this->inflection_point_desc.
size());
537 for (
size_t i = 0;
i < this->inflection_point_desc.
size();
i++) {
538 selectivity->inflection_point_desc[
i] =
539 this->inflection_point_desc[
i].initial_value_m;
541 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
544 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
545 << this->inflection_point_desc[
i].
id_m;
546 info->RegisterParameterName(
ss.str());
547 info->RegisterParameter(selectivity->inflection_point_desc[
i]);
549 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
552 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
553 << this->inflection_point_desc[
i].
id_m;
554 info->RegisterRandomEffectName(
ss.str());
555 info->RegisterRandomEffect(selectivity->inflection_point_desc[
i]);
558 info->variable_map[this->inflection_point_desc.
id_m] =
563 selectivity->slope_desc[
i] = this->
slope_desc[
i].initial_value_m;
565 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"fixed_effects") {
567 ss <<
"Selectivity." << this->
id <<
".slope_desc."
569 info->RegisterParameterName(
ss.str());
570 info->RegisterParameter(selectivity->slope_desc[
i]);
572 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"random_effects") {
574 ss <<
"Selectivity." << this->
id <<
".slope_desc."
576 info->RegisterRandomEffectName(
ss.str());
577 info->RegisterRandomEffect(selectivity->slope_desc[
i]);
584 info->selectivity_models[selectivity->id] = selectivity;
632 std::make_shared<AgeSpecificSelectivityInterface>(*
this);
668 if (this->ages.
size() > 0) {
670 this->ages.
storage_m->begin(),
this->ages.storage_m->end()));
675 for (
size_t i = 0;
i < this->logit_sel_at_age.
size();
i++) {
677 this->logit_sel_at_age[
i].initial_value_m;
690 " has been finalized already.");
695 std::shared_ptr<fims_info::Information<double>>
info =
701 it =
info->selectivity_models.find(this->
id);
705 " not found in Information.");
708 std::shared_ptr<fims_popdy::AgeSpecificSelectivity<double>>
sel =
709 std::dynamic_pointer_cast<fims_popdy::AgeSpecificSelectivity<double>>(
712 if (this->logit_sel_at_age[
i].estimation_type_m.
get() ==
"constant") {
713 this->logit_sel_at_age[
i].final_value_m =
714 this->logit_sel_at_age[
i].initial_value_m;
716 this->logit_sel_at_age[
i].final_value_m =
sel->logit_sel_at_age[
i];
729 std::stringstream
ss;
732 ss <<
" \"module_name\":\"Selectivity\",\n";
733 ss <<
" \"module_type\": \"AgeSpecific\",\n";
734 ss <<
" \"module_id\": " << this->
id <<
",\n";
736 ss <<
" \"parameters\": [\n{\n";
737 ss <<
" \"name\": \"logit_sel_at_age\",\n";
738 ss <<
" \"id\":" << this->logit_sel_at_age.
id_m <<
",\n";
739 ss <<
" \"type\": \"vector\",\n";
740 ss <<
" \"dimensionality\": {\n";
741 ss <<
" \"header\": [\"n_ages\"],\n";
742 ss <<
" \"dimensions\": [" << this->n_ages.
get() <<
"]\n},\n";
743 ss <<
" \"values\":" << this->logit_sel_at_age <<
"}]\n";
752 template <
typename Type>
754 std::shared_ptr<fims_info::Information<Type>>
info =
757 std::shared_ptr<fims_popdy::AgeSpecificSelectivity<Type>> selectivity =
758 std::make_shared<fims_popdy::AgeSpecificSelectivity<Type>>();
759 std::stringstream
ss;
761 selectivity->id = this->
id;
762 selectivity->n_ages = this->n_ages.
get();
763 selectivity->min_age = *std::min_element(this->ages.
storage_m->begin(),
764 this->ages.storage_m->end());
765 selectivity->logit_sel_at_age.resize(this->logit_sel_at_age.
size());
766 for (
size_t i = 0;
i < this->logit_sel_at_age.
size();
i++) {
767 selectivity->logit_sel_at_age[
i] =
768 this->logit_sel_at_age[
i].initial_value_m;
769 if (this->logit_sel_at_age[
i].estimation_type_m.
get() ==
772 ss <<
"Selectivity." << this->
id <<
".logit_sel_at_age."
773 << this->logit_sel_at_age[
i].
id_m;
774 info->RegisterParameterName(
ss.str());
775 info->RegisterParameter(selectivity->logit_sel_at_age[
i]);
777 if (this->logit_sel_at_age[
i].estimation_type_m.
get() ==
780 ss <<
"Selectivity." << this->
id <<
".logit_sel_at_age."
781 << this->logit_sel_at_age[
i].
id_m;
782 info->RegisterRandomEffect(selectivity->logit_sel_at_age[
i]);
783 info->RegisterRandomEffectName(
ss.str());
786 info->variable_map[this->logit_sel_at_age.
id_m] =
790 info->selectivity_models[selectivity->id] = selectivity;
Rcpp interface for selectivity_at_age to instantiate the object from R: selectivity_at_age <- methods...
Definition rcpp_selectivity.hpp:608
VariableVector logit_sel_at_age
Age-specific selectivity parameter values.
Definition rcpp_selectivity.hpp:625
virtual ~AgeSpecificSelectivityInterface()
The destructor.
Definition rcpp_selectivity.hpp:652
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_selectivity.hpp:658
SharedInt n_ages
The number of age bins.
Definition rcpp_selectivity.hpp:613
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_selectivity.hpp:686
AgeSpecificSelectivityInterface()
The constructor.
Definition rcpp_selectivity.hpp:630
virtual double evaluate(double x)
Evaluate selectivity using fims_math::inv_logit.
Definition rcpp_selectivity.hpp:665
RealVector ages
Vector of ages.
Definition rcpp_selectivity.hpp:617
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_selectivity.hpp:728
AgeSpecificSelectivityInterface(const AgeSpecificSelectivityInterface &other)
Construct a new Selectivity-at-age Interface object.
Definition rcpp_selectivity.hpp:642
SharedInt min_age
Minimum observed age.
Definition rcpp_selectivity.hpp:621
Rcpp interface for logistic selectivity as an S4 object. To instantiate from R: logistic_selectivity ...
Definition rcpp_selectivity.hpp:298
DoubleLogisticSelectivityInterface(const DoubleLogisticSelectivityInterface &other)
Construct a new Double Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:321
VariableVector slope_desc
Definition rcpp_selectivity.hpp:307
virtual double evaluate(double x)
evaluate the double logistic selectivity function
Definition rcpp_selectivity.hpp:338
virtual uint32_t get_id()
returns the id for the double logistic selectivity interface
Definition rcpp_selectivity.hpp:332
VariableVector slope_asc
Definition rcpp_selectivity.hpp:303
VariableVector inflection_point_asc
Definition rcpp_selectivity.hpp:300
VariableVector inflection_point_desc
Definition rcpp_selectivity.hpp:304
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_selectivity.hpp:428
virtual void finalize()
finalize function. Extracts derived quantities back to the Rcpp interface object from the Information...
Definition rcpp_selectivity.hpp:356
Base class for all interface objects.
Definition rcpp_interface_base.hpp:656
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:661
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:666
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:671
Rcpp interface for logistic selectivity to instantiate the object from R: logistic_selectivity <- met...
Definition rcpp_selectivity.hpp:77
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_selectivity.hpp:137
VariableVector slope
The width of the curve at the inflection point.
Definition rcpp_selectivity.hpp:86
LogisticSelectivityInterface()
The constructor.
Definition rcpp_selectivity.hpp:91
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_selectivity.hpp:188
virtual ~LogisticSelectivityInterface()
The destructor.
Definition rcpp_selectivity.hpp:111
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_selectivity.hpp:117
VariableVector inflection_point
The index value at which the response reaches 0.5.
Definition rcpp_selectivity.hpp:82
LogisticSelectivityInterface(const LogisticSelectivityInterface &other)
Construct a new Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:103
virtual double evaluate(double x)
Evaluate selectivity using the logistic function.
Definition rcpp_selectivity.hpp:124
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:432
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:603
std::shared_ptr< std::vector< double > > storage_m
real storage.
Definition rcpp_interface_base.hpp:441
Rcpp interface that serves as the parent class for Rcpp selectivity interfaces. This type should be i...
Definition rcpp_selectivity.hpp:19
virtual ~SelectivityInterfaceBase()
The destructor.
Definition rcpp_selectivity.hpp:58
SelectivityInterfaceBase()
The constructor.
Definition rcpp_selectivity.hpp:40
virtual uint32_t get_id()=0
Get the ID for the child selectivity interface objects to inherit.
SelectivityInterfaceBase(const SelectivityInterfaceBase &other)
Construct a new Selectivity Interface Base object.
Definition rcpp_selectivity.hpp:52
static uint32_t id_g
The static id of the SelectivityInterfaceBase.
Definition rcpp_selectivity.hpp:24
virtual double evaluate(double x)=0
A method for each child selectivity interface object to inherit so each selectivity option can have a...
uint32_t id
The local id of the SelectivityInterfaceBase object.
Definition rcpp_selectivity.hpp:28
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
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:29
int get() const
Retrieve the value of the integer.
Definition rcpp_shared_primitive.hpp:127
An Rcpp interface class that defines the VariableVector class.
Definition rcpp_interface_base.hpp:144
Variable & get(size_t pos)
An internal accessor for calling a position of a VariableVector from R.
Definition rcpp_interface_base.hpp:267
uint32_t id_m
The local ID of the Variable object.
Definition rcpp_interface_base.hpp:157
void resize(size_t size)
Resizes a VariableVector to the desired length.
Definition rcpp_interface_base.hpp:295
size_t size()
Returns the size of a VariableVector.
Definition rcpp_interface_base.hpp:288
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
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,...
Age-specific selectivity calculated using one parameter per age bin.
Definition age_specific.hpp:49
size_t n_ages
Stores the number of modeled age bins.
Definition age_specific.hpp:60
DoubleLogisticSelectivity class that returns the double logistic function value from fims_math.
Definition double_logistic.hpp:23
fims::Vector< Type > inflection_point_asc
Definition double_logistic.hpp:24
fims::Vector< Type > inflection_point_desc
Definition double_logistic.hpp:30
virtual const Type evaluate(const Type &x)
Method of the double logistic selectivity class that implements the double logistic function from FIM...
Definition double_logistic.hpp:52
LogisticSelectivity class that returns the logistic function value from fims_math.
Definition logistic.hpp:29
fims::Vector< Type > inflection_point
Definition logistic.hpp:31