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];
196 std::map<std::string, std::vector<double>> &se_values) {
198 this->inflection_point.
size(), -999);
203 for (
size_t i = 0;
i < this->inflection_point.
size();
i++) {
206 for (
size_t i = 0;
i < this->slope.
size();
i++) {
218 std::stringstream
ss;
221 ss <<
" \"module_name\":\"Selectivity\",\n";
222 ss <<
" \"module_type\": \"Logistic\",\n";
223 ss <<
" \"module_id\": " << this->
id <<
",\n";
225 ss <<
" \"parameters\": [\n{\n";
226 ss <<
" \"name\": \"inflection_point\",\n";
227 ss <<
" \"id\":" << this->inflection_point.
id_m <<
",\n";
228 ss <<
" \"type\": \"vector\",\n";
229 ss <<
" \"dimensionality\": {\n";
230 ss <<
" \"header\": [null],\n";
231 ss <<
" \"dimensions\": [1]\n},\n";
232 ss <<
" \"values\":" << this->inflection_point <<
"},\n ";
235 ss <<
" \"name\": \"slope\",\n";
236 ss <<
" \"id\":" << this->slope.
id_m <<
",\n";
237 ss <<
" \"type\": \"vector\",\n";
238 ss <<
" \"dimensionality\": {\n";
239 ss <<
" \"header\": [null],\n";
240 ss <<
" \"dimensions\": [1]\n},\n";
241 ss <<
" \"values\":" << this->slope <<
"}]\n";
250 template <
typename Type>
252 std::shared_ptr<fims_info::Information<Type>>
info =
255 std::shared_ptr<fims_popdy::LogisticSelectivity<Type>> selectivity =
256 std::make_shared<fims_popdy::LogisticSelectivity<Type>>();
257 std::stringstream
ss;
259 selectivity->id = this->
id;
260 selectivity->inflection_point.resize(this->inflection_point.
size());
261 for (
size_t i = 0;
i < this->inflection_point.
size();
i++) {
262 selectivity->inflection_point[
i] =
263 this->inflection_point[
i].initial_value_m;
264 if (this->inflection_point[
i].estimation_type_m.
get() ==
267 ss <<
"Selectivity." << this->
id <<
".inflection_point."
268 << this->inflection_point[
i].
id_m;
269 info->RegisterParameterName(
ss.str());
270 info->RegisterParameter(selectivity->inflection_point[
i]);
272 if (this->inflection_point[
i].estimation_type_m.
get() ==
275 ss <<
"Selectivity." << this->
id <<
".inflection_point."
276 << this->inflection_point[
i].
id_m;
277 info->RegisterRandomEffect(selectivity->inflection_point[
i]);
278 info->RegisterRandomEffectName(
ss.str());
281 info->variable_map[this->inflection_point.
id_m] =
284 selectivity->slope.
resize(this->slope.
size());
285 for (
size_t i = 0;
i < this->slope.
size();
i++) {
286 selectivity->slope[
i] = this->slope[
i].initial_value_m;
287 if (this->slope[
i].estimation_type_m.
get() ==
"fixed_effects") {
289 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
290 info->RegisterParameterName(
ss.str());
291 info->RegisterParameter(selectivity->slope[
i]);
293 if (this->slope[
i].estimation_type_m.
get() ==
"random_effects") {
295 ss <<
"Selectivity." << this->
id <<
".slope." << this->slope[
i].
id_m;
296 info->RegisterRandomEffectName(
ss.str());
297 info->RegisterRandomEffect(selectivity->slope[
i]);
300 info->variable_map[this->slope.
id_m] = &(selectivity)->
slope;
303 info->selectivity_models[selectivity->id] = selectivity;
313#ifdef TMBAD_FRAMEWORK
347 std::make_shared<DoubleLogisticSelectivityInterface>(*
this);
378 this->inflection_point_asc[0].initial_value_m;
383 this->inflection_point_desc[0].initial_value_m;
386 return DoubleLogisticSel.
evaluate(x);
396 fims::to_string(this->
id) +
397 " has been finalized already.");
402 std::shared_ptr<fims_info::Information<double>>
info =
408 it =
info->selectivity_models.find(this->
id);
412 fims::to_string(this->
id) +
413 " not found in Information.");
416 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<double>>
sel =
417 std::dynamic_pointer_cast<
421 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
423 this->inflection_point_asc[
i].final_value_m =
424 this->inflection_point_asc[
i].initial_value_m;
426 this->inflection_point_asc[
i].final_value_m =
427 sel->inflection_point_asc[
i];
432 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"constant") {
435 this->
slope_asc[
i].final_value_m = sel->slope_asc[
i];
440 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
442 this->inflection_point_desc[
i].final_value_m =
443 this->inflection_point_desc[
i].initial_value_m;
445 this->inflection_point_desc[
i].final_value_m =
446 sel->inflection_point_desc[
i];
470 std::map<std::string, std::vector<double>> &se_values) {
472 this->inflection_point_asc.
size(), -999);
478 this->inflection_point_desc.
size(), -999);
483 for (
size_t i = 0;
i < this->inflection_point_asc.
size();
i++) {
484 this->inflection_point_asc[
i].uncertainty_m =
488 this->
slope_asc[
i].uncertainty_m = slope_asc_uncertainty[
i];
490 for (
size_t i = 0;
i < this->inflection_point_desc.
size();
i++) {
491 this->inflection_point_desc[
i].uncertainty_m =
495 this->
slope_desc[
i].uncertainty_m = slope_desc_uncertainty[
i];
503 std::stringstream
ss;
506 ss <<
" \"module_name\": \"Selectivity\",\n";
507 ss <<
" \"module_type\": \"DoubleLogistic\",\n";
508 ss <<
" \"module_id\": " << this->
id <<
",\n";
510 ss <<
" \"parameters\":[\n{\n";
511 ss <<
" \"name\": \"inflection_point_asc\",\n";
512 ss <<
" \"id\":" << this->inflection_point_asc.
id_m <<
",\n";
513 ss <<
" \"type\": \"vector\",\n";
514 ss <<
" \"dimensionality\": {\n";
515 ss <<
" \"header\": [null],\n";
516 ss <<
" \"dimensions\": [1]\n},\n";
517 ss <<
" \"values\":" << this->inflection_point_asc <<
"},\n";
520 ss <<
" \"name\": \"slope_asc\",\n";
522 ss <<
" \"type\": \"vector\",\n";
523 ss <<
" \"dimensionality\": {\n";
524 ss <<
" \"header\": [null],\n";
525 ss <<
" \"dimensions\": [1]\n},\n";
529 ss <<
" \"name\": \"inflection_point_desc\",\n";
530 ss <<
" \"id\":" << this->inflection_point_desc.
id_m <<
",\n";
531 ss <<
" \"type\": \"vector\",\n";
532 ss <<
" \"dimensionality\": {\n";
533 ss <<
" \"header\": [null],\n";
534 ss <<
" \"dimensions\": [1]\n},\n";
535 ss <<
" \"values\":" << this->inflection_point_desc <<
"},\n";
538 ss <<
" \"name\": \"slope_desc\",\n";
540 ss <<
" \"type\": \"vector\",\n";
541 ss <<
" \"dimensionality\": {\n";
542 ss <<
" \"header\": [null],\n";
543 ss <<
" \"dimensions\": [1]\n},\n";
553 template <
typename Type>
555 std::shared_ptr<fims_info::Information<Type>>
info =
558 std::shared_ptr<fims_popdy::DoubleLogisticSelectivity<Type>> selectivity =
559 std::make_shared<fims_popdy::DoubleLogisticSelectivity<Type>>();
561 std::stringstream
ss;
563 selectivity->id = this->
id;
564 selectivity->inflection_point_asc.resize(this->inflection_point_asc.
size());
565 for (
size_t i = 0;
i < this->inflection_point_asc.
size();
i++) {
566 selectivity->inflection_point_asc[
i] =
567 this->inflection_point_asc[
i].initial_value_m;
568 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
571 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
572 << this->inflection_point_asc[
i].
id_m;
573 info->RegisterParameterName(
ss.str());
574 info->RegisterParameter(selectivity->inflection_point_asc[
i]);
576 if (this->inflection_point_asc[
i].estimation_type_m.
get() ==
579 ss <<
"Selectivity." << this->
id <<
".inflection_point_asc."
580 << this->inflection_point_asc[
i].
id_m;
581 info->RegisterRandomEffectName(
ss.str());
582 info->RegisterRandomEffect(selectivity->inflection_point_asc[
i]);
585 info->variable_map[this->inflection_point_asc.
id_m] =
590 selectivity->slope_asc[
i] = this->
slope_asc[
i].initial_value_m;
592 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"fixed_effects") {
594 ss <<
"Selectivity." << this->
id <<
".slope_asc."
596 info->RegisterParameterName(
ss.str());
597 info->RegisterParameter(selectivity->slope_asc[
i]);
599 if (this->
slope_asc[
i].estimation_type_m.
get() ==
"random_effects") {
601 ss <<
"Selectivity." << this->
id <<
".slope_asc."
603 info->RegisterRandomEffectName(
ss.str());
604 info->RegisterRandomEffect(selectivity->slope_asc[
i]);
609 selectivity->inflection_point_desc.
resize(
610 this->inflection_point_desc.
size());
611 for (
size_t i = 0;
i < this->inflection_point_desc.
size();
i++) {
612 selectivity->inflection_point_desc[
i] =
613 this->inflection_point_desc[
i].initial_value_m;
615 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
618 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
619 << this->inflection_point_desc[
i].
id_m;
620 info->RegisterParameterName(
ss.str());
621 info->RegisterParameter(selectivity->inflection_point_desc[
i]);
623 if (this->inflection_point_desc[
i].estimation_type_m.
get() ==
626 ss <<
"Selectivity." << this->
id <<
".inflection_point_desc."
627 << this->inflection_point_desc[
i].
id_m;
628 info->RegisterRandomEffectName(
ss.str());
629 info->RegisterRandomEffect(selectivity->inflection_point_desc[
i]);
632 info->variable_map[this->inflection_point_desc.
id_m] =
637 selectivity->slope_desc[
i] = this->
slope_desc[
i].initial_value_m;
639 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"fixed_effects") {
641 ss <<
"Selectivity." << this->
id <<
".slope_desc."
643 info->RegisterParameterName(
ss.str());
644 info->RegisterParameter(selectivity->slope_desc[
i]);
646 if (this->
slope_desc[
i].estimation_type_m.
get() ==
"random_effects") {
648 ss <<
"Selectivity." << this->
id <<
".slope_desc."
650 info->RegisterRandomEffectName(
ss.str());
651 info->RegisterRandomEffect(selectivity->slope_desc[
i]);
658 info->selectivity_models[selectivity->id] = selectivity;
668#ifdef TMBAD_FRAMEWORK
Rcpp interface for logistic selectivity as an S4 object. To instantiate from R: logistic_selectivity ...
Definition rcpp_selectivity.hpp:334
ParameterVector slope_desc
Definition rcpp_selectivity.hpp:343
ParameterVector inflection_point_desc
Definition rcpp_selectivity.hpp:340
DoubleLogisticSelectivityInterface(const DoubleLogisticSelectivityInterface &other)
Construct a new Double Logistic Selectivity Interface object.
Definition rcpp_selectivity.hpp:357
ParameterVector slope_asc
Definition rcpp_selectivity.hpp:339
virtual double evaluate(double x)
evaluate the double logistic selectivity function
Definition rcpp_selectivity.hpp:374
ParameterVector inflection_point_asc
Definition rcpp_selectivity.hpp:336
virtual uint32_t get_id()
returns the id for the double logistic selectivity interface
Definition rcpp_selectivity.hpp:368
virtual void set_uncertainty(std::map< std::string, std::vector< double > > &se_values)
Set uncertainty values for double logistic selectivity parameters.
Definition rcpp_selectivity.hpp:469
virtual std::string to_json()
Convert the data to json representation for the output.
Definition rcpp_selectivity.hpp:502
virtual void finalize()
finalize function. Extracts derived quantities back to the Rcpp interface object from the Information...
Definition rcpp_selectivity.hpp:392
Base class for all interface objects.
Definition rcpp_interface_base.hpp:634
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:639
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:644
void get_se_values(std::string name, std::map< std::string, std::vector< double > > &se_values, fims::Vector< double > &values)
Method to extract standard error values from the se_values working map.
Definition rcpp_interface_base.hpp:672
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:649
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:217
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 void set_uncertainty(std::map< std::string, std::vector< double > > &se_values)
Set uncertainty values for selectivity parameters.
Definition rcpp_selectivity.hpp:195
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:178
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:323
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:316
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:191
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:295
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
Definition fims_vector.hpp:27
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:598
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:279
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