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>>
75std::map<uint32_t, std::shared_ptr<SelectivityInterfaceBase>>
99 std::make_shared<LogisticSelectivityInterface>(*
this);
133 LogisticSel.inflection_point[0] = this->inflection_point[0].initial_value_m;
135 LogisticSel.slope[0] = this->slope[0].initial_value_m;
147 " has been finalized already.");
152 std::shared_ptr<fims_info::Information<double>>
info =
158 it =
info->selectivity_models.find(this->
id);
162 " not found in Information.");
165 std::shared_ptr<fims_popdy::LogisticSelectivity<double>>
sel =
166 std::dynamic_pointer_cast<fims_popdy::LogisticSelectivity<double>>(
170 if (this->inflection_point[
i].estimation_type_m.
get() ==
"constant") {
171 this->inflection_point[
i].final_value_m =
172 this->inflection_point[
i].initial_value_m;
174 this->inflection_point[
i].final_value_m =
sel->inflection_point[
i];
179 if (this->slope[
i].estimation_type_m.
get() ==
"constant") {
180 this->slope[
i].final_value_m = this->slope[
i].initial_value_m;
182 this->slope[
i].final_value_m =
sel->slope[
i];
195 std::stringstream
ss;
198 ss <<
" \"module_name\":\"Selectivity\",\n";
199 ss <<
" \"module_type\": \"Logistic\",\n";
200 ss <<
" \"module_id\": " << this->
id <<
",\n";
202 ss <<
" \"parameters\": [\n{\n";
203 ss <<
" \"name\": \"inflection_point\",\n";
204 ss <<
" \"id\":" << this->inflection_point.
id_m <<
",\n";
205 ss <<
" \"type\": \"vector\",\n";
206 ss <<
" \"dimensionality\": {\n";
207 ss <<
" \"header\": [null],\n";
208 ss <<
" \"dimensions\": [1]\n},\n";
209 ss <<
" \"values\":" << this->inflection_point <<
"},\n ";
212 ss <<
" \"name\": \"slope\",\n";
213 ss <<
" \"id\":" << this->slope.
id_m <<
",\n";
214 ss <<
" \"type\": \"vector\",\n";
215 ss <<
" \"dimensionality\": {\n";
216 ss <<
" \"header\": [null],\n";
217 ss <<
" \"dimensions\": [1]\n},\n";
218 ss <<
" \"values\":" << this->slope <<
"}]\n";
227 template <
typename Type>
229 std::shared_ptr<fims_info::Information<Type>>
info =
232 std::shared_ptr<fims_popdy::LogisticSelectivity<Type>> selectivity =
233 std::make_shared<fims_popdy::LogisticSelectivity<Type>>();
234 std::stringstream
ss;
236 selectivity->id = this->
id;
237 selectivity->inflection_point.resize(this->inflection_point.
size());
238 for (
size_t i = 0;
i < this->inflection_point.
size();
i++) {
239 selectivity->inflection_point[
i] =
240 this->inflection_point[
i].initial_value_m;
241 if (this->inflection_point[
i].estimation_type_m.
get() ==
244 ss <<
"Selectivity." << this->
id <<
".inflection_point."
245 << this->inflection_point[
i].
id_m;
246 info->RegisterParameterName(
ss.str());
247 info->RegisterParameter(selectivity->inflection_point[
i]);
249 if (this->inflection_point[
i].estimation_type_m.
get() ==
252 ss <<
"Selectivity." << this->
id <<
".inflection_point."
253 << this->inflection_point[
i].
id_m;
254 info->RegisterRandomEffect(selectivity->inflection_point[
i]);
255 info->RegisterRandomEffectName(
ss.str());
258 info->variable_map[this->inflection_point.
id_m] =
261 selectivity->slope.
resize(this->slope.
size());
262 for (
size_t i = 0;
i < this->slope.
size();
i++) {
263 selectivity->slope[
i] = this->slope[
i].initial_value_m;
264 if (this->slope[
i].estimation_type_m.
get() ==
"fixed_effects") {
266 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
267 info->RegisterParameterName(
ss.str());
268 info->RegisterParameter(selectivity->slope[
i]);
270 if (this->slope[
i].estimation_type_m.
get() ==
"random_effects") {
272 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
273 info->RegisterRandomEffectName(
ss.str());
274 info->RegisterRandomEffect(selectivity->slope[
i]);
277 info->variable_map[this->slope.
id_m] = &(selectivity)->
slope;
280 info->selectivity_models[selectivity->id] = selectivity;
317 std::make_shared<DoubleLogisticSelectivityInterface>(*
this);
348 this->inflection_point_asc[0].initial_value_m;
353 this->inflection_point_desc[0].initial_value_m;
366 fims::to_string(this->
id) +
367 " has been finalized already.");
372 std::shared_ptr<fims_info::Information<double>>
info =
378 it =
info->selectivity_models.find(this->
id);
382 fims::to_string(this->
id) +
383 " not found in Information.");
386 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<double>>
sel =
387 std::dynamic_pointer_cast<
391 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
393 this->inflection_point_asc[
i].final_value_m =
394 this->inflection_point_asc[
i].initial_value_m;
396 this->inflection_point_asc[
i].final_value_m =
397 sel->inflection_point_asc[
i];
402 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"constant") {
405 this->
slope_asc[
i].final_value_m = sel->slope_asc[
i];
410 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
412 this->inflection_point_desc[
i].final_value_m =
413 this->inflection_point_desc[
i].initial_value_m;
415 this->inflection_point_desc[
i].final_value_m =
416 sel->inflection_point_desc[
i];
435 std::stringstream
ss;
438 ss <<
" \"module_name\": \"Selectivity\",\n";
439 ss <<
" \"module_type\": \"DoubleLogistic\",\n";
440 ss <<
" \"module_id\": " << this->
id <<
",\n";
442 ss <<
" \"parameters\":[\n{\n";
443 ss <<
" \"name\": \"inflection_point_asc\",\n";
444 ss <<
" \"id\":" << this->inflection_point_asc.
id_m <<
",\n";
445 ss <<
" \"type\": \"vector\",\n";
446 ss <<
" \"dimensionality\": {\n";
447 ss <<
" \"header\": [null],\n";
448 ss <<
" \"dimensions\": [1]\n},\n";
449 ss <<
" \"values\":" << this->inflection_point_asc <<
"},\n";
452 ss <<
" \"name\": \"slope_asc\",\n";
454 ss <<
" \"type\": \"vector\",\n";
455 ss <<
" \"dimensionality\": {\n";
456 ss <<
" \"header\": [null],\n";
457 ss <<
" \"dimensions\": [1]\n},\n";
461 ss <<
" \"name\": \"inflection_point_desc\",\n";
462 ss <<
" \"id\":" << this->inflection_point_desc.
id_m <<
",\n";
463 ss <<
" \"type\": \"vector\",\n";
464 ss <<
" \"dimensionality\": {\n";
465 ss <<
" \"header\": [null],\n";
466 ss <<
" \"dimensions\": [1]\n},\n";
467 ss <<
" \"values\":" << this->inflection_point_desc <<
"},\n";
470 ss <<
" \"name\": \"slope_desc\",\n";
472 ss <<
" \"type\": \"vector\",\n";
473 ss <<
" \"dimensionality\": {\n";
474 ss <<
" \"header\": [null],\n";
475 ss <<
" \"dimensions\": [1]\n},\n";
485 template <
typename Type>
487 std::shared_ptr<fims_info::Information<Type>>
info =
490 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<Type>> selectivity =
491 std::make_shared<fims_popdy::DoubleLogisticSelectivity<Type>>();
493 std::stringstream
ss;
495 selectivity->id = this->
id;
496 selectivity->inflection_point_asc.resize(this->inflection_point_asc.
size());
497 for (
size_t i = 0;
i < this->inflection_point_asc.
size();
i++) {
498 selectivity->inflection_point_asc[
i] =
499 this->inflection_point_asc[
i].initial_value_m;
500 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
503 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
504 << this->inflection_point_asc[
i].
id_m;
505 info->RegisterParameterName(
ss.str());
506 info->RegisterParameter(selectivity->inflection_point_asc[
i]);
508 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
511 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
512 << this->inflection_point_asc[
i].
id_m;
513 info->RegisterRandomEffectName(
ss.str());
514 info->RegisterRandomEffect(selectivity->inflection_point_asc[
i]);
517 info->variable_map[this->inflection_point_asc.
id_m] =
522 selectivity->slope_asc[
i] = this->
slope_asc[
i].initial_value_m;
524 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"fixed_effects") {
526 ss <<
"Selectivity." << this->
id <<
".slope_asc."
528 info->RegisterParameterName(
ss.str());
529 info->RegisterParameter(selectivity->slope_asc[
i]);
531 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"random_effects") {
533 ss <<
"Selectivity." << this->
id <<
".slope_asc."
535 info->RegisterRandomEffectName(
ss.str());
536 info->RegisterRandomEffect(selectivity->slope_asc[
i]);
541 selectivity->inflection_point_desc.
resize(
542 this->inflection_point_desc.
size());
543 for (
size_t i = 0;
i < this->inflection_point_desc.
size();
i++) {
544 selectivity->inflection_point_desc[
i] =
545 this->inflection_point_desc[
i].initial_value_m;
547 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
550 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
551 << this->inflection_point_desc[
i].
id_m;
552 info->RegisterParameterName(
ss.str());
553 info->RegisterParameter(selectivity->inflection_point_desc[
i]);
555 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
558 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
559 << this->inflection_point_desc[
i].
id_m;
560 info->RegisterRandomEffectName(
ss.str());
561 info->RegisterRandomEffect(selectivity->inflection_point_desc[
i]);
564 info->variable_map[this->inflection_point_desc.
id_m] =
569 selectivity->slope_desc[
i] = this->
slope_desc[
i].initial_value_m;
571 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"fixed_effects") {
573 ss <<
"Selectivity." << this->
id <<
".slope_desc."
575 info->RegisterParameterName(
ss.str());
576 info->RegisterParameter(selectivity->slope_desc[
i]);
578 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"random_effects") {
580 ss <<
"Selectivity." << this->
id <<
".slope_desc."
582 info->RegisterRandomEffectName(
ss.str());
583 info->RegisterRandomEffect(selectivity->slope_desc[
i]);
590 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:304
ParameterVector slope_desc
Definition rcpp_selectivity.hpp:313
ParameterVector inflection_point_desc
Definition rcpp_selectivity.hpp:310
DoubleLogisticSelectivityInterface(const DoubleLogisticSelectivityInterface &other)
Construct a new Double Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:327
ParameterVector slope_asc
Definition rcpp_selectivity.hpp:309
virtual double evaluate(double x)
evaluate the double logistic selectivity function
Definition rcpp_selectivity.hpp:344
ParameterVector inflection_point_asc
Definition rcpp_selectivity.hpp:306
virtual uint32_t get_id()
returns the id for the double logistic selectivity interface
Definition rcpp_selectivity.hpp:338
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_selectivity.hpp:434
virtual void finalize()
finalize function. Extracts derived quantities back to the Rcpp interface object from the Information...
Definition rcpp_selectivity.hpp:362
Base class for all interface objects.
Definition rcpp_interface_base.hpp:574
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:579
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:584
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:589
Rcpp interface for logistic selectivity to instantiate the object from R: logistic_selectivity <- met...
Definition rcpp_selectivity.hpp:83
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_selectivity.hpp:143
ParameterVector inflection_point
The index value at which the response reaches 0.5.
Definition rcpp_selectivity.hpp:88
LogisticSelectivityInterface()
The constructor.
Definition rcpp_selectivity.hpp:97
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_selectivity.hpp:194
virtual ~LogisticSelectivityInterface()
The destructor.
Definition rcpp_selectivity.hpp:117
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_selectivity.hpp:123
ParameterVector slope
The width of the curve at the inflection point.
Definition rcpp_selectivity.hpp:92
LogisticSelectivityInterface(const LogisticSelectivityInterface &other)
Construct a new Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:109
virtual double evaluate(double x)
Evaluate selectivity using the logistic function.
Definition rcpp_selectivity.hpp:130
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:142
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:287
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:280
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:155
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:259
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:545
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:239
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:24
fims::Vector< Type > inflection_point_asc
Definition double_logistic.hpp:25
fims::Vector< Type > inflection_point_desc
Definition double_logistic.hpp:31
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:53
LogisticSelectivity class that returns the logistic function value from fims_math.
Definition logistic.hpp:30
fims::Vector< Type > inflection_point
Definition logistic.hpp:32