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>>
131 std::make_shared<BevertonHoltRecruitmentInterface>(*
this);
179 BevHolt.logit_steep[0] = this->logit_steep[0].initial_value_m;
180 if (this->logit_steep[0].initial_value_m == 1.0) {
182 "Steepness is subject to a logit transformation. "
183 "Fixing it at 1.0 is not currently possible.");
186 BevHolt.log_rzero[0] = this->log_rzero[0].initial_value_m;
205 fims::to_string(this->
id) +
206 " has been finalized already.");
211 std::shared_ptr<fims_info::Information<double>>
info =
216 it =
info->recruitment_models.find(this->
id);
220 fims::to_string(this->
id) +
221 " not found in Information.");
224 std::shared_ptr<fims_popdy::SRBevertonHolt<double>>
recr =
225 std::dynamic_pointer_cast<fims_popdy::SRBevertonHolt<double>>(
228 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
229 if (this->logit_steep[
i].estimation_type_m.
get() ==
"constant") {
230 this->logit_steep[
i].final_value_m =
231 this->logit_steep[
i].initial_value_m;
233 this->logit_steep[
i].final_value_m =
recr->logit_steep[
i];
239 this->log_rzero[
i].final_value_m = this->log_rzero[
i].initial_value_m;
241 this->log_rzero[
i].final_value_m =
recr->log_rzero[
i];
245 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
246 if (this->log_devs[
i].estimation_type_m.
get() ==
"constant") {
247 this->log_devs[
i].final_value_m = this->log_devs[
i].initial_value_m;
249 this->log_devs[
i].final_value_m =
recr->log_recruit_devs[
i];
253 for (
size_t i = 0;
i < this->log_r.
size();
i++) {
254 if (this->log_r[
i].estimation_type_m.
get() ==
"constant") {
255 this->log_r[
i].final_value_m = this->log_r[
i].initial_value_m;
257 this->log_r[
i].final_value_m =
recr->log_r[
i];
271 std::stringstream
ss;
274 ss <<
" \"module_name\": \"Recruitment\",\n";
275 ss <<
" \"module_type\": \"Beverton-Holt\",\n";
276 ss <<
" \"module_id\": " << this->
id <<
",\n";
278 ss <<
" \"parameters\": [\n{\n";
279 ss <<
" \"name\": \"logit_steep\",\n";
280 ss <<
" \"id\":" << this->logit_steep.
id_m <<
",\n";
281 ss <<
" \"type\": \"vector\",\n";
282 ss <<
" \"dimensionality\": {\n";
283 ss <<
" \"header\": [null],\n";
284 ss <<
" \"dimensions\": [" << this->logit_steep.
size() <<
"]\n},\n";
285 ss <<
" \"values\":" << this->logit_steep <<
"},\n";
288 ss <<
" \"name\": \"log_rzero\",\n";
289 ss <<
" \"id\":" << this->log_rzero.
id_m <<
",\n";
290 ss <<
" \"type\": \"vector\",\n";
291 ss <<
" \"dimensionality\": {\n";
292 ss <<
" \"header\": [null],\n";
293 ss <<
" \"dimensions\": [" << this->log_rzero.
size() <<
"]\n},\n";
294 ss <<
" \"values\":" << this->log_rzero <<
"},\n";
297 ss <<
" \"name\": \"log_devs\",\n";
298 ss <<
" \"id\":" << this->log_devs.
id_m <<
",\n";
299 ss <<
" \"type\": \"vector\",\n";
300 ss <<
" \"dimensionality\": {\n";
301 ss <<
" \"header\": [\"n_years-1\"],\n";
302 ss <<
" \"dimensions\": [" << this->log_devs.
size() <<
"]\n},\n";
303 ss <<
" \"values\":" << this->log_devs <<
"}]\n";
310 template <
typename Type>
312 std::shared_ptr<fims_info::Information<Type>>
info =
315 std::shared_ptr<fims_popdy::SRBevertonHolt<Type>> recruitment =
316 std::make_shared<fims_popdy::SRBevertonHolt<Type>>();
318 std::stringstream
ss;
321 recruitment->id = this->
id;
324 recruitment->logit_steep.resize(this->logit_steep.
size());
325 for (
size_t i = 0;
i < this->logit_steep.
size();
i++) {
326 recruitment->logit_steep[
i] = this->logit_steep[
i].initial_value_m;
328 if (this->logit_steep[
i].estimation_type_m.
get() ==
"fixed_effects") {
330 ss <<
"Recruitment." << this->
id <<
".logit_steep."
331 << this->logit_steep[
i].
id_m;
332 info->RegisterParameterName(
ss.str());
333 info->RegisterParameter(recruitment->logit_steep[
i]);
335 if (this->logit_steep[
i].estimation_type_m.
get() ==
"random_effects") {
337 ss <<
"Recruitment." << this->
id <<
".logit_steep."
338 << this->logit_steep[
i].
id_m;
339 info->RegisterRandomEffectName(
ss.str());
340 info->RegisterRandomEffect(recruitment->logit_steep[
i]);
346 recruitment->log_rzero.
resize(this->log_rzero.
size());
347 for (
size_t i = 0;
i < this->log_rzero.
size();
i++) {
348 recruitment->log_rzero[
i] = this->log_rzero[
i].initial_value_m;
350 if (this->log_rzero[
i].estimation_type_m.
get() ==
"fixed_effects") {
352 ss <<
"Recruitment." << this->
id <<
".log_rzero."
353 << this->log_rzero[
i].
id_m;
354 info->RegisterParameterName(
ss.str());
355 info->RegisterParameter(recruitment->log_rzero[
i]);
357 if (this->log_rzero[
i].estimation_type_m.
get() ==
"random_effects") {
359 ss <<
"Recruitment." << this->
id <<
".log_rzero."
360 << this->log_rzero[
i].
id_m;
361 info->RegisterRandomEffectName(
ss.str());
362 info->RegisterRandomEffect(recruitment->log_rzero[
i]);
367 recruitment->log_recruit_devs.
resize(this->log_devs.
size());
368 for (
size_t i = 0;
i < this->log_devs.
size();
i++) {
369 recruitment->log_recruit_devs[
i] = this->log_devs[
i].initial_value_m;
371 if (this->log_devs[
i].estimation_type_m.
get() ==
"fixed_effects") {
373 ss <<
"Recruitment." << this->
id <<
".log_devs."
374 << this->log_devs[
i].
id_m;
375 info->RegisterParameterName(
ss.str());
376 info->RegisterParameter(recruitment->log_recruit_devs[
i]);
378 if (this->log_devs[
i].estimation_type_m.
get() ==
"random_effects") {
380 ss <<
"Recruitment." << this->
id <<
".log_devs."
381 << this->log_devs[
i].
id_m;
382 info->RegisterRandomEffectName(
ss.str());
383 info->RegisterRandomEffect(recruitment->log_recruit_devs[
i]);
387 info->variable_map[this->log_devs.
id_m] = &(recruitment)->log_recruit_devs;
390 recruitment->log_r.resize(this->log_r.
size());
392 recruitment->log_r[
i] = this->log_r[
i].initial_value_m;
394 if (this->log_r[
i].estimation_type_m.
get() ==
"fixed_effects") {
396 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
397 info->RegisterParameterName(
ss.str());
398 info->RegisterParameter(recruitment->log_r[
i]);
400 if (this->log_r[
i].estimation_type_m.
get() ==
"random_effects") {
402 ss <<
"Recruitment." << this->
id <<
".log_r." << this->log_r[
i].
id_m;
403 info->RegisterRandomEffectName(
ss.str());
404 info->RegisterRandomEffect(recruitment->log_r[
i]);
408 info->variable_map[this->log_r.
id_m] = &(recruitment)->
log_r;
410 recruitment->log_expected_recruitment.
resize(this->n_years.
get() - 1);
412 recruitment->log_expected_recruitment[
i] = 0;
414 info->variable_map[this->log_expected_recruitment.
id_m] =
418 info->recruitment_models[recruitment->id] = recruitment;
448 std::make_shared<LogDevsRecruitmentInterface>(*
this));
479 template <
typename Type>
481 std::shared_ptr<fims_info::Information<Type>>
info =
485 std::make_shared<fims_popdy::LogDevs<Type>>();
521 std::make_shared<LogRRecruitmentInterface>(*
this));
552 template <
typename Type>
554 std::shared_ptr<fims_info::Information<Type>>
info =
558 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:85
ParameterVector log_devs
The natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:104
ParameterVector logit_steep
The logistic transformation of steepness (h; productivity of the population), where the parameter is ...
Definition rcpp_recruitment.hpp:96
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_recruitment.hpp:270
fims_double estimated_log_rzero
The estimate of the natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:120
SharedInt n_years
The number of years.
Definition rcpp_recruitment.hpp:90
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_recruitment.hpp:201
virtual ~BevertonHoltRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:157
void SetRecruitmentProcessID(uint32_t process_id)
Set the unique ID for the recruitment process object.
Definition rcpp_recruitment.hpp:169
BevertonHoltRecruitmentInterface(const BevertonHoltRecruitmentInterface &other)
Construct a new Beverton–Holt Recruitment Interface object.
Definition rcpp_recruitment.hpp:141
ParameterVector log_r
The recruitment random effect parameter on the natural log scale.
Definition rcpp_recruitment.hpp:108
ParameterVector log_rzero
The natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:100
virtual double evaluate_process(size_t pos)
Evaluate recruitment process - returns 0 in this module.
Definition rcpp_recruitment.hpp:195
RealVector estimated_log_devs
The estimates of the natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:124
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:163
fims_double estimated_logit_steep
The estimate of the logit transformation of steepness.
Definition rcpp_recruitment.hpp:116
BevertonHoltRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:129
virtual double evaluate_mean(double spawners, double phi_0)
Evaluates expected recruitment from the stock–recruitment relationship before recruitment-process dev...
Definition rcpp_recruitment.hpp:176
ParameterVector log_expected_recruitment
Expectation of the recruitment process.
Definition rcpp_recruitment.hpp:112
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 Log–Devs to instantiate from R: log_devs <- methods::new(log_devs).
Definition rcpp_recruitment.hpp:441
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:460
virtual double evaluate_mean(double spawners, double phi_0)
Evaluates expected recruitment from the stock–recruitment relationship before recruitment-process dev...
Definition rcpp_recruitment.hpp:465
virtual ~LogDevsRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:454
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–Devs approach.
Definition rcpp_recruitment.hpp:471
LogDevsRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:446
Rcpp interface for Log–R to instantiate from R: log_r <- methods::new(log_r).
Definition rcpp_recruitment.hpp:514
virtual ~LogRRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:527
LogRRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:519
virtual double evaluate_process(size_t pos)
Evaluate recruitment process using the Log–R approach.
Definition rcpp_recruitment.hpp:544
virtual double evaluate_mean(double spawners, double phi_0)
Evaluates expected recruitment from the stock–recruitment relationship before recruitment-process dev...
Definition rcpp_recruitment.hpp:538
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:533
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
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:413
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 double evaluate_mean(double spawners, double phi_0)=0
Evaluates expected recruitment from the stock–recruitment relationship before recruitment-process dev...
virtual ~RecruitmentInterfaceBase()
The destructor.
Definition rcpp_recruitment.hpp:63
SharedInt process_id
The process id of the RecruitmentInterfaceBase object.
Definition rcpp_recruitment.hpp:33
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:29
int get() const
Retrieve the value of the integer.
Definition rcpp_shared_primitive.hpp:127
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:789
#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,...
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