Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
Loading...
Searching...
No Matches
recruitment.hpp
Go to the documentation of this file.
1#ifndef RECRUITMENT_HPP
2#define RECRUITMENT_HPP
3
4/**
5 * @brief Calculates the recruitment for a given species and year.
6 *
7 * @param srr_fun Stock-recruit relationship (SRR) type: 0 = random about mean (the
8 * default), 2 = Beverton-Holt, 4 = Ricker. Codes 1, 3 and 5 are retired
9 * aliases of 0, 2 and 4 that compute the same curve here; build_srr()
10 * refuses them, because the environmental effect now comes from a
11 * recruitment linkage on R0 (code 1) or alpha (3 and 5).
12 * @param R0 Equilibrium or mean recruitment level (thousands of fish); read by the
13 * random-about-mean forms only.
14 * @param ssb Female spawning-stock biomass (mt), lagged by minage by the caller.
15 * @param srr_alpha SRR productivity parameter.
16 * @param srr_beta SRR density-dependence parameter.
17 * @param rec_dev Annual recruitment deviation, log scale.
18 * @param spr0 Equilibrium spawning biomass per recruit at F = 0 (M of year 1).
19 * Unused here: both curves are functions of srr_alpha, srr_beta and ssb,
20 * and the caller derives the unfished recruitment they imply -- (alpha -
21 * 1/spr0)/beta for Beverton-Holt, a posfun()-guarded log for Ricker.
22 * @return Expected recruitment (thousands of fish).
23 */
24template <class Type>
25Type calculate_recruitment(int srr_fun,
26 Type R0,
27 Type ssb,
28 Type srr_alpha,
29 Type srr_beta,
30 Type rec_dev,
31 Type spr0) {
32 Type R = 0;
33
34 switch(srr_fun) {
35 case 0: // Random about mean
36 R = R0 * exp(rec_dev);
37 break;
38
39 case 1: // Retired code: the same mean form as 0
40 R = R0 * exp(rec_dev);
41 break;
42
43 case 2: // Beverton-Holt
44 R = srr_alpha * ssb * exp(rec_dev) / (Type(1.0) + srr_beta * ssb);
45 break;
46
47 case 3: // Retired code: the same Beverton-Holt curve as 2
48 R = srr_alpha * ssb * exp(rec_dev) / (Type(1.0) + srr_beta * ssb);
49 break;
50
51 case 4: // Ricker
52 // Beta is estimated divided by 1,000,000 for estimation stability, so the fitted beta
53 // is 1e6 times the curve's coefficient.
54 R = srr_alpha * ssb * exp(-srr_beta * ssb / Type(1000000.0)) * exp(rec_dev);
55 break;
56
57 case 5: // Retired code: the same Ricker curve as 4
58 R = srr_alpha * ssb * exp(-srr_beta * ssb / Type(1000000.0)) * exp(rec_dev);
59 break;
60
61 default:
62 error("Invalid 'srr_fun'");
63 }
64
65 return R;
66}
67
68#endif
Type calculate_recruitment(int srr_fun, Type R0, Type ssb, Type srr_alpha, Type srr_beta, Type rec_dev, Type spr0)
Calculates the recruitment for a given species and year.