-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopmodel.tpl
More file actions
4792 lines (3961 loc) · 164 KB
/
opmodel.tpl
File metadata and controls
4792 lines (3961 loc) · 164 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Gulf of Alaska walleye pollock operating model
// temporal/seasonal components
// no spatial components
// ZTA
// Version 0.AF, January 2007
//
// 2014-03-31, update
//
// Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
// https://creativecommons.org/licenses/by-nc-sa/4.0/
//
DATA_SECTION
// BEGIN: BBB GOA pollock stock assessment data
!! ad_comm::change_datafile_name("stock_assess.dat");
init_int styr // Starting year for population model
init_int endyr // Ending year for population model
init_int base_endyr // Ending year for base model
init_int hcr_styr // Starting year for recruitment calculations for the harvest control rule
init_int rcrage // Recruitment age
init_int trmage // Last modeled age
init_int nbins1 // Number of length bins in transitiom matrix 1
init_int nbins2 // Number of length bins in transitiom matrix 2
init_int nbins3 // Number of length bins in transitiom matrix 3
//Fishery
init_vector cattot(styr,endyr) // Total catch in tons
init_vector cattot_log_sd(styr,endyr) // Total catch (cv) = sdev of log(cattot)
init_int nyrs_fsh // Number of fishery age comps
init_ivector fshyrs(1,nyrs_fsh) // Years for the fishery age comps
init_vector multN_fsh(1,nyrs_fsh) // Multinomial sample size by year
init_ivector ac_yng_fsh(1,nyrs_fsh) // Accumulation of lower ages
init_ivector ac_old_fsh(1,nyrs_fsh) // Accumulation of upper ages
init_int nyrslen_fsh // Number of fishery length comps
init_ivector fshlenyrs(1,nyrslen_fsh) // Years for the fishery length comps
init_vector multNlen_fsh(1,nyrslen_fsh) // Multinomial sample size by year
init_vector rwlk_sd(styr,endyr-1) // Random walk stdevs
init_matrix catp(1,nyrs_fsh,rcrage,trmage) // Catch proportions at age
init_matrix lenp(1,nyrslen_fsh,1,nbins1) // Catch proportions at age
init_matrix wt_fsh(styr,endyr,rcrage,trmage) // Weight at age by year
// For matrices indices for rows, then col
//Survey 1 (Acoustic)
//A
init_int nyrs_srv1_bs // Number of survey biomass estimates
init_ivector srvyrs1_bs(1,nyrs_srv1_bs) // Years in which surveys occured
init_vector indxsurv1_bs(1,nyrs_srv1_bs) // Survey index
init_vector indxsurv_log_sd1_bs(1,nyrs_srv1_bs) // Survey index (cv) = sdev of log(indxsurv)
//B
init_int nyrs_srv1_ek // Number of survey biomass estimates
init_ivector srvyrs1_ek(1,nyrs_srv1_ek) // Years in which surveys occured
init_vector indxsurv1_ek(1,nyrs_srv1_ek) // Survey index
init_vector indxsurv_log_sd1_ek(1,nyrs_srv1_ek) // Survey index (cv) = sdev of log(indxsurv)
//C
init_int nyrs_srv1_dy // Number of survey biomass estimates
init_ivector srvyrs1_dy(1,nyrs_srv1_dy) // Years in which surveys occured
init_vector indxsurv1_dy(1,nyrs_srv1_dy) // Survey index
init_vector indxsurv_log_sd1_dy(1,nyrs_srv1_dy) // Survey index (cv) = sdev of log(indxsurv)
init_vector yrfrct_srv1(styr,endyr) // Fraction of year to midpoint of survey
init_int nyrsac_srv1 // Number of survey age comps
init_ivector srv_acyrs1(1,nyrsac_srv1) // Years for the survey age comp
init_vector multN_srv1(1,nyrsac_srv1) // Multinomial sample size by year
init_ivector ac_yng_srv1(1,nyrsac_srv1) // Accumulation of lower ages
init_ivector ac_old_srv1(1,nyrsac_srv1) // Accumulation of upper ages
init_int nyrslen_srv1 // Number of survey length comps
init_ivector srv_lenyrs1(1,nyrslen_srv1) // Years for the survey length comps
init_vector multNlen_srv1(1,nyrslen_srv1) // Multinomial sample size by year
init_matrix srvp1(1,nyrsac_srv1,rcrage,trmage) // Survey proportions at age
init_matrix srvlenp1(1,nyrslen_srv1,1,nbins3) // Survey proportions at length
init_matrix wt_srv1(styr,endyr,rcrage,trmage) // Survey weights at age
// Note full dimensions for weight matrix
//Survey 2 (trawl)
init_int nyrs_srv2 // Number of surveys
init_ivector srvyrs2(1,nyrs_srv2) // Years in which surveys occured
init_vector indxsurv2(1,nyrs_srv2) // Survey index
init_vector indxsurv_log_sd2(1,nyrs_srv2) // Survey index (cv) = sdev of log(indxsurv)
init_vector yrfrct_srv2(styr,endyr) // Fraction of year to midpoint of survey
init_int nyrsac_srv2 // Number of survey age comps
init_ivector srv_acyrs2(1,nyrsac_srv2) // Years for the survey age comp
init_vector multN_srv2(1,nyrsac_srv2) // Multinomial sample size by year
init_ivector ac_yng_srv2(1,nyrsac_srv2) // Accumulation of lower ages
init_ivector ac_old_srv2(1,nyrsac_srv2) // Accumulation of upper ages
init_int nyrslen_srv2 // Number of survey length comps
init_ivector srv_lenyrs2(1,nyrslen_srv2) // Years for the survey length comps
init_vector multNlen_srv2(1,nyrslen_srv2) // Multinomial sample size by year
init_matrix srvp2(1,nyrsac_srv2,rcrage,trmage) // Survey proportions at age
init_matrix srvlenp2(1,nyrslen_srv2,1,nbins2) // Survey proportions at length
init_matrix wt_srv2(styr,endyr,rcrage,trmage) // Survey weights at age
//Survey 3 (coastal)
init_int nyrs_srv3 // Number of survey biomass estimates
init_ivector srvyrs3(1,nyrs_srv3) // Years in which surveys occured
init_vector indxsurv3(1,nyrs_srv3) // Survey index
init_vector indxsurv_log_sd3(1,nyrs_srv3) // Survey index (cv) = sdev of log(indxsurv)
init_vector yrfrct_srv3(styr,endyr) // Fraction of year to midpoint of survey
init_int nyrsac_srv3 // Number of survey age comps
init_ivector srv_acyrs3(1,nyrsac_srv3) // Years for the survey age comps
init_vector multN_srv3(1,nyrsac_srv3) // Multinomial sample size by year
init_int nyrslen_srv3 // Number of survey length comps
init_ivector srv_lenyrs3(1,nyrslen_srv3) // Years for the survey length comps
init_vector multNlen_srv3(1,nyrslen_srv3) // Multinomial sample size by year
init_matrix srvp3(1,nyrsac_srv3,rcrage,trmage) // Survey proportions at age
init_matrix srvlenp3(1,nyrslen_srv3,1,nbins2) // Survey proportions at length
init_matrix wt_srv3(styr,endyr,rcrage,trmage) // Survey weights at age
//Age error transition matrix
init_matrix age_trans(rcrage,trmage,rcrage,trmage)
//Age to length transition matrix
init_matrix len_trans1(rcrage,trmage,1,nbins1)
init_matrix len_trans2(rcrage,trmage,1,nbins2)
init_matrix len_trans3(rcrage,trmage,1,nbins3)
//Population vectors
init_matrix wt_pop(styr,endyr,rcrage,trmage) // Population weight at age
init_matrix wt_spawn(styr,endyr,rcrage,trmage) // Population weight at age at spawning (April 15)
// Anne's maturity vector
init_vector mat_old(rcrage,trmage) // Proportion mature
init_vector mat(rcrage,trmage) // Proportion mature
//Projection parameters
init_vector wt_pop_proj(rcrage,trmage) // Projection population weight at age at start of year
init_vector wt_spawn_proj(rcrage,trmage) // Projection population weight at age at spawning (April 15)
init_vector wt_fsh_proj(rcrage,trmage) // Projection fishery weight at age
init_vector wt_srv_proj(rcrage,trmage) // Projection arbitrary survey weight at age
init_vector Ftarget(endyr+1,endyr+5)
init_number B40
// mean log recruitment
init_number log_mean_recr_proj
// Variance for log recr
init_number sigmasq_recr
// END: BBB GOA pollock stock assessment data
int styr_fsh_sel_dev // updated first value for fsh sel devs
int iii // Index for year
int jjj // Index for age
number o // A small number
// new section for operating model parameters
!! ad_comm::change_datafile_name("opmodel.dat");
init_int st_age // starting age for age classes to keep track of
init_int end_age // ending age for age classes to keep track of
init_int om_hcr_styr // starting year in the OPERATING MODEL for recruitment calculations for the harvest control rule
init_int om_rec_avg_styr // starting year for the OPERATING MODEL for calculating average recruitment and std dev (used for generating future recruitment)
int nyears // number of years to keep track of
int nages // number of ages to keep track of
init_int nsel_fsh // number of fishery selectivity curves
init_vector fsh_frac(1,nsel_fsh) // fraction of the year when fishing occurs
init_int nsel_srv // number of survey selectivity curves
init_vector srv_frac(1,nsel_srv) // fraction of the year when survey occurs
init_number sp_frac // fraction of the year when spawning occurs
int nsel_tot // total number of selectivity curves
int nyears_simple // number of years (starting at styr) of continuous fishing
int nyears_complex // number of years (until endyr) of seasonal fishing
init_int styr_fsh_sel // year that multiple fishing seasons start
init_matrix frac_catch(styr_fsh_sel,endyr,1,nsel_fsh) // catch by year and season (fraction of year)
init_int nyrs_fsh_paa_all // number of years of expanded fishery c-a-a data
init_ivector yrs_fsh_paa_all(1,nyrs_fsh_paa_all) // years of expanded fishery c-a-a data
init_vector multN_fsh_paa_all(1,nyrs_fsh_paa_all) // effective sample size
init_matrix fsh_paa_all(1,nyrs_fsh_paa_all,st_age,end_age) // expanded fishery c-a-a data
init_int nyrs_srv_1_paa_all // number of years of expanded survey 1 p-a-a data
init_ivector yrs_srv_1_paa_all(1,nyrs_srv_1_paa_all) // years of expanded survey 1 p-a-a data
init_vector multN_srv_1_paa_all(1,nyrs_srv_1_paa_all) // effective sample size
init_matrix srv_1_paa_all(1,nyrs_srv_1_paa_all,st_age,end_age) // expanded survey 1 p-a-a data
init_int nyrs_srv_2_paa_all // number of years of expanded survey 1 p-a-a data
init_ivector yrs_srv_2_paa_all(1,nyrs_srv_2_paa_all) // years of expanded survey 1 p-a-a data
init_vector multN_srv_2_paa_all(1,nyrs_srv_2_paa_all) // effective sample size
init_matrix srv_2_paa_all(1,nyrs_srv_2_paa_all,st_age,end_age) // expanded survey 1 p-a-a data
init_vector M(st_age,end_age) // initial values for natural mortality at age
int first_rec_year // first year that recruits will be calculated
int last_rec_year // last year that recruits will be calculated
init_int s_r_relat // Stock-Recruit relationship: 1 - B-H, 2 - R, 3 - S, 4 - avg R
int h_phase // don't estimate h for avg R S-R relationship (R0 = avg R)
init_int nsel_lengths // number of lengths in selectivity curves
init_vector sel_lengths(1,nsel_lengths) // midpoint of selectivity length bins
init_int phase_fsh_sel // phase to turn on fishery selectivity curves
init_ivector phase_q(1,nsel_srv) // phase to turn on survey catchability estimation
init_ivector phase_srv_sel_age1(1,nsel_srv) // phase to turn on survey selectivity value for age-st_age fish
init_ivector phase_srv_sel_a1(1,nsel_srv) // phase to turn on survey selectivity curves (ascending part)
init_ivector phase_srv_sel_b1(1,nsel_srv) // phase to turn on survey selectivity curves (ascending part)
init_ivector phase_srv_sel_a2(1,nsel_srv) // phase to turn on survey selectivity curves (descending part)
init_ivector phase_srv_sel_b2(1,nsel_srv) // phase to turn on survey selectivity curves (descending part)
init_matrix age_trans_all(st_age,end_age,st_age,end_age) // ageing error matrix for expanded proportions-at-age data
init_matrix age_len_trans(st_age,end_age,1,nsel_lengths) // age-length transition matrix
vector maa_old(st_age,end_age) // old maturity-at-age matrix
vector maa(st_age,end_age) // maturity-at-age matrix
init_vector waa_pop(st_age,end_age) // average population weight-at-age
init_vector waa_fsh(st_age,end_age) // average fishery weight-at-age
init_matrix waa_srv(1,nsel_srv,st_age,end_age) // average weight-at-age for surveys
init_int nyrs_proj // number of years to do projections
init_matrix init_M_proj(endyr+1,endyr+nyrs_proj,st_age,end_age) // M-at-age values to use in projections
init_int nsubsample // number of MCMC iterations to skip
int mcmc_iter // number of MCMC iterations
init_int complex_flag // 0 - determinstic, simple model; 1 - recruitment error only; 2 - recruitment and survey obs error; 3 - full model
init_int future_rec_flag // 0 - generate future recruitment randomly using avg level of recruitment and sigmaR; 1 - future recruitment is historical recruitment sampled with replacement
init_int debug_flag // 1 - debug on; 0 - debug off
init_int catch_flag // 0 - no catch in future projections; 1 - calculate catch
init_int BRP_M_flag // 0 - use annual M-at-age for calculating BRPs; 1 - use average M-at-age since 1977+st_age for calculating BRPs
!! if (catch_flag == 3)
!! {
// new section for future catches
!! ad_comm::change_datafile_name("future_catch.dat");
init_matrix proj_catch_array(1,100,endyr+1,endyr+nyrs_proj); // values for annual catch in the future
!! }
number sigma_f // sigmaF (sigmaR for equilibrium numbers in first year)
number sigma_r // sigmaR (recruitment deviance)
number Tier3_alpha // alpha for the NPFMC Tier 3 decision rule, 0.05
number mult_factor // ABC when SB < SB20% is mult_factor * age_3_biomass, 0.001 * 0.001 => metric tonnes
number conv_factor // 1e9
number R0_mean // mean for prior on R0
number R0_stddev // std dev for prior on R0
!!#define MAX_IDF_LINES 4096 // maximum number of lines in stock_assess_proj.dat
!!#define MAX_IDF_LINE_LEN 4096 // maximum line length of lines in stock_assess_proj.dat
!!#define MAX_BISECT_ITER 128 // maximum number of iterations for the bisection
!!#define BISECT_TOL 0.000001 // maximum tolerance for bisection
!!cout << "Data check" << endl;
!!cout << "nyrs_srv2\t" << nyrs_srv2 << endl;
!!cout << "srv_frac\t" << srv_frac << endl;
!!cout << "phase_q\t" << phase_q << endl;
!!cout << "nyrs_proj\t" << nyrs_proj << endl;
LOCAL_CALCS
nsel_tot = nsel_fsh + nsel_srv;
nyears_simple = styr_fsh_sel - styr;
nyears_complex = endyr - styr_fsh_sel + 1;
nyears = endyr - styr + 1;
nages = end_age - st_age + 1;
first_rec_year = styr;
last_rec_year = endyr;
// styr_fsh_sel_dev = styr + 11; // HARDCODED - skip the years that BBB has random walk SD as 0.001
// rwlk_sd *= 3.0; // HARDCODED - test
// rwlk_sd(styr_fsh_sel_dev) *= 2.0; // HARDCODED - increase the SD for the first year used
styr_fsh_sel_dev = styr; // stop messing about with the rwlk_sd vector
if (s_r_relat == 1 || s_r_relat == 2 || s_r_relat == 3)
{
h_phase = 2;
}
else
{
h_phase = -2;
}
// map BBB maturity at age to (larger) maturity at age
maa_old.initialize();
maa.initialize();
maa_old = maa = 0.0;
if (trmage <= end_age)
{
maa_old(rcrage,trmage) = mat_old(rcrage,trmage);
maa(rcrage,trmage) = mat(rcrage,trmage);
if (trmage < end_age)
{
for (int a = (trmage + 1); a <= end_age; a++)
{
maa_old(a) = 1.0;
maa(a) = 1.0;
}
}
}
sigma_f = 1.0;
sigma_r = 1.0;
Tier3_alpha = 0.05;
mult_factor = 0.000001;
conv_factor = 1000000000.; // convert from kg to millions of metric tonnes
R0_mean = 1.0446e+009;
R0_stddev = 0.1 * R0_mean; // DDD-specified CV of 0.1
o = 0.00001;
mcmc_iter = 0;
END_CALCS
INITIALIZATION_SECTION
// using a PIN file instead
PARAMETER_SECTION
init_bounded_number log_R0(5.0,35.0,1);
init_bounded_number log_h(-1.6,1.6,h_phase);
init_bounded_number log_q(-10.0,10.0,-1);
init_bounded_vector log_q_fsh(1,nsel_fsh,-10.0,10.0,-1);
init_bounded_number log_q_srv_bs(-10.0,10.0,5);
init_bounded_number log_q_srv_ek(-10.0,10.0,5);
init_bounded_number_vector log_q_srv(1,nsel_srv,-10.0,10.0,phase_q);
init_bounded_number log_initR(5.0,35.0,1);
init_bounded_number mean_log_Fmort(-10.0,10.0,1);
init_bounded_dev_vector log_Fmort_dev(styr,endyr,-10.0,10.0,2);
init_bounded_dev_vector log_rec_dev(first_rec_year,last_rec_year,-15.0,15.0,3);
init_bounded_dev_vector log_init_dev(st_age+1,end_age,-15.0,15.0,-2);
// comparing BBB's code: slope == b, inflection == a
init_bounded_number log_fsh_sel_cont_a1(0.0,2.0,phase_fsh_sel); // in BBB model, bounds are 1 and 5; starting point is 4
init_bounded_number log_fsh_sel_cont_b1(-5.0,5.0,phase_fsh_sel); // in BBB model, bounds are -5 and 5; starting point is 1
init_bounded_number log_fsh_sel_cont_a2(1.0,3.0,phase_fsh_sel); // in BBB model, bounds are 7 and 20; starting point is 7
init_bounded_number log_fsh_sel_cont_b2(-5.0,5.0,phase_fsh_sel); // in BBB model, bounds are -5 and 5; starting point is 1
init_bounded_vector log_fsh_sel_a1(1,nsel_fsh,0.0,5.0,-phase_fsh_sel);
init_bounded_vector log_fsh_sel_b1(1,nsel_fsh,-5.0,5.0,-phase_fsh_sel);
init_bounded_vector log_fsh_sel_a2(1,nsel_fsh,1.0,5.0,-phase_fsh_sel);
init_bounded_vector log_fsh_sel_b2(1,nsel_fsh,-5.0,5.0,-phase_fsh_sel);
init_bounded_number_vector log_srv_sel_age1(1,nsel_srv,-15.0,1.0,phase_srv_sel_age1); // in BBB model, bounds are 0 and 2
init_bounded_number_vector log_srv_sel_a1(1,nsel_srv,0.0,5.0,phase_srv_sel_a1); // in BBB model, bounds are (X, 1, X, 1, X, 1) and (X, 50, X, 20, X, 100); starting points are (X, 7, X, 5, X, 5)
init_bounded_number_vector log_srv_sel_b1(1,nsel_srv,-5.0,5.0,phase_srv_sel_b1); // in BBB model, bounds are -5 and 5; starting points are (X, 0, X, 0, X, 0)
init_bounded_number_vector log_srv_sel_a2(1,nsel_srv,1.0,5.0,phase_srv_sel_a2); // in BBB model, bounds are (7, 5, X, X, X, 5) and (20, 10, X, X, X, 100); starting points are (9, 8, X, X, X, 8)
init_bounded_number_vector log_srv_sel_b2(1,nsel_srv,-5.0,5.0,phase_srv_sel_b2); // in BBB model, bounds are -5 and 5, except for srv 6 (-20,5); starting points are (1, 0, X, X, X, -10)
// init_number_vector class is not defined in all versions of ADMB
// init_vector log_srv_sel_a1(1,nsel_srv,-phase_fsh_sel);
// init_vector log_srv_sel_b1(1,nsel_srv,-phase_fsh_sel);
// init_vector log_srv_sel_a2(1,nsel_srv,-phase_fsh_sel);
// init_vector log_srv_sel_b2(1,nsel_srv,-phase_fsh_sel);
init_bounded_dev_vector fsh_sel_cont_a1_dev(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel);
init_bounded_dev_vector fsh_sel_cont_b1_dev(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel);
init_bounded_dev_vector fsh_sel_cont_a2_dev(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel);
init_bounded_dev_vector fsh_sel_cont_b2_dev(styr_fsh_sel_dev,endyr,-5.0,5.0,phase_fsh_sel);
matrix N(styr,endyr+1,st_age,end_age);
matrix C(styr,endyr,st_age,end_age);
matrix F(styr,endyr,st_age,end_age);
matrix Slen(1,nsel_tot+1,1,nsel_lengths);
matrix Sage(1,nsel_tot+1,st_age,end_age);
matrix Sage_fsh(styr,endyr,st_age,end_age);
matrix Z(styr,endyr,st_age,end_age);
matrix expZ(styr,endyr,st_age,end_age);
matrix expZsp(styr,endyr,st_age,end_age);
3darray expZfrac(1,nsel_srv,styr,endyr,st_age,end_age);
vector initN(st_age,end_age);
vector Fmort(styr,endyr);
vector spawn_biomass(styr-1,endyr+1);
vector total_biomass(styr-1,endyr+1);
vector age_3_plus_biomass(styr-1,endyr+1);
vector estsrvbio_bs(styr,endyr);
vector estsrvbio_ek(styr,endyr);
matrix estsrvbio(1,nsel_srv,styr,endyr);
number fsh_sel_cont_a1;
number fsh_sel_cont_b1;
number fsh_sel_cont_a2;
number fsh_sel_cont_b2;
vector fsh_sel_a1(1,nsel_fsh);
vector fsh_sel_b1(1,nsel_fsh);
vector fsh_sel_a2(1,nsel_fsh);
vector fsh_sel_b2(1,nsel_fsh);
vector srv_sel_age1(1,nsel_srv);
vector srv_sel_a1(1,nsel_srv);
vector srv_sel_b1(1,nsel_srv);
vector srv_sel_a2(1,nsel_srv);
vector srv_sel_b2(1,nsel_srv);
number R0;
number h;
number steepness;
number q;
vector q_fsh(1,nsel_fsh);
number q_srv_bs;
number q_srv_ek;
vector q_srv(1,nsel_srv);
number initR;
// extra data not in BBB's model
vector pred_catch(styr,endyr);
matrix pred_fsh_paa_all(styr,endyr,st_age,end_age);
matrix pred_fsh_paa(styr,endyr,rcrage,trmage);
3darray pred_srv_paa_all(1,nsel_srv,styr,endyr,st_age,end_age);
3darray pred_srv_paa(1,nsel_srv,styr,endyr,rcrage,trmage);
matrix pred_fsh_pal(1,nyrslen_fsh,1,nbins1);
matrix pred_srv_1_pal(1,nyrslen_srv1,1,nbins3);
matrix pred_srv_2_pal(1,nyrslen_srv2,1,nbins2);
matrix pred_srv_3_pal(1,nyrslen_srv3,1,nbins2);
// projection parameters
matrix N_proj(endyr+1,endyr+nyrs_proj+1,st_age,end_age);
matrix C_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
vector F_proj(endyr+1,endyr+nyrs_proj);
matrix M_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
matrix Z_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
matrix expZ_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
matrix expZsp_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
3darray expZfrac_proj(1,nsel_srv,endyr+1,endyr+nyrs_proj,st_age,end_age);
matrix fsh_paa_all_proj(endyr,endyr+nyrs_proj,st_age,end_age);
3darray srv_paa_all_proj(1,nsel_srv,endyr+1,endyr+nyrs_proj,st_age,end_age);
vector catch_proj(endyr+1,endyr+nyrs_proj);
vector spawn_biomass_proj(endyr+1,endyr+nyrs_proj);
vector total_biomass_proj(endyr+1,endyr+nyrs_proj);
vector age_3_plus_biomass_proj(endyr+1,endyr+nyrs_proj);
matrix estsrvbio_proj(1,nsel_srv,endyr+1,endyr+nyrs_proj);
3darray estsrvN_proj(1,nsel_srv,endyr+1,endyr+nyrs_proj,st_age,end_age);
vector estsrvbio_proj_2_sd(endyr+1,endyr+nyrs_proj);
vector estsrvbio_proj_2_multN(endyr+1,endyr+nyrs_proj);
vector estFOFL_proj(endyr+1,endyr+nyrs_proj);
vector estFABC_proj(endyr+1,endyr+nyrs_proj);
vector estABC_proj(endyr+1,endyr+nyrs_proj);
matrix estABCaa_proj(endyr+1,endyr+nyrs_proj,st_age,end_age);
number mcmc_avg_rec;
number mcmc_avg_log_rec;
number mcmc_std_dev_avg_log_rec;
number mcmc_CV_avg_log_rec;
number mcmc_avg_rec_years;
number mcmc_max_rec;
// initialize the random number generator used for the projections
!!CLASS random_number_generator mcmc_rng(1);
// parameters for decision rule
vector F100(endyr,endyr+nyrs_proj);
vector SB100(endyr,endyr+nyrs_proj);
vector SBtarget(endyr,endyr+nyrs_proj);
vector F40(endyr,endyr+nyrs_proj);
vector SB40(endyr,endyr+nyrs_proj);
vector F35(endyr,endyr+nyrs_proj);
vector SB35(endyr,endyr+nyrs_proj);
vector F20(endyr,endyr+nyrs_proj);
vector SB20(endyr,endyr+nyrs_proj);
vector Sage_fsh_avg(st_age,end_age);
vector M_at_age(st_age,end_age);
number F_ABC;
number ABC;
number F_OFL;
number OFL;
number phi0;
number avgR;
number avgR_CV;
number SB0;
number SBcurr;
// calculated value for B0 over a moving window of 25 years of avg rec level
vector B0_mw(endyr+1,endyr+nyrs_proj);
vector f(1,20);
objective_function_value obj_fun;
// sdreport_number sd_q_srv_bs;
// sdreport_vector sd_q_srv(1,nsel_srv);
sdreport_vector sd_recruits_1(styr,endyr+1);
sdreport_number sd_avg_rec_1;
sdreport_number sd_avg_rec_1_alt;
sdreport_vector sd_recruits_2(styr,endyr+1);
sdreport_number sd_avg_rec_2;
sdreport_number sd_avg_rec_2_alt;
sdreport_vector sd_total_biomass(styr,endyr);
sdreport_vector sd_spawn_biomass(styr,endyr);
sdreport_vector sd_age_3_plus_biomass(styr,endyr);
// sdreport_vector sd_estsrvbio_bs(styr,endyr);
// sdreport_matrix sd_estsrvbio(1,nsel_srv,styr,endyr);
likeprof_number var_prof
PRELIMINARY_CALCS_SECTION // from BBB's model
// Do upper and lower accumulations in age composition data
// Fishery
for (iii=1;iii<=nyrs_fsh;iii++)
{
for (jjj=rcrage;jjj<=trmage;jjj++)
{
if(jjj<ac_yng_fsh(iii))
{
catp(iii,ac_yng_fsh(iii)) += catp(iii,jjj);
catp(iii,jjj) = 0;
}
if(jjj>ac_old_fsh(iii))
{
catp(iii,ac_old_fsh(iii)) += catp(iii,jjj);
catp(iii,jjj) = 0;
}
}}
// Survey 1
for (iii=1;iii<=nyrsac_srv1;iii++)
{
for (jjj=rcrage;jjj<=trmage;jjj++)
{
if(jjj<ac_yng_srv1(iii))
{
srvp1(iii,ac_yng_srv1(iii)) += srvp1(iii,jjj);
srvp1(iii,jjj) = 0;
}
if(jjj>ac_old_srv1(iii))
{
srvp1(iii,ac_old_srv1(iii)) += srvp1(iii,jjj);
srvp1(iii,jjj) = 0;
}
}}
// Survey 2
for (iii=1;iii<=nyrsac_srv2;iii++)
{
for (jjj=rcrage;jjj<=trmage;jjj++)
{
if(jjj<ac_yng_srv2(iii))
{
srvp2(iii,ac_yng_srv2(iii)) += srvp2(iii,jjj);
srvp2(iii,jjj) = 0;
}
if(jjj>ac_old_srv2(iii))
{
srvp2(iii,ac_old_srv2(iii)) += srvp2(iii,jjj);
srvp2(iii,jjj) = 0;
}
}}
var_prof.set_stepnumber(30);
// var_prof.set_stepnumber(10);
var_prof.set_stepsize(0.1);
PROCEDURE_SECTION
calculate_selectivity();
calculate_mortality();
calculate_n_a_a();
calculate_c_a_a();
calculate_length_comps();
evaluate_objective_function();
calculate_projections();
FUNCTION calculate_selectivity
dvariable maxSel;
int a,i,j;
fsh_sel_cont_a1 = mfexp(log_fsh_sel_cont_a1);
fsh_sel_cont_b1 = mfexp(log_fsh_sel_cont_b1);
fsh_sel_cont_a2 = mfexp(log_fsh_sel_cont_a2);
fsh_sel_cont_b2 = mfexp(log_fsh_sel_cont_b2);
fsh_sel_a1 = mfexp(log_fsh_sel_a1);
fsh_sel_b1 = mfexp(log_fsh_sel_b1);
fsh_sel_a2 = mfexp(log_fsh_sel_a2);
fsh_sel_b2 = mfexp(log_fsh_sel_b2);
srv_sel_age1 = mfexp(log_srv_sel_age1);
srv_sel_a1 = mfexp(log_srv_sel_a1);
srv_sel_b1 = mfexp(log_srv_sel_b1);
srv_sel_a2 = mfexp(log_srv_sel_a2);
srv_sel_b2 = mfexp(log_srv_sel_b2);
Slen.initialize();
Sage.initialize();
// if (debug_flag) cout << fsh_sel_cont_b2 << " " << fsh_sel_b2 << " " << srv_sel_b2 << endl;
// if (debug_flag) cout << endl;
// selectivity curves 1 to nsel_fsh are for the fisheries (seasons in later years)
// selectivity curves nsel_fsh + 1 to nsel_fsh + nsel_srv are for the surveys
// selectivity curve nsel_tot (nsel_fsh + nsel_srv) + 1 is for continuous fishing
for (a = st_age; a <= end_age; a++)
{
// all curves are double logistic, courtesy of Dorn and Methot 1990
for (i = 1; i <= nsel_fsh; i++)
{
Sage(i,a) = (1.0 / (1.0 + mfexp(-fsh_sel_b1(i)*(double(a) - fsh_sel_a1(i)))))*(1.0 - (1.0 / (1.0 + mfexp(-fsh_sel_b2(i)*(double(a) - fsh_sel_a2(i))))));
}
for (i = 1; i <= nsel_srv; i++)
{
Sage(i+nsel_fsh,a) = (1.0 / (1.0 + mfexp(-srv_sel_b1(i)*(double(a) - srv_sel_a1(i)))))*(1.0 - (1.0 / (1.0 + mfexp(-srv_sel_b2(i)*(double(a) - srv_sel_a2(i))))));
}
Sage(nsel_tot+1,a) = (1.0 / (1.0 + mfexp(-fsh_sel_cont_b1*(double(a) - fsh_sel_cont_a1))))*(1.0 - (1.0 / (1.0 + mfexp(-fsh_sel_cont_b2*(double(a) - fsh_sel_cont_a2)))));
}
// set selectivity for upper ages to selectivity at trmage
// MAY CHANGE LATER WHEN DATA IS AVAILABLE TO AGE 15
// for version 0.16 and above: extended p-a-a data (ages 1 to 15) is
// available for the fishery and surveys 1 and 2
if (trmage < end_age)
{
for (j = (trmage + 1); j <= end_age; j++)
{
i = 3 + nsel_fsh; // survey 3
Sage(i,j) = Sage(i,trmage);
}
}
// match BBB's model by having a separate value for age-st_age fish
for (i = 1; i <= nsel_srv; i++)
{
// include them in the selectivity curve ONLY if they will be estimated
if (phase_srv_sel_age1(i) > 0)
{
Sage(i+nsel_fsh,st_age) = srv_sel_age1(i);
}
}
// rescale age selectivity curves
for (i = 1; i <= nsel_tot+1; i++)
{
maxSel = max(Sage(i));
Sage(i) /= maxSel;
}
// match BBB's model by having a separate value for age-st_age fish
// for (i = 1; i <= nsel_srv; i++)
// {
// include them in the selectivity curve ONLY if they will be estimated
// if (phase_srv_sel_age1(i) > 0)
// {
// Sage(i+nsel_fsh,st_age) = srv_sel_age1(i);
// }
// }
// convert from selectivity-at-length to selectivity-at-age
for (i = 1; i <= nsel_tot+1; i++)
{
Slen(i) = Sage(i) * age_len_trans;
}
// rescale length selectivity curves
for (i = 1; i <= nsel_tot+1; i++)
{
maxSel = max(Slen(i));
Slen(i) /= maxSel;
}
if (debug_flag) cout << "end of calc_sel" << endl;
FUNCTION calculate_mortality
dvariable maxSel;
int y,a,i;
Sage_fsh.initialize();
Fmort.initialize();
// annual fishing mortality
Fmort = mfexp(mean_log_Fmort + log_Fmort_dev);
// covers the period for changes in fishery selectivity
for (y = styr_fsh_sel_dev; y <= endyr; y++)
{
// annual fishery selectivity
for (a = st_age; a <= end_age; a++)
{
Sage_fsh(y,a) = (1.0 / (1.0 + mfexp(-(fsh_sel_cont_b1 * mfexp(fsh_sel_cont_b1_dev(y))) * (double(a) - (fsh_sel_cont_a1 + fsh_sel_cont_a1_dev(y)))))) * (1.0 - (1.0 / (1.0 + mfexp(-(fsh_sel_cont_b2 * mfexp(fsh_sel_cont_b2_dev(y))) * (double(a) - (fsh_sel_cont_a2 + fsh_sel_cont_a2_dev(y)))))));
}
// normalize selectivity
maxSel = max(Sage_fsh(y));
Sage_fsh(y) /= maxSel;
}
// fishery selectivity is constant over the period where BBB has very low SD on random walk
for (y = styr; y < styr_fsh_sel_dev; y++)
{
Sage_fsh(y) = Sage_fsh(styr_fsh_sel_dev);
}
for (y = styr; y <= endyr; y++)
{
// ages covered by selectivity
for (a = st_age; a <= end_age; a++)
{
F(y,a) = Sage_fsh(y,a) * Fmort(y);
Z(y,a) = M(a) + F(y,a);
}
}
expZ = mfexp(-Z);
// survival with fishing until spawning
expZsp = mfexp(-sp_frac * Z);
for (y = styr; y <= endyr; y++)
{
// this assumes continuous fishing - NEED TO CHANGE WITH OPTION
expZfrac(1,y) = mfexp(-yrfrct_srv1(y) * Z(y));
expZfrac(2,y) = mfexp(-yrfrct_srv2(y) * Z(y));
expZfrac(3,y) = mfexp(-yrfrct_srv3(y) * Z(y));
}
if (debug_flag) cout << "end of calc_mort" << endl;
FUNCTION calculate_n_a_a
dvariable totn, wt_a, wt_sp_a, spbio_tmp, Ntmp, srvbio_tmp;
int y,a,i,j,j_max;
int acc_age;
R0 = mfexp(log_R0);
h = mfexp(log_h);
q = mfexp(log_q);
q_fsh = mfexp(log_q_fsh);
q_srv_bs = mfexp(log_q_srv_bs);
q_srv_ek = mfexp(log_q_srv_ek);
q_srv = mfexp(log_q_srv);
initR = mfexp(log_initR);
// equilibrium age structure
initN(st_age) = initR * mfexp(log_rec_dev(styr));
for (a = (st_age+1); a <= end_age; a++)
{
initN(a) = initN(a-1) * mfexp(-M(a-1));
}
initN(end_age) /= (1.0 - mfexp(-M(end_age)));
// put in first year deviances but not for the recruits (age 1)
for (a = (st_age+1); a <= end_age; a++)
{
initN(a) *= mfexp(log_init_dev(a));
}
// calculate the equilibrium spawning and total biomass
spawn_biomass.initialize();
total_biomass.initialize();
age_3_plus_biomass.initialize();
for (a = (st_age+1); a <= end_age; a++)
{
if (a < rcrage || a > trmage)
{
if (a > trmage && (complex_flag == 0 || complex_flag == 1 || complex_flag == 2))
{
wt_a = wt_pop(styr,trmage);
wt_sp_a = wt_spawn(styr,trmage);
}
else
{
wt_a = waa_pop(a);
wt_sp_a = waa_srv(1,a);
}
spawn_biomass(styr-1) += (0.5 * initN(a) * maa(a) * wt_sp_a * mfexp(-sp_frac * M(a)));
total_biomass(styr-1) += (initN(a) * wt_a);
if (a >= 3)
{
age_3_plus_biomass(styr-1) += (initN(a) * wt_a);
}
}
else
{
spawn_biomass(styr-1) += (0.5 * initN(a) * maa(a) * wt_spawn(styr,a) * mfexp(-sp_frac * M(a)));
total_biomass(styr-1) += (initN(a) * wt_pop(styr,a));
if (a >= 3)
{
age_3_plus_biomass(styr-1) += (initN(a) * wt_pop(styr,a));
}
}
}
if (debug_flag) cout << "init of calc_n_a_a" << endl;
// cout << "in calculate_n_a_a: R0 = " << R0 << ", h = " << h << ", SpBio(styr-1) = " << spawn_biomass(styr-1) << ", s_r_relat = " << s_r_relat << endl;
// calculate the equilibrium number of recruits (age 1 in following year)
spbio_tmp = spawn_biomass(styr-1) / conv_factor;
steepness = 0.0;
phi0.initialize();
Ntmp.initialize();
Ntmp = 0.5;
for (a = st_age ; a < end_age; a++)
{
if (a < rcrage)
{
wt_sp_a = waa_srv(1,a);
}
else if (a > trmage)
{
if (complex_flag == 0 || complex_flag == 1 || complex_flag == 2)
{
wt_sp_a = wt_spawn(styr,trmage);
}
else
{
wt_sp_a = waa_srv(1,a);
}
}
else
{
wt_sp_a = wt_spawn(styr,a);
}
phi0 += (Ntmp * maa(a) * wt_sp_a * mfexp(-sp_frac * M(a)));
Ntmp *= mfexp(-M(a));
}
Ntmp /= (1.0 - mfexp(-M(end_age)));
phi0 += (Ntmp * maa(end_age) * wt_sp_a * mfexp(-sp_frac * M(end_age)));
// if (last_phase()) cout << "phi0 in year " << styr << " is " << phi0 << endl;
if (s_r_relat == 1)
{
// Beverton-Holt S-R relationship (gamma = -1)
N(styr,st_age) = conv_factor * (4.0 * R0 * h * spbio_tmp) / ((phi0 * R0 * (1.0 - h)) + (((5.0 * h) - 1.0) * spbio_tmp));
steepness = h;
}
else if (s_r_relat == 2)
{
// Ricker S-R relationship (gamma = 0)
N(styr,st_age) = conv_factor * (1.0 / phi0) * spbio_tmp * mfexp(h * (1.0 - (spbio_tmp / (R0 * phi0))));
steepness = mfexp(h) / (mfexp(h) + 4.0);
}
else if (s_r_relat == 3)
{
// Schaefer S-R relationship (gamma = 1)
N(styr,st_age) = conv_factor * R0 * spbio_tmp * (1.0 - (h * spbio_tmp));
}
else
{
// average recruits S-R relationship
N(styr,st_age) = initR;
}
N(styr)((st_age+1),end_age) = initN((st_age+1),end_age);
if (debug_flag) cout << "begin of calc_n_a_a" << endl;
estsrvbio_bs.initialize();
estsrvbio_ek.initialize();
estsrvbio.initialize();
pred_srv_paa_all.initialize();
pred_srv_paa.initialize();
for (y = styr; y <= endyr; y++)
{
// apply recruitment errors
N(y,st_age) *= mfexp(log_rec_dev(y));
for (a = (st_age+1); a <= end_age; a++)
{
// this assumes continuous fishing
N(y+1,a) = N(y,a-1) * expZ(y,a-1);
}
N(y+1,end_age) = (N(y,end_age) * expZ(y,end_age)) + (N(y,end_age-1) * expZ(y,end_age-1));
for (a = (st_age+1); a <= end_age; a++)
{
// spawning takes place after fishing seasons A and B
// and survey 1 take place; need to change this
if (a < rcrage || a > trmage)
{
if (a > trmage && (complex_flag == 0 || complex_flag == 1 || complex_flag == 2))
{
wt_a = wt_pop(y,trmage);
wt_sp_a = wt_spawn(y,trmage);
}
else
{
wt_a = waa_pop(a);
wt_sp_a = waa_srv(1,a);
}
spawn_biomass(y) += (0.5 * N(y,a) * maa(a) * wt_sp_a * expZsp(y,a));
total_biomass(y) += (N(y,a) * wt_a);
if (a >= 3)
{
age_3_plus_biomass(y) += (N(y,a) * wt_a);
}
}
else
{
spawn_biomass(y) += (0.5 * N(y,a) * maa(a) * wt_spawn(y,a) * expZsp(y,a));
total_biomass(y) += (N(y,a) * wt_pop(y,a));
if (a >= 3)
{
age_3_plus_biomass(y) += (N(y,a) * wt_pop(y,a));
}
}
}
// calculate the number of recruits (age 1 in following year)
spbio_tmp = spawn_biomass(y) / conv_factor;
steepness = 0.0;
phi0.initialize();
Ntmp.initialize();
Ntmp = 0.5;
for (a = st_age ; a < end_age; a++)
{
if (a < rcrage)
{
wt_sp_a = waa_srv(1,a);
}
else if (a > trmage)
{
if (complex_flag == 0 || complex_flag == 1 || complex_flag == 2)
{
wt_sp_a = wt_spawn(y,trmage);
}
else
{
wt_sp_a = waa_srv(1,a);
}
}
else
{
wt_sp_a = wt_spawn(y,a);
}
phi0 += (Ntmp * maa(a) * wt_sp_a * mfexp(-sp_frac * M(a)));
Ntmp *= mfexp(-M(a));
}
Ntmp /= (1.0 - mfexp(-M(end_age)));
phi0 += (Ntmp * maa(end_age) * wt_sp_a * mfexp(-sp_frac * M(end_age)));
// if (last_phase()) cout << "phi0 in year " << y << " is " << phi0 << endl;
if (s_r_relat == 1)
{
// Beverton-Holt S-R relationship (gamma = -1)
N(y+1,st_age) = conv_factor * (4.0 * R0 * h * spbio_tmp) / ((phi0 * R0 * (1.0 - h)) + (((5.0 * h) - 1.0) * spbio_tmp));
steepness = h;
}
else if (s_r_relat == 2)
{
// Ricker S-R relationship (gamma = 0)
N(y+1,st_age) = conv_factor * (1.0 / phi0) * spbio_tmp * mfexp(h * (1.0 - (spbio_tmp / (R0 * phi0))));
steepness = mfexp(h) / (mfexp(h) + 4.0);
}
else if (s_r_relat == 3)
{
// Schaefer S-R relationship (gamma = 1)
N(y+1,st_age) = conv_factor * R0 * spbio_tmp * (1.0 - (h * spbio_tmp));
}
else
{
// average recruits S-R relationship