-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock_assess.cpp
1784 lines (1750 loc) · 57.5 KB
/
stock_assess.cpp
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
#include <admodel.h>
#include <contrib.h>
extern "C" {
void ad_boundf(int i);
}
#include <stock_assess.htp>
model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
{
pad_report1 = new ofstream("mceval.dat");
styr.allocate("styr");
endyr.allocate("endyr");
base_endyr.allocate("base_endyr");
hcr_styr.allocate("hcr_styr");
rcrage.allocate("rcrage");
trmage.allocate("trmage");
nbins1.allocate("nbins1");
nbins2.allocate("nbins2");
nbins3.allocate("nbins3");
cattot.allocate(styr,endyr,"cattot");
cattot_log_sd.allocate(styr,endyr,"cattot_log_sd");
nyrs_fsh.allocate("nyrs_fsh");
fshyrs.allocate(1,nyrs_fsh,"fshyrs");
multN_fsh.allocate(1,nyrs_fsh,"multN_fsh");
ac_yng_fsh.allocate(1,nyrs_fsh,"ac_yng_fsh");
ac_old_fsh.allocate(1,nyrs_fsh,"ac_old_fsh");
nyrslen_fsh.allocate("nyrslen_fsh");
fshlenyrs.allocate(1,nyrslen_fsh,"fshlenyrs");
multNlen_fsh.allocate(1,nyrslen_fsh,"multNlen_fsh");
rwlk_sd.allocate(styr,endyr-1,"rwlk_sd");
rwlk_sd_short.allocate(styr,base_endyr);
catp.allocate(1,nyrs_fsh,rcrage,trmage,"catp");
lenp.allocate(1,nyrslen_fsh,1,nbins1,"lenp");
wt_fsh.allocate(styr,endyr,rcrage,trmage,"wt_fsh");
nyrs_srv1_bs.allocate("nyrs_srv1_bs");
srvyrs1_bs.allocate(1,nyrs_srv1_bs,"srvyrs1_bs");
indxsurv1_bs.allocate(1,nyrs_srv1_bs,"indxsurv1_bs");
indxsurv_log_sd1_bs.allocate(1,nyrs_srv1_bs,"indxsurv_log_sd1_bs");
nyrs_srv1_ek.allocate("nyrs_srv1_ek");
srvyrs1_ek.allocate(1,nyrs_srv1_ek,"srvyrs1_ek");
indxsurv1_ek.allocate(1,nyrs_srv1_ek,"indxsurv1_ek");
indxsurv_log_sd1_ek.allocate(1,nyrs_srv1_ek,"indxsurv_log_sd1_ek");
nyrs_srv1_dy.allocate("nyrs_srv1_dy");
srvyrs1_dy.allocate(1,nyrs_srv1_dy,"srvyrs1_dy");
indxsurv1_dy.allocate(1,nyrs_srv1_dy,"indxsurv1_dy");
indxsurv_log_sd1_dy.allocate(1,nyrs_srv1_dy,"indxsurv_log_sd1_dy");
yrfrct_srv1.allocate(styr,endyr,"yrfrct_srv1");
nyrsac_srv1.allocate("nyrsac_srv1");
srv_acyrs1.allocate(1,nyrsac_srv1,"srv_acyrs1");
multN_srv1.allocate(1,nyrsac_srv1,"multN_srv1");
ac_yng_srv1.allocate(1,nyrsac_srv1,"ac_yng_srv1");
ac_old_srv1.allocate(1,nyrsac_srv1,"ac_old_srv1");
nyrslen_srv1.allocate("nyrslen_srv1");
srv_lenyrs1.allocate(1,nyrslen_srv1,"srv_lenyrs1");
multNlen_srv1.allocate(1,nyrslen_srv1,"multNlen_srv1");
srvp1.allocate(1,nyrsac_srv1,rcrage,trmage,"srvp1");
srvlenp1.allocate(1,nyrslen_srv1,1,nbins3,"srvlenp1");
wt_srv1.allocate(styr,endyr,rcrage,trmage,"wt_srv1");
nyrs_srv2.allocate("nyrs_srv2");
srvyrs2.allocate(1,nyrs_srv2,"srvyrs2");
indxsurv2.allocate(1,nyrs_srv2,"indxsurv2");
indxsurv_log_sd2.allocate(1,nyrs_srv2,"indxsurv_log_sd2");
yrfrct_srv2.allocate(styr,endyr,"yrfrct_srv2");
nyrsac_srv2.allocate("nyrsac_srv2");
srv_acyrs2.allocate(1,nyrsac_srv2,"srv_acyrs2");
multN_srv2.allocate(1,nyrsac_srv2,"multN_srv2");
ac_yng_srv2.allocate(1,nyrsac_srv2,"ac_yng_srv2");
ac_old_srv2.allocate(1,nyrsac_srv2,"ac_old_srv2");
nyrslen_srv2.allocate("nyrslen_srv2");
srv_lenyrs2.allocate(1,nyrslen_srv2,"srv_lenyrs2");
multNlen_srv2.allocate(1,nyrslen_srv2,"multNlen_srv2");
srvp2.allocate(1,nyrsac_srv2,rcrage,trmage,"srvp2");
srvlenp2.allocate(1,nyrslen_srv2,1,nbins2,"srvlenp2");
wt_srv2.allocate(styr,endyr,rcrage,trmage,"wt_srv2");
nyrs_srv3.allocate("nyrs_srv3");
srvyrs3.allocate(1,nyrs_srv3,"srvyrs3");
indxsurv3.allocate(1,nyrs_srv3,"indxsurv3");
indxsurv_log_sd3.allocate(1,nyrs_srv3,"indxsurv_log_sd3");
yrfrct_srv3.allocate(styr,endyr,"yrfrct_srv3");
nyrsac_srv3.allocate("nyrsac_srv3");
srv_acyrs3.allocate(1,nyrsac_srv3,"srv_acyrs3");
multN_srv3.allocate(1,nyrsac_srv3,"multN_srv3");
nyrslen_srv3.allocate("nyrslen_srv3");
srv_lenyrs3.allocate(1,nyrslen_srv3,"srv_lenyrs3");
multNlen_srv3.allocate(1,nyrslen_srv3,"multNlen_srv3");
srvp3.allocate(1,nyrsac_srv3,rcrage,trmage,"srvp3");
srvlenp3.allocate(1,nyrslen_srv3,1,nbins2,"srvlenp3");
wt_srv3.allocate(styr,endyr,rcrage,trmage,"wt_srv3");
age_trans.allocate(rcrage,trmage,rcrage,trmage,"age_trans");
len_trans1.allocate(rcrage,trmage,1,nbins1,"len_trans1");
len_trans2.allocate(rcrage,trmage,1,nbins2,"len_trans2");
len_trans3.allocate(rcrage,trmage,1,nbins3,"len_trans3");
wt_pop.allocate(styr,endyr,rcrage,trmage,"wt_pop");
wt_spawn.allocate(styr,endyr,rcrage,trmage,"wt_spawn");
mat_old.allocate(rcrage,trmage,"mat_old");
mat.allocate(rcrage,trmage,"mat");
wt_pop_proj.allocate(rcrage,trmage,"wt_pop_proj");
wt_spawn_proj.allocate(rcrage,trmage,"wt_spawn_proj");
wt_fsh_proj.allocate(rcrage,trmage,"wt_fsh_proj");
wt_srv_proj.allocate(rcrage,trmage,"wt_srv_proj");
Ftarget.allocate(endyr+1,endyr+5,"Ftarget");
B40.allocate("B40");
log_mean_recr_proj.allocate("log_mean_recr_proj");
sigmasq_recr.allocate("sigmasq_recr");
#define MAX_BISECT_ITER 128 // maximum number of iterations for the bisection
#define BISECT_TOL 0.00001 // maximum tolerance for bisection
if (endyr > base_endyr)
{
phase_future = 4;
}
else
{
phase_future = -4;
}
endyr_fsh_dev = base_endyr;
// mess about with the random walk deviations so that the base_endyr+1 and beyond values don't matter in the likelihood calcs
for (i = styr; i < (endyr_fsh_dev - 1); i++)
{
rwlk_sd_short(i) = rwlk_sd(i);
}
rwlk_sd_short(endyr_fsh_dev - 1) = rwlk_sd(endyr-1);
Tier3_alpha = 0.05;
}
void model_parameters::initializationfunction(void)
{
mean_log_initN.set_initial_value(0.0);
mean_log_recruit.set_initial_value(0.0);
mean_log_F.set_initial_value(-1.6);
M.set_initial_value(0.30);
log_q1_bs.set_initial_value(0.0);
log_q1_ek.set_initial_value(0.0);
log_q1_dy.set_initial_value(0.3);
log_q2.set_initial_value(0.0);
log_q3.set_initial_value(-1.6);
slp1_fsh_dev.set_initial_value(0.0);
inf1_fsh_dev.set_initial_value(0.0);
slp2_fsh_dev.set_initial_value(0.0);
inf2_fsh_dev.set_initial_value(0.0);
log_slp1_fsh_mean.set_initial_value(1.0);
inf1_fsh_mean.set_initial_value(4.0);
log_slp2_fsh_mean.set_initial_value(1.0);
inf2_fsh_mean.set_initial_value(8.0);
log_slp1_fsh_mean_const.set_initial_value(1.0);
inf1_fsh_mean_const.set_initial_value(4.0);
log_slp2_fsh_mean_const.set_initial_value(1.0);
inf2_fsh_mean_const.set_initial_value(8.0);
log_slp2_srv1.set_initial_value(1.0);
inf2_srv1.set_initial_value(9.0);
log_slp1_srv2.set_initial_value(-0.8);
inf1_srv2.set_initial_value(47.0);
log_slp2_srv2.set_initial_value(-.14);
inf2_srv2.set_initial_value(7.0);
log_slp1_srv3.set_initial_value(0.0);
inf1_srv3.set_initial_value(5.0);
}
model_parameters::model_parameters(int sz,int argc,char * argv[]) :
model_data(argc,argv) , function_minimizer(sz)
{
initializationfunction();
M.allocate(0.1,0.5,-1,"M");
mean_log_initN.allocate(-15,15,-1,"mean_log_initN");
dev_log_initN.allocate(rcrage+1,trmage,-15,15,-2,"dev_log_initN");
initN.allocate(rcrage+1,trmage,"initN");
#ifndef NO_AD_INITIALIZE
initN.initialize();
#endif
mean_log_recruit.allocate(-15,15,1,"mean_log_recruit");
dev_log_recruit.allocate(styr,endyr,-15,15,4,"dev_log_recruit");
log_recr_proj.allocate(endyr+1,endyr+5,-5,5,10,"log_recr_proj");
recruit_proj.allocate(endyr+1,endyr+5,"recruit_proj");
N_proj.allocate(endyr+1,endyr+5,rcrage,trmage,"N_proj");
#ifndef NO_AD_INITIALIZE
N_proj.initialize();
#endif
F_proj.allocate(endyr+1,endyr+5,"F_proj");
#ifndef NO_AD_INITIALIZE
F_proj.initialize();
#endif
Z_proj.allocate(endyr+1,endyr+5,rcrage,trmage,"Z_proj");
#ifndef NO_AD_INITIALIZE
Z_proj.initialize();
#endif
C_proj.allocate(endyr+1,endyr+5,rcrage,trmage,"C_proj");
#ifndef NO_AD_INITIALIZE
C_proj.initialize();
#endif
Nsrv_proj.allocate(endyr+1,endyr+5,rcrage,trmage,"Nsrv_proj");
#ifndef NO_AD_INITIALIZE
Nsrv_proj.initialize();
#endif
slctfsh_proj.allocate(rcrage,trmage,"slctfsh_proj");
#ifndef NO_AD_INITIALIZE
slctfsh_proj.initialize();
#endif
Ecattot_proj.allocate(endyr+1,endyr+5,"Ecattot_proj");
#ifndef NO_AD_INITIALIZE
Ecattot_proj.initialize();
#endif
Esumbio_proj.allocate(endyr+1,endyr+5,"Esumbio_proj");
Espawnbio_proj.allocate(endyr+1,endyr+5,"Espawnbio_proj");
Esrv_proj.allocate(endyr+1,endyr+5,"Esrv_proj");
Exrate_proj.allocate(endyr+1,endyr+5,"Exrate_proj");
sbio.allocate("sbio");
#ifndef NO_AD_INITIALIZE
sbio.initialize();
#endif
log_slp1_fsh_mean.allocate(-5,5,4,"log_slp1_fsh_mean");
inf1_fsh_mean.allocate(1,5,4,"inf1_fsh_mean");
log_slp2_fsh_mean.allocate(-5,5,4,"log_slp2_fsh_mean");
inf2_fsh_mean.allocate(7,20,4,"inf2_fsh_mean");
slp1_fsh_dev.allocate(styr,endyr_fsh_dev,-5,5,5,"slp1_fsh_dev");
inf1_fsh_dev.allocate(styr,endyr_fsh_dev,-5,5,5,"inf1_fsh_dev");
slp2_fsh_dev.allocate(styr,endyr_fsh_dev,-5,5,5,"slp2_fsh_dev");
inf2_fsh_dev.allocate(styr,endyr_fsh_dev,-5,5,5,"inf2_fsh_dev");
slp1_fsh.allocate(styr,endyr_fsh_dev,"slp1_fsh");
#ifndef NO_AD_INITIALIZE
slp1_fsh.initialize();
#endif
inf1_fsh.allocate(styr,endyr_fsh_dev,"inf1_fsh");
#ifndef NO_AD_INITIALIZE
inf1_fsh.initialize();
#endif
slp2_fsh.allocate(styr,endyr_fsh_dev,"slp2_fsh");
#ifndef NO_AD_INITIALIZE
slp2_fsh.initialize();
#endif
inf2_fsh.allocate(styr,endyr_fsh_dev,"inf2_fsh");
#ifndef NO_AD_INITIALIZE
inf2_fsh.initialize();
#endif
log_slp1_fsh_mean_const.allocate(-5,5,phase_future,"log_slp1_fsh_mean_const");
inf1_fsh_mean_const.allocate(1,5,phase_future,"inf1_fsh_mean_const");
log_slp2_fsh_mean_const.allocate(-5,5,phase_future,"log_slp2_fsh_mean_const");
inf2_fsh_mean_const.allocate(7,20,phase_future,"inf2_fsh_mean_const");
slp1_fsh_const.allocate("slp1_fsh_const");
#ifndef NO_AD_INITIALIZE
slp1_fsh_const.initialize();
#endif
inf1_fsh_const.allocate("inf1_fsh_const");
#ifndef NO_AD_INITIALIZE
inf1_fsh_const.initialize();
#endif
slp2_fsh_const.allocate("slp2_fsh_const");
#ifndef NO_AD_INITIALIZE
slp2_fsh_const.initialize();
#endif
inf2_fsh_const.allocate("inf2_fsh_const");
#ifndef NO_AD_INITIALIZE
inf2_fsh_const.initialize();
#endif
log_slp2_srv1.allocate(-5,5,7,"log_slp2_srv1");
inf2_srv1.allocate(5,20,7,"inf2_srv1");
srv1_age1.allocate(0,2,7,"srv1_age1");
log_slp1_srv2.allocate(-5,5,7,"log_slp1_srv2");
inf1_srv2.allocate(1,50,-1,"inf1_srv2");
log_slp2_srv2.allocate(-5,5,8,"log_slp2_srv2");
inf2_srv2.allocate(5,10,8,"inf2_srv2");
srv2_age1.allocate(0,2,7,"srv2_age1");
log_slp1_srv3.allocate(-5,5,9,"log_slp1_srv3");
inf1_srv3.allocate(1,20,9,"inf1_srv3");
mean_log_F.allocate(-10,10,1,"mean_log_F");
dev_log_F.allocate(styr,endyr,-10,10,2,"dev_log_F");
F.allocate(styr,endyr,"F");
#ifndef NO_AD_INITIALIZE
F.initialize();
#endif
log_q1_bs.allocate(-10,10,5,"log_q1_bs");
log_q1_ek.allocate(-10,10,5,"log_q1_ek");
log_q1_dy.allocate(-10,10,5,"log_q1_dy");
log_q2.allocate(-10,10,-1,"log_q2");
log_q3.allocate(-10,10,6,"log_q3");
q1_bs.allocate("q1_bs");
#ifndef NO_AD_INITIALIZE
q1_bs.initialize();
#endif
q1_ek.allocate("q1_ek");
#ifndef NO_AD_INITIALIZE
q1_ek.initialize();
#endif
q1_dy.allocate("q1_dy");
#ifndef NO_AD_INITIALIZE
q1_dy.initialize();
#endif
q2.allocate("q2");
#ifndef NO_AD_INITIALIZE
q2.initialize();
#endif
q3.allocate("q3");
#ifndef NO_AD_INITIALIZE
q3.initialize();
#endif
avgR.allocate("avgR");
#ifndef NO_AD_INITIALIZE
avgR.initialize();
#endif
avgR_CV.allocate("avgR_CV");
#ifndef NO_AD_INITIALIZE
avgR_CV.initialize();
#endif
SB0.allocate("SB0");
#ifndef NO_AD_INITIALIZE
SB0.initialize();
#endif
R0.allocate("R0");
#ifndef NO_AD_INITIALIZE
R0.initialize();
#endif
phi0.allocate("phi0");
#ifndef NO_AD_INITIALIZE
phi0.initialize();
#endif
SBcurr.allocate("SBcurr");
#ifndef NO_AD_INITIALIZE
SBcurr.initialize();
#endif
F100.allocate("F100");
#ifndef NO_AD_INITIALIZE
F100.initialize();
#endif
SB100.allocate("SB100");
#ifndef NO_AD_INITIALIZE
SB100.initialize();
#endif
SBtarget.allocate("SBtarget");
#ifndef NO_AD_INITIALIZE
SBtarget.initialize();
#endif
F40.allocate("F40");
#ifndef NO_AD_INITIALIZE
F40.initialize();
#endif
SB40.allocate("SB40");
#ifndef NO_AD_INITIALIZE
SB40.initialize();
#endif
F35.allocate("F35");
#ifndef NO_AD_INITIALIZE
F35.initialize();
#endif
SB35.allocate("SB35");
#ifndef NO_AD_INITIALIZE
SB35.initialize();
#endif
F20.allocate("F20");
#ifndef NO_AD_INITIALIZE
F20.initialize();
#endif
SB20.allocate("SB20");
#ifndef NO_AD_INITIALIZE
SB20.initialize();
#endif
F_ABC.allocate("F_ABC");
#ifndef NO_AD_INITIALIZE
F_ABC.initialize();
#endif
ABC.allocate("ABC");
#ifndef NO_AD_INITIALIZE
ABC.initialize();
#endif
F_OFL.allocate("F_OFL");
#ifndef NO_AD_INITIALIZE
F_OFL.initialize();
#endif
OFL.allocate("OFL");
#ifndef NO_AD_INITIALIZE
OFL.initialize();
#endif
N.allocate(styr,endyr+5,rcrage,trmage,"N");
#ifndef NO_AD_INITIALIZE
N.initialize();
#endif
endN.allocate(rcrage,trmage,"endN");
all_recruits.allocate(styr,endyr+5,"all_recruits");
#ifndef NO_AD_INITIALIZE
all_recruits.initialize();
#endif
Z.allocate(styr,endyr,rcrage,trmage,"Z");
#ifndef NO_AD_INITIALIZE
Z.initialize();
#endif
C.allocate(styr,endyr,rcrage,trmage,"C");
#ifndef NO_AD_INITIALIZE
C.initialize();
#endif
Nsrv1.allocate(styr,endyr,rcrage,trmage,"Nsrv1");
#ifndef NO_AD_INITIALIZE
Nsrv1.initialize();
#endif
slctsrv1.allocate(rcrage,trmage,"slctsrv1");
#ifndef NO_AD_INITIALIZE
slctsrv1.initialize();
#endif
Nsrv2.allocate(styr,endyr,rcrage,trmage,"Nsrv2");
#ifndef NO_AD_INITIALIZE
Nsrv2.initialize();
#endif
slctsrv2.allocate(rcrage,trmage,"slctsrv2");
#ifndef NO_AD_INITIALIZE
slctsrv2.initialize();
#endif
Nsrv3.allocate(styr,endyr,rcrage,trmage,"Nsrv3");
#ifndef NO_AD_INITIALIZE
Nsrv3.initialize();
#endif
slctsrv3.allocate(rcrage,trmage,"slctsrv3");
#ifndef NO_AD_INITIALIZE
slctsrv3.initialize();
#endif
slctfsh_base.allocate(rcrage,trmage,"slctfsh_base");
#ifndef NO_AD_INITIALIZE
slctfsh_base.initialize();
#endif
slctfsh.allocate(styr,endyr,rcrage,trmage,"slctfsh");
#ifndef NO_AD_INITIALIZE
slctfsh.initialize();
#endif
slctfsh_const.allocate(rcrage,trmage,"slctfsh_const");
#ifndef NO_AD_INITIALIZE
slctfsh_const.initialize();
#endif
Eecocon.allocate(styr,endyr,"Eecocon");
#ifndef NO_AD_INITIALIZE
Eecocon.initialize();
#endif
Eec.allocate(styr,endyr,rcrage,trmage,"Eec");
#ifndef NO_AD_INITIALIZE
Eec.initialize();
#endif
Ecattot.allocate(styr,endyr,"Ecattot");
#ifndef NO_AD_INITIALIZE
Ecattot.initialize();
#endif
Ecatp.allocate(styr,endyr,rcrage,trmage,"Ecatp");
#ifndef NO_AD_INITIALIZE
Ecatp.initialize();
#endif
Elenp.allocate(styr,endyr,1,nbins1,"Elenp");
#ifndef NO_AD_INITIALIZE
Elenp.initialize();
#endif
Eindxsurv1_bs.allocate(styr,endyr,"Eindxsurv1_bs");
#ifndef NO_AD_INITIALIZE
Eindxsurv1_bs.initialize();
#endif
Eindxsurv1_ek.allocate(styr,endyr,"Eindxsurv1_ek");
#ifndef NO_AD_INITIALIZE
Eindxsurv1_ek.initialize();
#endif
Eindxsurv1_dy.allocate(styr,endyr,"Eindxsurv1_dy");
#ifndef NO_AD_INITIALIZE
Eindxsurv1_dy.initialize();
#endif
Esrvp1.allocate(styr,endyr,rcrage,trmage,"Esrvp1");
#ifndef NO_AD_INITIALIZE
Esrvp1.initialize();
#endif
Esrvlenp1.allocate(styr,endyr,1,nbins3,"Esrvlenp1");
#ifndef NO_AD_INITIALIZE
Esrvlenp1.initialize();
#endif
Eindxsurv2.allocate(styr,endyr,"Eindxsurv2");
#ifndef NO_AD_INITIALIZE
Eindxsurv2.initialize();
#endif
Esrvp2.allocate(styr,endyr,rcrage,trmage,"Esrvp2");
#ifndef NO_AD_INITIALIZE
Esrvp2.initialize();
#endif
Esrvlenp2.allocate(styr,endyr,1,nbins2,"Esrvlenp2");
#ifndef NO_AD_INITIALIZE
Esrvlenp2.initialize();
#endif
Eindxsurv3.allocate(styr,endyr,"Eindxsurv3");
#ifndef NO_AD_INITIALIZE
Eindxsurv3.initialize();
#endif
Esrvp3.allocate(styr,endyr,rcrage,trmage,"Esrvp3");
#ifndef NO_AD_INITIALIZE
Esrvp3.initialize();
#endif
Esrvlenp3.allocate(styr,endyr,1,nbins2,"Esrvlenp3");
#ifndef NO_AD_INITIALIZE
Esrvlenp3.initialize();
#endif
loglik.allocate(1,22,"loglik");
#ifndef NO_AD_INITIALIZE
loglik.initialize();
#endif
llcatp.allocate(1,nyrs_fsh,"llcatp");
#ifndef NO_AD_INITIALIZE
llcatp.initialize();
#endif
lllenp.allocate(1,nyrslen_fsh,"lllenp");
#ifndef NO_AD_INITIALIZE
lllenp.initialize();
#endif
llsrvp1.allocate(1,nyrsac_srv1,"llsrvp1");
#ifndef NO_AD_INITIALIZE
llsrvp1.initialize();
#endif
llsrvlenp1.allocate(1,nyrslen_srv1,"llsrvlenp1");
#ifndef NO_AD_INITIALIZE
llsrvlenp1.initialize();
#endif
llsrvp2.allocate(1,nyrsac_srv2,"llsrvp2");
#ifndef NO_AD_INITIALIZE
llsrvp2.initialize();
#endif
llsrvlenp2.allocate(1,nyrslen_srv2,"llsrvlenp2");
#ifndef NO_AD_INITIALIZE
llsrvlenp2.initialize();
#endif
llsrvp3.allocate(1,nyrsac_srv3,"llsrvp3");
#ifndef NO_AD_INITIALIZE
llsrvp3.initialize();
#endif
llsrvlenp3.allocate(1,nyrslen_srv3,"llsrvlenp3");
#ifndef NO_AD_INITIALIZE
llsrvlenp3.initialize();
#endif
recruit.allocate(styr,endyr,"recruit");
sd_avg_rec.allocate("sd_avg_rec");
Espawnbio.allocate(styr,endyr+1,"Espawnbio");
Esumbio.allocate(styr,endyr+1,"Esumbio");
res_fish.allocate(1,nyrs_fsh,rcrage,2*trmage-rcrage+1,"res_fish");
#ifndef NO_AD_INITIALIZE
res_fish.initialize();
#endif
res_srv1.allocate(1,nyrsac_srv1,rcrage,2*trmage-rcrage+1,"res_srv1");
#ifndef NO_AD_INITIALIZE
res_srv1.initialize();
#endif
res_srv2.allocate(1,nyrsac_srv2,rcrage,2*trmage-rcrage+1,"res_srv2");
#ifndef NO_AD_INITIALIZE
res_srv2.initialize();
#endif
res_srv3.allocate(1,nyrsac_srv3,rcrage,2*trmage-rcrage+1,"res_srv3");
#ifndef NO_AD_INITIALIZE
res_srv3.initialize();
#endif
res_srv3len.allocate(1,nyrslen_srv3,1,2*nbins2,"res_srv3len");
#ifndef NO_AD_INITIALIZE
res_srv3len.initialize();
#endif
pearson_fish.allocate(1,nyrs_fsh,rcrage,trmage,"pearson_fish");
#ifndef NO_AD_INITIALIZE
pearson_fish.initialize();
#endif
pearson_srv1.allocate(1,nyrsac_srv1,rcrage,trmage,"pearson_srv1");
#ifndef NO_AD_INITIALIZE
pearson_srv1.initialize();
#endif
pearson_srv2.allocate(1,nyrsac_srv2,rcrage,trmage,"pearson_srv2");
#ifndef NO_AD_INITIALIZE
pearson_srv2.initialize();
#endif
pearson_srv3.allocate(1,nyrsac_srv3,rcrage,trmage,"pearson_srv3");
#ifndef NO_AD_INITIALIZE
pearson_srv3.initialize();
#endif
pearson_srv3len.allocate(1,nyrslen_srv3,1,nbins2,"pearson_srv3len");
#ifndef NO_AD_INITIALIZE
pearson_srv3len.initialize();
#endif
effN_fsh.allocate(1,nyrs_fsh,"effN_fsh");
#ifndef NO_AD_INITIALIZE
effN_fsh.initialize();
#endif
effN_srv1.allocate(1,nyrsac_srv1,"effN_srv1");
#ifndef NO_AD_INITIALIZE
effN_srv1.initialize();
#endif
effN_srv2.allocate(1,nyrsac_srv2,"effN_srv2");
#ifndef NO_AD_INITIALIZE
effN_srv2.initialize();
#endif
effN_srv3.allocate(1,nyrsac_srv3,"effN_srv3");
#ifndef NO_AD_INITIALIZE
effN_srv3.initialize();
#endif
RMSE_srv1_bs.allocate("RMSE_srv1_bs");
#ifndef NO_AD_INITIALIZE
RMSE_srv1_bs.initialize();
#endif
RMSE_srv1_ek.allocate("RMSE_srv1_ek");
#ifndef NO_AD_INITIALIZE
RMSE_srv1_ek.initialize();
#endif
RMSE_srv1_dy.allocate("RMSE_srv1_dy");
#ifndef NO_AD_INITIALIZE
RMSE_srv1_dy.initialize();
#endif
RMSE_srv2.allocate("RMSE_srv2");
#ifndef NO_AD_INITIALIZE
RMSE_srv2.initialize();
#endif
RMSE_srv3.allocate("RMSE_srv3");
#ifndef NO_AD_INITIALIZE
RMSE_srv3.initialize();
#endif
var_prof.allocate("var_prof");
objfun.allocate("objfun");
prior_function_value.allocate("prior_function_value");
likelihood_function_value.allocate("likelihood_function_value");
}
void model_parameters::preliminary_calculations(void)
{
#if defined(USE_ADPVM)
admaster_slave_variable_interface(*this);
#endif
for (i=1;i<=nyrs_fsh;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_fsh(i))
{
catp(i,ac_yng_fsh(i)) += catp(i,j);
catp(i,j) = 0;
}
if(j>ac_old_fsh(i))
{
catp(i,ac_old_fsh(i)) += catp(i,j);
catp(i,j) = 0;
}
}}
for (i=1;i<=nyrsac_srv1;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_srv1(i))
{
srvp1(i,ac_yng_srv1(i)) += srvp1(i,j);
srvp1(i,j) = 0;
}
if(j>ac_old_srv1(i))
{
srvp1(i,ac_old_srv1(i)) += srvp1(i,j);
srvp1(i,j) = 0;
}
}}
for (i=1;i<=nyrsac_srv2;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_srv2(i))
{
srvp2(i,ac_yng_srv2(i)) += srvp2(i,j);
srvp2(i,j) = 0;
}
if(j>ac_old_srv2(i))
{
srvp2(i,ac_old_srv2(i)) += srvp2(i,j);
srvp2(i,j) = 0;
}
}}
mcmc_iter = 0;
y_frac_sp = 0.21; // this matches what MWD uses; rounded value for 15 March
o = 0.00001;
var_prof.set_stepnumber(30);
var_prof.set_stepsize(0.1);
}
void model_parameters::userfunction(void)
{
objfun =0.0;
ofstream& report1= *pad_report1;
Convert_log_parameters();
Selectivity();
Mortality();
Numbers_at_age();
Catch_at_age();
Expected_values();
if(last_phase())
{
Projections();
}
Objective_function();
MCMC_output();
}
void model_parameters::Convert_log_parameters(void)
{
ofstream& report1= *pad_report1;
for (j=rcrage+1;j<=trmage;j++)
{
initN(j) = mfexp(mean_log_recruit + dev_log_recruit(styr) - M*double(j-rcrage)+dev_log_initN(j));
}
initN(trmage) /= (1.0 - mfexp(-M));
recruit = mfexp(mean_log_recruit + dev_log_recruit);
F = mfexp(mean_log_F + dev_log_F);
q1_bs = mfexp(log_q1_bs);
q1_ek = mfexp(log_q1_ek);
q1_dy = mfexp(log_q1_dy);
q2 = mfexp(log_q2);
q3 = mfexp(log_q3);
}
void model_parameters::Selectivity(void)
{
ofstream& report1= *pad_report1;
for (i=styr;i<=endyr_fsh_dev;i++)
{
slp1_fsh(i)=mfexp(log_slp1_fsh_mean+slp1_fsh_dev(i));
inf1_fsh(i)=inf1_fsh_mean+inf1_fsh_dev(i);
slp2_fsh(i)=mfexp(log_slp2_fsh_mean+slp2_fsh_dev(i));
inf2_fsh(i)=inf2_fsh_mean+inf2_fsh_dev(i);
for (j=rcrage;j<=trmage;j++)
{
slctfsh(i,j) = (1/(1+mfexp(-(slp1_fsh(i))*(double(j)-(inf1_fsh(i))))))*
(1-1/(1+mfexp(-(slp2_fsh(i))*(double(j)-(inf2_fsh(i))))));
}
slctfsh(i)=slctfsh(i)/slctfsh(i,6);
}
// ZTA - calculate constant future fishery selectivity
if (endyr > base_endyr)
{
slctfsh_const.initialize();
slp1_fsh_const=mfexp(log_slp1_fsh_mean_const);
inf1_fsh_const=inf1_fsh_mean_const;
slp2_fsh_const=mfexp(log_slp2_fsh_mean_const);
inf2_fsh_const=inf2_fsh_mean_const;
for (j = rcrage; j <= trmage; j++)
{
slctfsh_const(j) = (1.0/(1.0+mfexp(-(slp1_fsh_const)*(double(j)-(inf1_fsh_const)))))*
(1.0-(1.0/(1.0+mfexp(-(slp2_fsh_const)*(double(j)-(inf2_fsh_const))))));
}
slctfsh_const /= max(slctfsh_const);
for (i = (base_endyr+1); i <= endyr; i++)
{
slctfsh(i) = slctfsh_const;
}
}
for (j=rcrage;j<=trmage;j++)
{
slctfsh_base(j) = (1.0/(1.0+mfexp(-(mfexp(log_slp1_fsh_mean))*(double(j)-(inf1_fsh_mean)))))*
(1.0-1.0/(1.0+mfexp(-(mfexp(log_slp2_fsh_mean))*(double(j)-(inf2_fsh_mean)))));
}
slctfsh_base=slctfsh_base/max(slctfsh_base);
for (j=rcrage;j<=trmage;j++)
{
slctsrv1(j) = (1-1/(1+mfexp(-mfexp(log_slp2_srv1)*(double(j)-inf2_srv1))));
}
slctsrv1=slctsrv1/slctsrv1(2);
slctsrv1(rcrage)=srv1_age1;
for (j=rcrage;j<=trmage;j++)
{
slctsrv2(j) = (1/(1+mfexp(-mfexp(log_slp1_srv2)*(double(j)-inf1_srv2))))
*(1-1/(1+mfexp(-mfexp(log_slp2_srv2)*(double(j)-inf2_srv2))));
}
slctsrv2=slctsrv2/slctsrv2(7);
slctsrv2(rcrage)=srv2_age1;
for (j=rcrage;j<=trmage;j++)
{
slctsrv3(j) = (1/(1+mfexp(-mfexp(log_slp1_srv3)*(double(j)-inf1_srv3))));
}
slctsrv3=slctsrv3/slctsrv3(10);
}
void model_parameters::Mortality(void)
{
ofstream& report1= *pad_report1;
for (i=styr;i<=endyr;i++)
{
for (j=rcrage;j<=trmage;j++)
{
Z(i,j)=(F(i)*slctfsh(i,j))+M;
}}
}
void model_parameters::Numbers_at_age(void)
{
ofstream& report1= *pad_report1;
N.initialize();
N(styr)(rcrage+1,trmage)=initN;
for (i=styr;i<=endyr;i++)
{
N(i,rcrage)=recruit(i);
}
for (i=styr;i<endyr;i++)
{
for (j=rcrage;j<trmage;j++)
{
N(i+1,j+1)=N(i,j)*mfexp(-Z(i,j));
}
N(i+1,trmage)+=N(i,trmage)*mfexp(-Z(i,trmage));
}
endN=N(endyr);
sd_avg_rec = mean(recruit((hcr_styr+rcrage),(endyr-1)));
}
void model_parameters::Catch_at_age(void)
{
ofstream& report1= *pad_report1;
for (i=styr;i<=endyr;i++)
{
for (j=rcrage;j<=trmage;j++)
{
C(i,j)=N(i,j)*((F(i)*slctfsh(i,j))/Z(i,j))*(1-mfexp(-Z(i,j)));
Eec(i,j)=N(i,j)*(M/Z(i,j))*(1-mfexp(-Z(i,j)));
Nsrv1(i,j)=slctsrv1(j)*N(i,j)*mfexp(-yrfrct_srv1(i)*Z(i,j));
Nsrv2(i,j)=slctsrv2(j)*N(i,j)*mfexp(-yrfrct_srv2(i)*Z(i,j));
Nsrv3(i,j)=slctsrv3(j)*N(i,j)*mfexp(-yrfrct_srv3(i)*Z(i,j));
}}
}
void model_parameters::Expected_values(void)
{
ofstream& report1= *pad_report1;
for (i=styr;i<=endyr;i++)
{
Ecattot(i) = 1000000*sum(elem_prod(C(i),wt_fsh(i)));
Eecocon(i) = 1000000*sum(elem_prod(Eec(i),wt_pop(i)));
Ecatp(i) = (C(i)/sum(C(i)))*age_trans;
Elenp(i) = Ecatp(i) * len_trans1;
Eindxsurv1_bs(i)= q1_bs*sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-yrfrct_srv1(i)*Z(i))),slctsrv1),wt_srv1(i)));
Eindxsurv1_ek(i)= q1_ek*sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-yrfrct_srv1(i)*Z(i))),slctsrv1),wt_srv1(i)));
Eindxsurv1_dy(i)= q1_dy*sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-yrfrct_srv1(i)*Z(i))),slctsrv1),wt_srv1(i)));
Esrvp1(i) = (Nsrv1(i)/sum(Nsrv1(i)))*age_trans;
Esrvlenp1(i) = Esrvp1(i) * len_trans3;
Eindxsurv2(i)= q2*sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-yrfrct_srv2(i)*Z(i))),slctsrv2),wt_srv2(i)));
Esrvp2(i) = (Nsrv2(i)/sum(Nsrv2(i)))*age_trans;
Esrvlenp2(i) = Esrvp2(i) * len_trans2;
Eindxsurv3(i)= q3*sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-yrfrct_srv3(i)*Z(i))),slctsrv3),wt_srv3(i)));
Esrvp3(i) = (Nsrv3(i)/sum(Nsrv3(i)))*age_trans;
Esrvlenp3(i) = Esrvp3(i) * len_trans2;
Esumbio(i)= N(i)(rcrage+2,trmage)*wt_pop(i)(rcrage+2,trmage);
Espawnbio(i)= sum(elem_prod(elem_prod(elem_prod(N(i),mfexp(-0.21*Z(i))),wt_spawn(i)),0.5*mat));
}
for (i=1;i<=nyrs_fsh;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_fsh(i))
{
Ecatp(fshyrs(i),ac_yng_fsh(i)) += Ecatp(fshyrs(i),j);
Ecatp(fshyrs(i),j) = 0;
}
if(j>ac_old_fsh(i))
{
Ecatp(fshyrs(i),ac_old_fsh(i)) += Ecatp(fshyrs(i),j);
Ecatp(fshyrs(i),j) = 0;
}
}}
for (i=1;i<=nyrsac_srv1;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_srv1(i))
{
Esrvp1(srv_acyrs1(i),ac_yng_srv1(i)) += Esrvp1(srv_acyrs1(i),j);
Esrvp1(srv_acyrs1(i),j) = 0;
}
if(j>ac_old_srv1(i))
{
Esrvp1(srv_acyrs1(i),ac_old_srv1(i)) += Esrvp1(srv_acyrs1(i),j);
Esrvp1(srv_acyrs1(i),j) = 0;
}
}}
for (i=1;i<=nyrsac_srv2;i++)
{
for (j=rcrage;j<=trmage;j++)
{
if(j<ac_yng_srv2(i))
{
Esrvp2(srv_acyrs2(i),ac_yng_srv2(i)) += Esrvp2(srv_acyrs2(i),j);
Esrvp2(srv_acyrs2(i),j) = 0.;
}
if(j>ac_old_srv2(i))
{
Esrvp2(srv_acyrs2(i),ac_old_srv2(i)) += Esrvp2(srv_acyrs2(i),j);
Esrvp2(srv_acyrs2(i),j) = 0;
}
}}
}
void model_parameters::Projections(void)
{
ofstream& report1= *pad_report1;
dvariable sbio, sumbio;
sbio = sumbio = 0.0;
all_recruits.initialize();
all_recruits = column(N,rcrage);
for (i=endyr+1;i<=endyr+5;i++)
{
recruit_proj(i)=mfexp(log_recr_proj(i)+(sigmasq_recr/2));
all_recruits(i) = mean(recruit((hcr_styr+rcrage),(endyr-1)));
}
for (i=endyr+1;i<=endyr+5;i++)
{
N_proj(i,rcrage)=recruit_proj(i);
}
for (j=rcrage;j<trmage;j++)
{
N_proj(endyr+1,j+1)=N(endyr,j)*mfexp(-Z(endyr,j));
}
N_proj(endyr+1,trmage)+=N(endyr,trmage)*mfexp(-Z(endyr,trmage));
endyr_avg_slct=endyr-1;
styr_avg_slct=endyr_avg_slct-4;
for (j=rcrage;j<=trmage;j++)
{
slctfsh_proj(j) = 0;
for (i=styr_avg_slct;i<=endyr_avg_slct;i++)
{
slctfsh_proj(j) += slctfsh(i,j);
}
}
slctfsh_proj=slctfsh_proj/max(slctfsh_proj);
for (i=endyr+1;i<=endyr+5;i++)
{
// ZTA - assuming that N() are the numbers-at-age at the beginning of the year,
// ZTA - this updates N() for use in calculate_curr_bio_ref_points()
N(i) = N_proj(i);
// ZTA - calculate values for decision rule
F100 = get_spr_rates(1.00, slctfsh_proj, (i-1));
SB100 = SBcurr;
F40 = get_spr_rates(0.40, slctfsh_proj, (i-1));
SB40 = SBcurr;
F35 = get_spr_rates(0.35, slctfsh_proj, (i-1));
SB35 = SBcurr;
F20 = get_spr_rates(0.20, slctfsh_proj, (i-1));
SB20 = SBcurr;
SBtarget = SB40 * (F35 / F40);
// ZTA - initialize
F_proj(i) = F40;
// cout << "in Projections:\tyear " << i << "\tF40 " << F40 << "\tSBtarget " << SBtarget << endl;
for (loop=1;loop<=10;loop++)
{
for (j=rcrage;j<=trmage;j++)
{
Z_proj(i,j)=(F_proj(i)*slctfsh_proj(j))+M;
}
sbio = sum(elem_prod(elem_prod(elem_prod(N_proj(i),mfexp(-0.21*Z_proj(i))),wt_spawn_proj),0.5*mat));
// MWD old version
// F_proj(i)=Ftarget(i);
// if (sbio < B40)
// {
// F_proj(i)=Ftarget(i)*(((sbio/B40)-0.05)/(1-0.05));
// }
// }
if (sbio < (0.25 * SB20))
{
F_proj(i) = 0.0;
}
else if (sbio < SB20)
{
// F_proj(i) = 0.0;
// one one-thousandth of the current biomass caught as bycatch in other fisheries
sumbio = sum(elem_prod(N_proj(i)(rcrage+2,trmage),wt_pop_proj(rcrage+2,trmage)));
F_proj(i) = solve_for_fishing_mortality((0.001*1000000.0*sumbio),i);
}
else if (sbio < SBtarget)
{
F_proj(i)=F40*(((sbio/SBtarget)-0.05)/(1.0-0.05));
}
else
{
F_proj(i)=F40;
}
}
for (j=rcrage;j<=trmage;j++)
{
Z_proj(i,j)=(F_proj(i)*slctfsh_proj(j))+M;
}
sbio = sum(elem_prod(elem_prod(elem_prod(N_proj(i),mfexp(-0.21*Z_proj(i))),wt_spawn_proj),0.5*mat));
if (sbio < SB20)
{
sumbio = sum(elem_prod(N_proj(i)(rcrage+2,trmage),wt_pop_proj(rcrage+2,trmage)));
cout << "in stock_assess::Projections:\tyear " << i << ", B40 " << B40 << ", SB40 " << SB40 << ", SB20 " << SB20 << ", Low SB " << sbio << ", sumbio " << sumbio << ", F_ABC " << F_proj(i) << endl;
}
if(i<endyr+5)
{
for (j=rcrage;j<trmage;j++)
{
N_proj(i+1,j+1)=N_proj(i,j)*mfexp(-Z_proj(i,j));
}
N_proj(i+1,trmage)+=N_proj(i,trmage)*mfexp(-Z_proj(i,trmage));
N(i+1) = N_proj(i+1);
}
for (j=rcrage;j<=trmage;j++)
{
C_proj(i,j)=N_proj(i,j)*((F_proj(i)*slctfsh_proj(j))/Z_proj(i,j))*(1-mfexp(-Z_proj(i,j)));
Nsrv_proj(i,j)=N_proj(i,j)*mfexp(-yrfrct_srv1(endyr)*Z_proj(i,j));
}
Ecattot_proj(i) = 1000000*sum(elem_prod(C_proj(i),wt_fsh_proj));
Esumbio_proj(i)= N_proj(i)(rcrage+2,trmage)*wt_pop_proj(rcrage+2,trmage);
Exrate_proj(i)=Ecattot_proj(i)/(1000000*Esumbio_proj(i));
Espawnbio_proj(i)= sum(elem_prod(elem_prod(elem_prod(N_proj(i),mfexp(-0.21*Z_proj(i))),wt_spawn_proj),0.5*mat));
Esrv_proj(i)= q1_ek*sum(elem_prod(elem_prod(elem_prod(N_proj(i),mfexp(-yrfrct_srv1(endyr)*Z_proj(i))),slctsrv1),wt_srv_proj));
}
}
void model_parameters::Objective_function(void)
{