10#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_RECRUITMENT_HPP
11#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_RECRUITMENT_HPP
13#include "../../../population_dynamics/recruitment/recruitment.hpp"
39 static std::map<uint32_t, std::shared_ptr<RecruitmentInterfaceBase>>
87std::map<uint32_t, std::shared_ptr<RecruitmentInterfaceBase>>
140 std::make_shared<BevertonHoltRecruitmentInterface>(*
this);
192 BevHolt.logit_steep[0] = this->logit_steep[0].initial_value_m;
193 if (this->logit_steep[0].initial_value_m == 1.0) {
195 "Steepness is subject to a logit transformation. "
196 "Fixing it at 1.0 is not currently possible.");
199 BevHolt.log_rzero[0] = this->log_rzero[0].initial_value_m;
218 fims::to_string(this->
id) +
219 " has been finalized already.");
224 std::shared_ptr<fims_info::Information<double>>
info =
229 it =
info->recruitment_models.find(this->
id);
233 fims::to_string(this->
id) +
234 " not found in Information.");
237 std::shared_ptr<fims_popdy::SRBevertonHolt<double>>
recr =
238 std::dynamic_pointer_cast<fims_popdy::SRBevertonHolt<double>>(
241 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
242 if (this->logit_steep[
i].estimation_type_m.
get() ==
"constant") {
243 this->logit_steep[
i].final_value_m =
244 this->logit_steep[
i].initial_value_m;
246 this->logit_steep[
i].final_value_m =
recr->logit_steep[
i];
252 this->log_rzero[
i].final_value_m = this->log_rzero[
i].initial_value_m;
254 this->log_rzero[
i].final_value_m =
recr->log_rzero[
i];
258 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
259 if (this->log_devs[
i].estimation_type_m.
get() ==
"constant") {
260 this->log_devs[
i].final_value_m = this->log_devs[
i].initial_value_m;
262 this->log_devs[
i].final_value_m =
recr->log_recruit_devs[
i];
266 for (
size_t i = 0;
i < this->log_r.
size();
i++) {
267 if (this->log_r[
i].estimation_type_m.
get() ==
"constant") {
268 this->log_r[
i].final_value_m = this->log_r[
i].initial_value_m;
270 this->log_r[
i].final_value_m =
recr->log_r[
i];
282 std::map<std::string, std::vector<double>> &se_values) {
292 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
295 for (
size_t i = 0;
i < this->log_rzero.
size();
i++) {
298 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
311 std::stringstream
ss;
314 ss <<
" \"module_name\": \"Recruitment\",\n";
315 ss <<
" \"module_type\": \"Beverton-Holt\",\n";
316 ss <<
" \"module_id\": " << this->
id <<
",\n";
318 ss <<
" \"parameters\": [\n{\n";
319 ss <<
" \"name\": \"logit_steep\",\n";
320 ss <<
" \"id\":" << this->logit_steep.
id_m <<
",\n";
321 ss <<
" \"type\": \"vector\",\n";
322 ss <<
" \"dimensionality\": {\n";
323 ss <<
" \"header\": [null],\n";
324 ss <<
" \"dimensions\": [" << this->logit_steep.
size() <<
"]\n},\n";
325 ss <<
" \"values\":" << this->logit_steep <<
"},\n";
328 ss <<
" \"name\": \"log_rzero\",\n";
329 ss <<
" \"id\":" << this->log_rzero.
id_m <<
",\n";
330 ss <<
" \"type\": \"vector\",\n";
331 ss <<
" \"dimensionality\": {\n";
332 ss <<
" \"header\": [null],\n";
333 ss <<
" \"dimensions\": [" << this->log_rzero.
size() <<
"]\n},\n";
334 ss <<
" \"values\":" << this->log_rzero <<
"},\n";
337 ss <<
" \"name\": \"log_devs\",\n";
338 ss <<
" \"id\":" << this->log_devs.
id_m <<
",\n";
339 ss <<
" \"type\": \"vector\",\n";
340 ss <<
" \"dimensionality\": {\n";
341 ss <<
" \"header\": [\"n_years-1\"],\n";
342 ss <<
" \"dimensions\": [" << this->log_devs.
size() <<
"]\n},\n";
343 ss <<
" \"values\":" << this->log_devs <<
"}]\n";
350 template <
typename Type>
352 std::shared_ptr<fims_info::Information<Type>>
info =
355 std::shared_ptr<fims_popdy::SRBevertonHolt<Type>> recruitment =
356 std::make_shared<fims_popdy::SRBevertonHolt<Type>>();
358 std::stringstream
ss;
361 recruitment->id = this->
id;
364 recruitment->logit_steep.resize(this->logit_steep.
size());
365 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
366 recruitment->logit_steep[
i] = this->logit_steep[
i].initial_value_m;
368 if (this->logit_steep[
i].estimation_type_m.
get() ==
"fixed_effects") {
370 ss <<
"Recruitment." << this->
id <<
".logit_steep."
371 << this->logit_steep[
i].
id_m;
372 info->RegisterParameterName(
ss.str());
373 info->RegisterParameter(recruitment->logit_steep[
i]);
375 if (this->logit_steep[
i].estimation_type_m.
get() ==
"random_effects") {
377 ss <<
"Recruitment." << this->
id <<
".logit_steep."
378 << this->logit_steep[
i].
id_m;
379 info->RegisterRandomEffectName(
ss.str());
380 info->RegisterRandomEffect(recruitment->logit_steep[
i]);
386 recruitment->log_rzero.
resize(this->log_rzero.
size());
387 for (
size_t i = 0;
i < this->log_rzero.
size();
i++) {
388 recruitment->log_rzero[
i] = this->log_rzero[
i].initial_value_m;
390 if (this->log_rzero[
i].estimation_type_m.
get() ==
"fixed_effects") {
392 ss <<
"Recruitment." << this->
id <<
".log_rzero."
393 << this->log_rzero[
i].
id_m;
394 info->RegisterParameterName(
ss.str());
395 info->RegisterParameter(recruitment->log_rzero[
i]);
397 if (this->log_rzero[
i].estimation_type_m.
get() ==
"random_effects") {
399 ss <<
"Recruitment." << this->
id <<
".log_rzero."
400 << this->log_rzero[
i].
id_m;
401 info->RegisterRandomEffectName(
ss.str());
402 info->RegisterRandomEffect(recruitment->log_rzero[
i]);
407 recruitment->log_recruit_devs.
resize(this->log_devs.
size());
408 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
409 recruitment->log_recruit_devs[
i] = this->log_devs[
i].initial_value_m;
411 if (this->log_devs[
i].estimation_type_m.
get() ==
"fixed_effects") {
413 ss <<
"Recruitment." << this->
id <<
".log_devs."
414 << this->log_devs[
i].
id_m;
415 info->RegisterParameterName(
ss.str());
416 info->RegisterParameter(recruitment->log_recruit_devs[
i]);
418 if (this->log_devs[
i].estimation_type_m.
get() ==
"random_effects") {
420 ss <<
"Recruitment." << this->
id <<
".log_devs."
421 << this->log_devs[
i].
id_m;
422 info->RegisterRandomEffectName(
ss.str());
423 info->RegisterRandomEffect(recruitment->log_recruit_devs[
i]);
427 info->variable_map[this->log_devs.
id_m] = &(recruitment)->log_recruit_devs;
430 recruitment->log_r.resize(this->log_r.
size());
432 recruitment->log_r[
i] = this->log_r[
i].initial_value_m;
434 if (this->log_r[
i].estimation_type_m.
get() ==
"fixed_effects") {
436 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
437 info->RegisterParameterName(
ss.str());
438 info->RegisterParameter(recruitment->log_r[
i]);
440 if (this->log_r[
i].estimation_type_m.
get() ==
"random_effects") {
442 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
443 info->RegisterRandomEffectName(
ss.str());
444 info->RegisterRandomEffect(recruitment->log_r[
i]);
448 info->variable_map[this->log_r.
id_m] = &(recruitment)->
log_r;
450 recruitment->log_expected_recruitment.
resize(this->n_years.
get() + 1);
452 recruitment->log_expected_recruitment[
i] = 0;
454 info->variable_map[this->log_expected_recruitment.
id_m] =
458 info->recruitment_models[recruitment->id] = recruitment;
468#ifdef TMBAD_FRAMEWORK
495 std::make_shared<LogDevsRecruitmentInterface>(*
this));
528 template <
typename Type>
530 std::shared_ptr<fims_info::Information<Type>>
info =
534 std::make_shared<fims_popdy::LogDevs<Type>>();
550#ifdef TMBAD_FRAMEWORK
577 std::make_shared<LogRRecruitmentInterface>(*
this));
610 template <
typename Type>
612 std::shared_ptr<fims_info::Information<Type>>
info =
616 std::make_shared<fims_popdy::LogR<Type>>();
632#ifdef TMBAD_FRAMEWORK
Rcpp interface for Beverton–Holt to instantiate from R: beverton_holt <- methods::new(beverton_holt).
Definition rcpp_recruitment.hpp:94
virtual void set_uncertainty(std::map< std::string, std::vector< double > > &se_values)
Sets the uncertainty values for the parameters from the standard error values passed from R.
Definition rcpp_recruitment.hpp:281
ParameterVector log_devs
The natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:113
ParameterVector logit_steep
The logistic transformation of steepness (h; productivity of the population), where the parameter is ...
Definition rcpp_recruitment.hpp:105
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_recruitment.hpp:310
fims_double estimated_log_rzero
The estimate of the natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:129
SharedInt n_years
The number of years.
Definition rcpp_recruitment.hpp:99
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_recruitment.hpp:214
virtual ~BevertonHoltRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:166
void SetRecruitmentProcessID(uint32_t process_id)
Set the unique ID for the recruitment process object.
Definition rcpp_recruitment.hpp:178
BevertonHoltRecruitmentInterface(const BevertonHoltRecruitmentInterface &other)
Construct a new Beverton–Holt Recruitment Interface object.
Definition rcpp_recruitment.hpp:150
ParameterVector log_r
The recruitment random effect parameter on the natural log scale.
Definition rcpp_recruitment.hpp:117
ParameterVector log_rzero
The natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:109
virtual double evaluate_process(size_t pos)
Evaluate recruitment process - returns 0 in this module.
Definition rcpp_recruitment.hpp:208
RealVector estimated_log_devs
The estimates of the natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:133
virtual double evaluate_mean(double spawners, double ssbzero)
Evaluate recruitment using the Beverton–Holt stock–recruitment relationship.
Definition rcpp_recruitment.hpp:189
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:172
fims_double estimated_logit_steep
The estimate of the logit transformation of steepness.
Definition rcpp_recruitment.hpp:125
BevertonHoltRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:138
ParameterVector log_expected_recruitment
Expectation of the recruitment process.
Definition rcpp_recruitment.hpp:121
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 Log–Devs to instantiate from R: log_devs <- methods::new(log_devs).
Definition rcpp_recruitment.hpp:488
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:507
virtual ~LogDevsRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:501
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–Devs approach.
Definition rcpp_recruitment.hpp:520
LogDevsRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:493
virtual double evaluate_mean(double spawners, double ssbzero)
Evaluate mean - returns empty function for this module.
Definition rcpp_recruitment.hpp:514
Rcpp interface for Log–R to instantiate from R: log_r <- methods::new(log_r).
Definition rcpp_recruitment.hpp:570
virtual ~LogRRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:583
LogRRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:575
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–R approach.
Definition rcpp_recruitment.hpp:602
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:589
virtual double evaluate_mean(double spawners, double ssbzero)
Evaluate mean - returns empty function for this module.
Definition rcpp_recruitment.hpp:596
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
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:434
Rcpp interface that serves as the parent class for Rcpp recruitment interfaces. This type should be i...
Definition rcpp_recruitment.hpp:20
virtual double evaluate_process(size_t pos)=0
A method for each child recruitment process interface object to inherit so each recruitment process o...
uint32_t id
The local id of the RecruitmentInterfaceBase object.
Definition rcpp_recruitment.hpp:29
virtual uint32_t get_id()=0
Get the ID for the child recruitment interface objects to inherit.
virtual ~RecruitmentInterfaceBase()
The destructor.
Definition rcpp_recruitment.hpp:63
SharedInt process_id
The process id of the RecruitmentInterfaceBase object.
Definition rcpp_recruitment.hpp:33
virtual double evaluate_mean(double spawners, double ssbzero)=0
A method for each child recruitment interface object to inherit so each recruitment option can have a...
RecruitmentInterfaceBase(const RecruitmentInterfaceBase &other)
Construct a new Recruitment Interface Base object.
Definition rcpp_recruitment.hpp:57
RecruitmentInterfaceBase()
The constructor.
Definition rcpp_recruitment.hpp:45
static uint32_t id_g
The static id of the RecruitmentInterfaceBase object.
Definition rcpp_recruitment.hpp:25
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
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:24
int get() const
Retrieve the value of the integer.
Definition rcpp_shared_primitive.hpp:122
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:784
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,...
Log Devs class that returns the log of the input added to the log of the recruitment deviations.
Definition log_devs.hpp:21
virtual const Type evaluate_process(size_t pos)
Log of the recruitment deviations approach to adding error to expected recruitment.
Definition log_devs.hpp:34
Log Devs class that returns the log of the input added to the log of the recruitment deviations.
Definition log_r.hpp:21
virtual const Type evaluate_process(size_t pos)
Log of recruitment approach to adding error to expected recruitment.
Definition log_r.hpp:34
BevertonHolt class that returns the Beverton–Holt stock–recruitment from fims_math.
Definition sr_beverton_holt.hpp:26
fims::Vector< Type > logit_steep
Definition sr_beverton_holt.hpp:31