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];
284 std::stringstream
ss;
287 ss <<
" \"module_name\": \"Recruitment\",\n";
288 ss <<
" \"module_type\": \"Beverton-Holt\",\n";
289 ss <<
" \"module_id\": " << this->
id <<
",\n";
291 ss <<
" \"parameters\": [\n{\n";
292 ss <<
" \"name\": \"logit_steep\",\n";
293 ss <<
" \"id\":" << this->logit_steep.
id_m <<
",\n";
294 ss <<
" \"type\": \"vector\",\n";
295 ss <<
" \"dimensionality\": {\n";
296 ss <<
" \"header\": [null],\n";
297 ss <<
" \"dimensions\": [" << this->logit_steep.
size() <<
"]\n},\n";
298 ss <<
" \"values\":" << this->logit_steep <<
"},\n";
301 ss <<
" \"name\": \"log_rzero\",\n";
302 ss <<
" \"id\":" << this->log_rzero.
id_m <<
",\n";
303 ss <<
" \"type\": \"vector\",\n";
304 ss <<
" \"dimensionality\": {\n";
305 ss <<
" \"header\": [null],\n";
306 ss <<
" \"dimensions\": [" << this->log_rzero.
size() <<
"]\n},\n";
307 ss <<
" \"values\":" << this->log_rzero <<
"},\n";
310 ss <<
" \"name\": \"log_devs\",\n";
311 ss <<
" \"id\":" << this->log_devs.
id_m <<
",\n";
312 ss <<
" \"type\": \"vector\",\n";
313 ss <<
" \"dimensionality\": {\n";
314 ss <<
" \"header\": [\"n_years-1\"],\n";
315 ss <<
" \"dimensions\": [" << this->log_devs.
size() <<
"]\n},\n";
316 ss <<
" \"values\":" << this->log_devs <<
"}]\n";
323 template <
typename Type>
325 std::shared_ptr<fims_info::Information<Type>>
info =
328 std::shared_ptr<fims_popdy::SRBevertonHolt<Type>> recruitment =
329 std::make_shared<fims_popdy::SRBevertonHolt<Type>>();
331 std::stringstream
ss;
334 recruitment->id = this->
id;
337 recruitment->logit_steep.resize(this->logit_steep.
size());
338 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
339 recruitment->logit_steep[
i] = this->logit_steep[
i].initial_value_m;
341 if (this->logit_steep[
i].estimation_type_m.
get() ==
"fixed_effects") {
343 ss <<
"Recruitment." << this->
id <<
".logit_steep."
344 << this->logit_steep[
i].
id_m;
345 info->RegisterParameterName(
ss.str());
346 info->RegisterParameter(recruitment->logit_steep[
i]);
348 if (this->logit_steep[
i].estimation_type_m.
get() ==
"random_effects") {
350 ss <<
"Recruitment." << this->
id <<
".logit_steep."
351 << this->logit_steep[
i].
id_m;
352 info->RegisterRandomEffectName(
ss.str());
353 info->RegisterRandomEffect(recruitment->logit_steep[
i]);
359 recruitment->log_rzero.
resize(this->log_rzero.
size());
360 for (
size_t i = 0;
i < this->log_rzero.
size();
i++) {
361 recruitment->log_rzero[
i] = this->log_rzero[
i].initial_value_m;
363 if (this->log_rzero[
i].estimation_type_m.
get() ==
"fixed_effects") {
365 ss <<
"Recruitment." << this->
id <<
".log_rzero."
366 << this->log_rzero[
i].
id_m;
367 info->RegisterParameterName(
ss.str());
368 info->RegisterParameter(recruitment->log_rzero[
i]);
370 if (this->log_rzero[
i].estimation_type_m.
get() ==
"random_effects") {
372 ss <<
"Recruitment." << this->
id <<
".log_rzero."
373 << this->log_rzero[
i].
id_m;
374 info->RegisterRandomEffectName(
ss.str());
375 info->RegisterRandomEffect(recruitment->log_rzero[
i]);
380 recruitment->log_recruit_devs.
resize(this->log_devs.
size());
381 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
382 recruitment->log_recruit_devs[
i] = this->log_devs[
i].initial_value_m;
384 if (this->log_devs[
i].estimation_type_m.
get() ==
"fixed_effects") {
386 ss <<
"Recruitment." << this->
id <<
".log_devs."
387 << this->log_devs[
i].
id_m;
388 info->RegisterParameterName(
ss.str());
389 info->RegisterParameter(recruitment->log_recruit_devs[
i]);
391 if (this->log_devs[
i].estimation_type_m.
get() ==
"random_effects") {
393 ss <<
"Recruitment." << this->
id <<
".log_devs."
394 << this->log_devs[
i].
id_m;
395 info->RegisterRandomEffectName(
ss.str());
396 info->RegisterRandomEffect(recruitment->log_recruit_devs[
i]);
400 info->variable_map[this->log_devs.
id_m] = &(recruitment)->log_recruit_devs;
403 recruitment->log_r.resize(this->log_r.
size());
405 recruitment->log_r[
i] = this->log_r[
i].initial_value_m;
407 if (this->log_r[
i].estimation_type_m.
get() ==
"fixed_effects") {
409 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
410 info->RegisterParameterName(
ss.str());
411 info->RegisterParameter(recruitment->log_r[
i]);
413 if (this->log_r[
i].estimation_type_m.
get() ==
"random_effects") {
415 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
416 info->RegisterRandomEffectName(
ss.str());
417 info->RegisterRandomEffect(recruitment->log_r[
i]);
421 info->variable_map[this->log_r.
id_m] = &(recruitment)->
log_r;
423 recruitment->log_expected_recruitment.
resize(this->n_years.
get() + 1);
425 recruitment->log_expected_recruitment[
i] = 0;
427 info->variable_map[this->log_expected_recruitment.
id_m] =
431 info->recruitment_models[recruitment->id] = recruitment;
461 std::make_shared<LogDevsRecruitmentInterface>(*
this));
494 template <
typename Type>
496 std::shared_ptr<fims_info::Information<Type>>
info =
500 std::make_shared<fims_popdy::LogDevs<Type>>();
536 std::make_shared<LogRRecruitmentInterface>(*
this));
569 template <
typename Type>
571 std::shared_ptr<fims_info::Information<Type>>
info =
575 std::make_shared<fims_popdy::LogR<Type>>();
Rcpp interface for Beverton–Holt to instantiate from R: beverton_holt <- methods::new(beverton_holt).
Definition rcpp_recruitment.hpp:94
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:283
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: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 Log–Devs to instantiate from R: log_devs <- methods::new(log_devs).
Definition rcpp_recruitment.hpp:454
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:473
virtual ~LogDevsRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:467
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–Devs approach.
Definition rcpp_recruitment.hpp:486
LogDevsRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:459
virtual double evaluate_mean(double spawners, double ssbzero)
Evaluate mean - returns empty function for this module.
Definition rcpp_recruitment.hpp:480
Rcpp interface for Log–R to instantiate from R: log_r <- methods::new(log_r).
Definition rcpp_recruitment.hpp:529
virtual ~LogRRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:542
LogRRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:534
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–R approach.
Definition rcpp_recruitment.hpp:561
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:548
virtual double evaluate_mean(double spawners, double ssbzero)
Evaluate mean - returns empty function for this module.
Definition rcpp_recruitment.hpp:555
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
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:374
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
#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,...
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:28
fims::Vector< Type > logit_steep
Definition sr_beverton_holt.hpp:33