10#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_RECRUITMENT_HPP
11#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_RECRUITMENT_HPP
39 static std::map<uint32_t, std::shared_ptr<RecruitmentInterfaceBase>>
46 this->
id = RecruitmentInterfaceBase::id_g++;
124 std::make_shared<BevertonHoltRecruitmentInterface>(*
this);
172 BevHolt.
logit_steep[0] = this->logit_steep[0].initial_value_m;
173 if (this->logit_steep[0].initial_value_m == 1.0) {
175 "Steepness is subject to a logit transformation. "
176 "Fixing it at 1.0 is not currently possible.");
179 BevHolt.
log_rzero[0] = this->log_rzero[0].initial_value_m;
193 " has been finalized already.");
198 std::shared_ptr<fims_info::Information<double>> info =
208 " not found in Information.");
211 std::shared_ptr<fims_popdy::SRBevertonHolt<double>> recr =
212 std::dynamic_pointer_cast<fims_popdy::SRBevertonHolt<double>>(
215 for (
size_t i = 0; i < this->logit_steep.
size(); i++) {
216 if (this->logit_steep[i].estimation_type_m.
get() ==
"constant") {
217 this->logit_steep[i].final_value_m =
218 this->logit_steep[i].initial_value_m;
220 this->logit_steep[i].final_value_m = recr->logit_steep[i];
224 for (
size_t i = 0; i <
log_rzero.size(); i++) {
225 if (
log_rzero[i].estimation_type_m.get() ==
"constant") {
226 this->log_rzero[i].final_value_m = this->log_rzero[i].initial_value_m;
228 this->log_rzero[i].final_value_m = recr->log_rzero[i];
232 for (
size_t i = 0; i < this->log_devs.
size(); i++) {
233 if (this->log_devs[i].estimation_type_m.
get() ==
"constant") {
234 this->log_devs[i].final_value_m = this->log_devs[i].initial_value_m;
236 this->log_devs[i].final_value_m = recr->log_recruit_devs[i];
240 for (
size_t i = 0; i < this->log_r.
size(); i++) {
241 if (this->log_r[i].estimation_type_m.
get() ==
"constant") {
242 this->log_r[i].final_value_m = this->log_r[i].initial_value_m;
244 this->log_r[i].final_value_m = recr->log_r[i];
258 std::stringstream ss;
261 ss <<
" \"module_name\": \"Recruitment\",\n";
262 ss <<
" \"module_type\": \"Beverton-Holt\",\n";
263 ss <<
" \"module_id\": " << this->
id <<
",\n";
265 ss <<
" \"parameters\": [\n{\n";
266 ss <<
" \"name\": \"logit_steep\",\n";
267 ss <<
" \"id\":" << this->logit_steep.
id_m <<
",\n";
268 ss <<
" \"type\": \"vector\",\n";
269 ss <<
" \"dimensionality\": {\n";
270 ss <<
" \"header\": [null],\n";
271 ss <<
" \"dimensions\": [" << this->logit_steep.
size() <<
"]\n},\n";
272 ss <<
" \"values\":" << this->logit_steep <<
"},\n";
275 ss <<
" \"name\": \"log_rzero\",\n";
276 ss <<
" \"id\":" << this->log_rzero.
id_m <<
",\n";
277 ss <<
" \"type\": \"vector\",\n";
278 ss <<
" \"dimensionality\": {\n";
279 ss <<
" \"header\": [null],\n";
280 ss <<
" \"dimensions\": [" << this->log_rzero.
size() <<
"]\n},\n";
281 ss <<
" \"values\":" << this->log_rzero <<
"},\n";
284 ss <<
" \"name\": \"log_devs\",\n";
285 ss <<
" \"id\":" << this->log_devs.
id_m <<
",\n";
286 ss <<
" \"type\": \"vector\",\n";
287 ss <<
" \"dimensionality\": {\n";
288 ss <<
" \"header\": [\"n_years-1\"],\n";
289 ss <<
" \"dimensions\": [" << this->log_devs.
size() <<
"]\n},\n";
290 ss <<
" \"values\":" << this->log_devs <<
"}]\n";
297 template <
typename Type>
298 bool add_to_fims_tmb_internal() {
299 std::shared_ptr<fims_info::Information<Type>> info =
302 std::shared_ptr<fims_popdy::SRBevertonHolt<Type>> recruitment =
303 std::make_shared<fims_popdy::SRBevertonHolt<Type>>();
305 std::stringstream ss;
308 recruitment->id = this->
id;
311 recruitment->logit_steep.resize(this->logit_steep.
size());
312 for (
size_t i = 0; i < this->logit_steep.
size(); i++) {
313 recruitment->logit_steep[i] = this->logit_steep[i].initial_value_m;
315 if (this->logit_steep[i].estimation_type_m.
get() ==
"fixed_effects") {
317 ss <<
"Recruitment." << this->
id <<
".logit_steep."
318 << this->logit_steep[i].
id_m;
319 info->RegisterParameterName(ss.str());
320 info->RegisterParameter(recruitment->logit_steep[i]);
322 if (this->
logit_steep[i].estimation_type_m.get() ==
"random_effects") {
324 ss <<
"Recruitment." << this->
id <<
".logit_steep."
326 info->RegisterRandomEffectName(ss.str());
327 info->RegisterRandomEffect(recruitment->logit_steep[i]);
333 recruitment->log_rzero.resize(this->
log_rzero.size());
334 for (
size_t i = 0; i < this->
log_rzero.size(); i++) {
335 recruitment->log_rzero[i] = this->
log_rzero[i].initial_value_m;
337 if (this->
log_rzero[i].estimation_type_m.get() ==
"fixed_effects") {
339 ss <<
"Recruitment." << this->
id <<
".log_rzero."
341 info->RegisterParameterName(ss.str());
342 info->RegisterParameter(recruitment->log_rzero[i]);
344 if (this->
log_rzero[i].estimation_type_m.get() ==
"random_effects") {
346 ss <<
"Recruitment." << this->
id <<
".log_rzero."
348 info->RegisterRandomEffectName(ss.str());
349 info->RegisterRandomEffect(recruitment->log_rzero[i]);
354 recruitment->log_recruit_devs.resize(this->
log_devs.size());
355 for (
size_t i = 0; i < this->
log_devs.size(); i++) {
356 recruitment->log_recruit_devs[i] = this->
log_devs[i].initial_value_m;
358 if (this->
log_devs[i].estimation_type_m.get() ==
"fixed_effects") {
360 ss <<
"Recruitment." << this->
id <<
".log_devs."
362 info->RegisterParameterName(ss.str());
363 info->RegisterParameter(recruitment->log_recruit_devs[i]);
365 if (this->
log_devs[i].estimation_type_m.get() ==
"random_effects") {
367 ss <<
"Recruitment." << this->
id <<
".log_devs."
369 info->RegisterRandomEffectName(ss.str());
370 info->RegisterRandomEffect(recruitment->log_recruit_devs[i]);
374 info->variable_map[this->
log_devs.id_m] = &(recruitment)->log_recruit_devs;
377 recruitment->log_r.resize(this->
log_r.size());
378 for (
size_t i = 0; i <
log_r.size(); i++) {
379 recruitment->log_r[i] = this->
log_r[i].initial_value_m;
381 if (this->
log_r[i].estimation_type_m.get() ==
"fixed_effects") {
383 ss <<
"Recruitment." << this->
id <<
".log_r." << this->
log_r[i].id_m;
384 info->RegisterParameterName(ss.str());
385 info->RegisterParameter(recruitment->log_r[i]);
387 if (this->
log_r[i].estimation_type_m.get() ==
"random_effects") {
389 ss <<
"Recruitment." << this->
id <<
".log_r." << this->
log_r[i].id_m;
390 info->RegisterRandomEffectName(ss.str());
391 info->RegisterRandomEffect(recruitment->log_r[i]);
395 info->variable_map[this->
log_r.id_m] = &(recruitment)->
log_r;
397 recruitment->log_expected_recruitment.resize(this->
n_years.get() - 1);
398 for (
size_t i = 0; i < static_cast<size_t>(this->
n_years.get() - 1); i++) {
399 recruitment->log_expected_recruitment[i] = 0;
405 info->recruitment_models[recruitment->id] = recruitment;
415 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
416 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
435 std::make_shared<LogDevsRecruitmentInterface>(*
this));
456 template <
typename Type>
457 bool add_to_fims_tmb_internal() {
458 std::shared_ptr<fims_info::Information<Type>> info =
461 std::shared_ptr<fims_popdy::LogDevs<Type>> recruitment_process =
462 std::make_shared<fims_popdy::LogDevs<Type>>();
464 recruitment_process->id = this->
id;
467 info->recruitment_process_models[recruitment_process->id] =
478 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
479 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
498 std::make_shared<LogRRecruitmentInterface>(*
this));
519 template <
typename Type>
520 bool add_to_fims_tmb_internal() {
521 std::shared_ptr<fims_info::Information<Type>> info =
524 std::shared_ptr<fims_popdy::LogR<Type>> recruitment_process =
525 std::make_shared<fims_popdy::LogR<Type>>();
527 recruitment_process->id = this->
id;
530 info->recruitment_process_models[recruitment_process->id] =
541 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
542 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
VariableVector log_rzero
The natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:93
VariableVector log_expected_recruitment
Expectation of the recruitment process.
Definition rcpp_recruitment.hpp:105
virtual std::string to_json()
Converts the data to json representation for the output.
Definition rcpp_recruitment.hpp:257
fims_double estimated_log_rzero
The estimate of the natural log of recruitment at unfished biomass.
Definition rcpp_recruitment.hpp:113
SharedInt n_years
The number of years.
Definition rcpp_recruitment.hpp:83
virtual void finalize()
Extracts derived quantities back to the Rcpp interface object from the Information object.
Definition rcpp_recruitment.hpp:188
VariableVector log_devs
The natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:97
virtual ~BevertonHoltRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:150
void SetRecruitmentProcessID(uint32_t process_id)
Set the unique ID for the recruitment process object.
Definition rcpp_recruitment.hpp:162
BevertonHoltRecruitmentInterface(const BevertonHoltRecruitmentInterface &other)
Construct a new Beverton–Holt Recruitment Interface object.
Definition rcpp_recruitment.hpp:134
RealVector estimated_log_devs
The estimates of the natural log of recruitment deviations.
Definition rcpp_recruitment.hpp:117
VariableVector log_r
The recruitment random effect parameter on the natural log scale.
Definition rcpp_recruitment.hpp:101
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:156
fims_double estimated_logit_steep
The estimate of the logit transformation of steepness.
Definition rcpp_recruitment.hpp:109
BevertonHoltRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:122
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:169
VariableVector logit_steep
The logistic transformation of steepness (h; productivity of the population), where the parameter is ...
Definition rcpp_recruitment.hpp:89
Base class for all interface objects.
Definition rcpp_interface_base.hpp:655
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:660
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:665
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:670
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:447
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:452
virtual ~LogDevsRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:441
LogDevsRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:433
virtual ~LogRRecruitmentInterface()
The destructor.
Definition rcpp_recruitment.hpp:504
LogRRecruitmentInterface()
The constructor.
Definition rcpp_recruitment.hpp:496
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:515
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_recruitment.hpp:510
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:431
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 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
An Rcpp interface class that defines the VariableVector class.
Definition rcpp_interface_base.hpp:143
Variable & get(size_t pos)
An internal accessor for calling a position of a VariableVector from R.
Definition rcpp_interface_base.hpp:266
uint32_t id_m
The local ID of the Variable object.
Definition rcpp_interface_base.hpp:156
size_t size()
Returns the size of a VariableVector.
Definition rcpp_interface_base.hpp:287
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
std::string to_string(T v)
Definition def.hpp:735
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...
SharedReal fims_double
An alias for the SharedReal class.
Definition rcpp_shared_primitive.hpp:2115
Includes any .hpp files within the subfolders so that only this file needs to included in include sta...
fims::Vector< Type > log_rzero
Definition recruitment_base.hpp:35
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
virtual const Type evaluate_mean(const Type &spawners, const Type &phi_0)
Evaluates expected recruitment from the stock–recruitment relationship before recruitment-process dev...
Definition sr_beverton_holt.hpp:49