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;
Rcpp interface for logistic selectivity as an S4 object. To instantiate from R: logistic_selectivity ...
Definition rcpp_selectivity.hpp:298
ParameterVector slope_desc
Definition rcpp_selectivity.hpp:307
ParameterVector inflection_point_desc
Definition rcpp_selectivity.hpp:304
DoubleLogisticSelectivityInterface(const DoubleLogisticSelectivityInterface &other)
Construct a new Double Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:321
ParameterVector slope_asc
Definition rcpp_selectivity.hpp:303
virtual double evaluate(double x)
evaluate the double logistic selectivity function
Definition rcpp_selectivity.hpp:338
ParameterVector inflection_point_asc
Definition rcpp_selectivity.hpp:300
virtual uint32_t get_id()
returns the id for the double logistic selectivity interface
Definition rcpp_selectivity.hpp:332
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:628
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:633
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
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
ParameterVector inflection_point
The index value at which the response reaches 0.5.
Definition rcpp_selectivity.hpp:82
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
ParameterVector slope
The width of the curve at the inflection point.
Definition rcpp_selectivity.hpp:86
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 ParameterVector class.
Definition rcpp_interface_base.hpp:144
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:295
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:288
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:157
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:267
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
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:235
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...
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