-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-mw_gadget3.script1.baseline
173 lines (131 loc) · 5.52 KB
/
test-mw_gadget3.script1.baseline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
library(gadget3)
library(gadgetutils)
actions <- list()
data_path <- ""
# Create area definitions ####################
area_names <- structure(1:2, names = c("IV4", "IV5"))
# Create time definitions ####################
actions_time <- list(
g3a_time(
1999L, 2004L,
step_lengths = c(3L, 3L, 3L, 3L)),
NULL)
actions <- c(actions, actions_time)
# Create stock definition for ling ####################
ling <- g3_stock("ling", seq(30, 50, 10)) |>
g3s_livesonareas(area_names[c("IV4", "IV5")]) |>
g3s_age(3L, 5L)
actions_ling <- list(
g3a_growmature(ling, g3a_grow_impl_bbinom(
maxlengthgroupgrowth = 2L)),
g3a_naturalmortality(ling),
g3a_initialconditions_normalcv(ling),
g3a_renewal_normalparam(ling,
run_step = NULL),
g3a_age(ling),
NULL)
actions_likelihood_ling <- list(
g3l_understocking(list(ling), weight = 1e+08, nll_breakdown = TRUE),
NULL)
actions <- c(actions, actions_ling, actions_likelihood_ling)
# Create commercial fleet definition for comm ####################
comm <- g3_fleet("comm") |> g3s_livesonareas(area_names[c("IV4", "IV5")])
actions_comm <- list(
g3a_predate_fleet(
comm,
list(ling),
suitabilities = g3_suitability_exponentiall50(),
catchability_f = g3a_predate_catchability_totalfleet(g3_timeareadata("landings_comm", landings_comm, "weight", areas = area_names)) ),
NULL)
actions_likelihood_comm <- list(
g3l_catchdistribution(
"ldist_comm",
ldist_comm,
fleets = list(comm),
stocks = list(ling),
function_f = g3l_distribution_sumofsquares(),
area_group = area_names,
report = TRUE,
nll_breakdown = TRUE),
NULL)
actions <- c(actions, actions_comm, actions_likelihood_comm)
# Create commercial fleet definition for surv ####################
surv <- g3_fleet("surv") |> g3s_livesonareas(area_names[c("IV4", "IV5")])
actions_surv <- list(
g3a_predate_fleet(
surv,
list(ling),
suitabilities = g3_suitability_exponentiall50(),
catchability_f = g3a_predate_catchability_totalfleet(g3_timeareadata("landings_surv", landings_surv, "weight", areas = area_names)) ),
NULL)
actions_likelihood_surv <- list(
g3l_catchdistribution(
"aldist_surv",
aldist_surv,
fleets = list(surv),
stocks = list(ling),
function_f = g3l_distribution_sumofsquares(),
area_group = area_names,
report = TRUE,
nll_breakdown = TRUE),
NULL)
actions <- c(actions, actions_surv, actions_likelihood_surv)
# Create survey fleet definition for acoustic ####################
acoustic <- g3_fleet("acoustic") |> g3s_livesonareas(area_names[c("IV4", "IV5")])
actions_acoustic <- list(
g3a_predate_fleet(
acoustic,
list(ling),
suitabilities = g3_suitability_exponentiall50(),
catchability_f = g3a_predate_catchability_totalfleet(1) ),
NULL)
actions_likelihood_acoustic <- list(
g3l_catchdistribution(
"dist_acoustic",
dist_acoustic,
fleets = list(acoustic),
stocks = list(ling),
function_f = g3l_distribution_sumofsquares(),
area_group = area_names,
report = TRUE,
nll_breakdown = TRUE),
NULL)
actions <- c(actions, actions_acoustic, actions_likelihood_acoustic)
# Create model objective function ####################
# Turn model into C++ code
model_code <- g3_to_tmb(c(actions, list(
# Include detailed reporting for all actions
g3a_report_detail(actions),
# Add lower/upper bounds from parameters to output likelihood
g3l_bounds_penalty(actions) )))
# Guess l50 / linf based on stock sizes
estimate_l50 <- gadget3::g3_stock_def(ling, "midlen")[[length(gadget3::g3_stock_def(ling, "midlen")) / 2]]
estimate_linf <- max(gadget3::g3_stock_def(ling, "midlen"))
estimate_t0 <- gadget3::g3_stock_def(ling, "minage") - 0.8
attr(model_code, "parameter_template") |>
# fish.init.scalar & fish.rec.scalar: Overall scalar for recruitment/initial conditions, see g3a_renewal_normalparam()
g3_init_val("*.rec|init.scalar", 10, lower = 0.001, upper = 200) |>
# fish.rec.(age): Per-age recriutment scalar, see g3a_renewal_normalparam()
g3_init_val("*.init.#", 10, lower = 0.001, upper = 200) |>
# fish.rec.(year): Recruitment level year-on-year, see g3a_renewal_normalparam()
g3_init_val("*.rec.#", 100, lower = 1e-6, upper = 1000) |>
# fish.rec.sd: Standard deviation for recruitment, see g3a_renewal_normalparam()
g3_init_val("*.rec.sd", 5, lower = 4, upper = 20) |>
# init.F: Offset for initial M, see g3a_renewal_initabund()
g3_init_val("init.F", 0.5, lower = 0.1, upper = 1) |>
# fish.M.(age): per-age M for our species, see g3a_naturalmortality()
g3_init_val("*.M.#", 0.15, lower = 0.001, upper = 1) |>
# fish.Linf, fish.K, fish.t0: VonB parameters for our species, see g3a_renewal_vonb_t0(), g3a_grow_lengthvbsimple()
g3_init_val("*.Linf", estimate_linf, spread = 0.2) |>
g3_init_val("*.K", 0.3, lower = 0.04, upper = 1.2) |>
g3_init_val("*.t0", estimate_t0, spread = 2) |>
# fish.walpha, fish.wbeta: Age/weight relationship for initialconditions, renewal, see g3a_renewal_normalparam()
g3_init_val("*.walpha", 0.01, optimise = FALSE) |>
g3_init_val("*.wbeta", 3, optimise = FALSE) |>
# fish.f_surv.alpha, fish.f_surv.l50: Curve/l50 for fishing suitability, see g3_suitability_exponentiall50()
g3_init_val("*.*.alpha", 0.07, lower = 0.01, upper = 0.2) |>
g3_init_val("*.*.l50", estimate_l50, spread = 0.25) |>
# fish.bbin: Beta for beta-binomial distribution for fish growth, see g3a_grow_impl_bbinom()
g3_init_val("*.bbin", 100, lower = 1e-05, upper = 1000) |>
# identity() is a do-nothing function, but it lets us finish on a new line
identity() -> params.in