-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhydra_sim.cpp
More file actions
2296 lines (2255 loc) · 105 KB
/
Copy pathhydra_sim.cpp
File metadata and controls
2296 lines (2255 loc) · 105 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
#ifdef DEBUG
#ifndef __SUNPRO_C
#include <cfenv>
#include <cstdlib>
#endif
#endif
//Including C++ libraries
#include "statsLib.h"
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <sstream>
#include <time.h>
time_t baseTime;
clock_t startTime = clock();
// ofstream test("test.csv"); // for debugging only
ofstream gavjunk("gav.junk");
ofstream pmse_predvals("pmse_predvals.out");
#ifdef DEBUG
#include <chrono>
#endif
#include <admodel.h>
#ifdef USE_ADMB_CONTRIBS
#include <contrib.h>
#endif
extern "C" {
void ad_boundf(int i);
}
#include <hydra_sim.htp>
model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
{
adstring tmpstring;
tmpstring=adprogram_name + adstring(".dat");
if (argc > 1)
{
int on=0;
if ( (on=option_match(argc,argv,"-ind"))>-1)
{
if (on>argc-2 || argv[on+1][0] == '-')
{
cerr << "Invalid input data command line option"
" -- ignored" << endl;
}
else
{
tmpstring = adstring(argv[on+1]);
}
}
}
global_datafile = new cifstream(tmpstring);
if (!global_datafile)
{
cerr << "Error: Unable to allocate global_datafile in model_data constructor.";
ad_exit(1);
}
if (!(*global_datafile))
{
delete global_datafile;
global_datafile=NULL;
}
int on,opt;
sim=0;
rseed=1;
//the following line checks for the "-sim" command line option
//if it exists the if statement retreives the random number seed
//that is required for the simulation model
if((on=option_match(ad_comm::argc,ad_comm::argv,"-sim",opt))>-1)
{
sim=1;
rseed=atoi(ad_comm::argv[on+1]);
}
debug.allocate("debug");
Nyrs.allocate("Nyrs");
Nspecies.allocate("Nspecies");
Nsizebins.allocate("Nsizebins");
Nareas.allocate("Nareas");
Nfleets.allocate("Nfleets");
Nsurveys.allocate("Nsurveys");
Totsizebins = Nspecies*Nsizebins;
maxThreshold.allocate(1,Nareas);
Nprey = Nspecies + 1;
o = 0.001; //small number to add before taking logs in objective function calcs
wtconv.allocate("wtconv");
datfilename.allocate("datfilename");
binwidth.allocate(1,Nspecies,1,Nsizebins,"binwidth");
lenwt_a.allocate(1,Nspecies,"lenwt_a");
lenwt_b.allocate(1,Nspecies,"lenwt_b");
lbinmax.allocate(1,Nspecies,1,Nsizebins);
lbinmin.allocate(1,Nspecies,1,Nsizebins);
lbinmidpt.allocate(1,Nspecies,1,Nsizebins);
wtbinmax.allocate(1,Nspecies,1,Nsizebins);
wtbinmin.allocate(1,Nspecies,1,Nsizebins);
wtatlbinmidpt.allocate(1,Nspecies,1,Nsizebins);
binavgwt.allocate(1,Nspecies,1,Nsizebins);
powlbinmaxb.allocate(1,Nspecies,1,Nsizebins);
for (spp=1; spp<=Nspecies; spp++){
lbinmax(spp,1) = binwidth(spp,1);
lbinmin(spp,1) = 0.0; //lowest bin assumed to start at 0!
lbinmidpt(spp,1) = binwidth(spp,1)/2.0;
for (size=2; size<=Nsizebins; size++){
lbinmax(spp, size) = binwidth(spp, size) + lbinmax(spp, size-1);
lbinmin(spp, size) = lbinmax(spp, size-1);
lbinmidpt(spp, size) = binwidth(spp, size)/2.0 + lbinmax(spp, size-1);
}
wtbinmax(spp) = lenwt_a(spp)* pow(lbinmax(spp), lenwt_b(spp));
wtbinmin(spp) = lenwt_a(spp)* pow(lbinmin(spp), lenwt_b(spp));
wtatlbinmidpt(spp) = lenwt_a(spp)* pow(lbinmidpt(spp), lenwt_b(spp));
}
binavgwt = (wtbinmin + wtbinmax)/2.0;
Nrecruitment_cov.allocate("Nrecruitment_cov");
Nmaturity_cov.allocate("Nmaturity_cov");
Ngrowth_cov.allocate("Ngrowth_cov");
recruitment_cov.allocate(1,Nrecruitment_cov,1,Nyrs,"recruitment_cov");
maturity_cov.allocate(1,Nmaturity_cov,1,Nyrs,"maturity_cov");
growth_cov.allocate(1,Ngrowth_cov,1,Nyrs,"growth_cov");
obs_effort.allocate(1,Nareas,1,Nfleets,1,Nyrs,"obs_effort");
mean_stomwt.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"mean_stomwt");
obs_temp.allocate(1,Nareas,1,Nyrs,"obs_temp");
yr1Nphase.allocate("yr1Nphase");
recphase.allocate("recphase");
avg_rec_phase.allocate("avg_rec_phase");
recsigmaphase.allocate("recsigmaphase");
avg_F_phase.allocate("avg_F_phase");
dev_rec_phase.allocate("dev_rec_phase");
dev_F_phase.allocate("dev_F_phase");
fqphase.allocate("fqphase");
fsphase.allocate("fsphase");
sqphase.allocate("sqphase");
ssphase.allocate("ssphase");
ssig_phase.allocate("ssig_phase");
csig_phase.allocate("csig_phase");
m1_phase.allocate("m1_phase");
oF1_phase.allocate("oF1_phase");
oFdev_phase.allocate("oFdev_phase");
vuln_phase.allocate("vuln_phase");
recGamma_alpha.allocate(1,Nareas,1,Nspecies,"recGamma_alpha");
recGamma_shape.allocate(1,Nareas,1,Nspecies,"recGamma_shape");
recGamma_beta.allocate(1,Nareas,1,Nspecies,"recGamma_beta");
recDS_alpha.allocate(1,Nareas,1,Nspecies,"recDS_alpha");
recDS_shape.allocate(1,Nareas,1,Nspecies,"recDS_shape");
recDS_beta.allocate(1,Nareas,1,Nspecies,"recDS_beta");
recGamSSB_alpha.allocate(1,Nareas,1,Nspecies,"recGamSSB_alpha");
recGamSSB_shape.allocate(1,Nareas,1,Nspecies,"recGamSSB_shape");
recGamSSB_beta.allocate(1,Nareas,1,Nspecies,"recGamSSB_beta");
recRicker_alpha.allocate(1,Nareas,1,Nspecies,"recRicker_alpha");
recRicker_shape.allocate(1,Nareas,1,Nspecies,"recRicker_shape");
recRicker_beta.allocate(1,Nareas,1,Nspecies,"recRicker_beta");
recBH_alpha.allocate(1,Nareas,1,Nspecies,"recBH_alpha");
recBH_shape.allocate(1,Nareas,1,Nspecies,"recBH_shape");
recBH_beta.allocate(1,Nareas,1,Nspecies,"recBH_beta");
recShepherd_alpha.allocate(1,Nareas,1,Nspecies,"recShepherd_alpha");
recShepherd_shape.allocate(1,Nareas,1,Nspecies,"recShepherd_shape");
recShepherd_beta.allocate(1,Nareas,1,Nspecies,"recShepherd_beta");
recHockey_alpha.allocate(1,Nareas,1,Nspecies,"recHockey_alpha");
recHockey_shape.allocate(1,Nareas,1,Nspecies,"recHockey_shape");
recHockey_beta.allocate(1,Nareas,1,Nspecies,"recHockey_beta");
recSegmented_alpha.allocate(1,Nareas,1,Nspecies,"recSegmented_alpha");
recSegmented_shape.allocate(1,Nareas,1,Nspecies,"recSegmented_shape");
recSegmented_beta.allocate(1,Nareas,1,Nspecies,"recSegmented_beta");
rectype.allocate(1,Nspecies,"rectype");
stochrec.allocate(1,Nspecies,"stochrec");
rec_alpha.allocate(1,Nareas,1,Nspecies);
rec_shape.allocate(1,Nareas,1,Nspecies);
rec_beta.allocate(1,Nareas,1,Nspecies);
for (area=1; area<=Nareas; area++){
for(spp=1; spp<=Nspecies; spp++){
switch (rectype (spp)){
case 1: //egg production based recruitment, 3 par gamma (Ricker-ish)
rec_alpha(area,spp) = recGamma_alpha(area,spp);
rec_shape(area,spp) = recGamma_shape(area,spp);
rec_beta(area,spp) = recGamma_beta(area,spp);
break;
case 2: //SSB based recruitment, 3 par Deriso-Schnute; see Quinn & Deriso 1999 p 95
rec_alpha(area,spp) = recDS_alpha(area,spp);
rec_shape(area,spp) = recDS_shape(area,spp);
rec_beta(area,spp) = recDS_beta(area,spp);
break;
case 3: //SSB based recruitment, 3 par gamma
rec_alpha(area,spp) = recGamSSB_alpha(area,spp);
rec_shape(area,spp) = recGamSSB_shape(area,spp);
rec_beta(area,spp) = recGamSSB_beta(area,spp);
break;
case 4: //SSB based recruitment, 2 par Ricker
rec_alpha(area,spp) = recRicker_alpha(area,spp);
rec_shape(area,spp) = recRicker_shape(area,spp);
rec_beta(area,spp) = recRicker_beta(area,spp);
break;
case 5: //SSB based recruitment, 2 par BevHolt
rec_alpha(area,spp) = recBH_alpha(area,spp);
rec_shape(area,spp) = recBH_shape(area,spp);
rec_beta(area,spp) = recBH_beta(area,spp);
break;
case 6: // SSB based recruitment, 3 parameters Shepherd
rec_alpha(area,spp) = recShepherd_alpha(area,spp);
rec_shape(area,spp) = recShepherd_shape(area,spp);
rec_beta(area,spp) = recShepherd_beta(area,spp);
break;
case 7: // SSB based rcruitment. hockeyStick
rec_alpha(area,spp) = recHockey_alpha(area,spp);
rec_shape(area,spp) = recHockey_shape(area,spp);
rec_beta(area,spp) = recHockey_beta(area,spp);
break;
case 8: // SSB based recruitment,segmented regresion with breakpoint
rec_alpha(area,spp) = recSegmented_alpha(area,spp);
rec_shape(area,spp) = recSegmented_shape(area,spp);
rec_beta(area,spp) = recSegmented_beta(area,spp);
break;
case 9: //no functional form, uses average+devs in .pin file
rec_alpha(area,spp) = 0;
rec_shape(area,spp) = 0;
rec_beta(area,spp) = 0;
break;
default:
cout<<"undefined recruitment type, check .dat file"<<endl;
exit(1);
}
}
}
sexratio.allocate(1,Nareas,1,Nspecies,"sexratio");
recruitment_covwt.allocate(1,Nspecies,1,Nrecruitment_cov,"recruitment_covwt");
fecund_d.allocate(1,Nareas,1,Nspecies,"fecund_d");
fecund_h.allocate(1,Nareas,1,Nspecies,"fecund_h");
fecund_theta.allocate(1,Nareas,1,Nspecies,1,Nsizebins,"fecund_theta");
fecundity.allocate(1,Nareas,1,Nspecies,1,Nsizebins);
for (area=1; area<=Nareas; area++){
for(spp=1; spp<=Nspecies; spp++){
fecundity(area, spp) = elem_prod(fecund_theta(area, spp),
(fecund_d(area, spp)
* pow(lbinmidpt(spp),fecund_h(area, spp))));
}
}
maturity_nu.allocate(1,Nareas,1,Nspecies,"maturity_nu");
maturity_omega.allocate(1,Nareas,1,Nspecies,"maturity_omega");
maturity_covwt.allocate(1,Nspecies,1,Nmaturity_cov,"maturity_covwt");
covariates_M.allocate(1,Nspecies,1,Nyrs);
growth_psi.allocate(1,Nareas,1,Nspecies,"growth_psi");
growth_kappa.allocate(1,Nareas,1,Nspecies,"growth_kappa");
growth_covwt.allocate(1,Nspecies,1,Ngrowth_cov,"growth_covwt");
vonB_Linf.allocate(1,Nareas,1,Nspecies,"vonB_Linf");
vonB_k.allocate(1,Nareas,1,Nspecies,"vonB_k");
growthtype.allocate(1,Nspecies,"growthtype");
phimax.allocate("phimax");
growthprob_phi.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins);
delta_t.allocate(1,Nsizebins);
lmax_test.allocate(1,2);
growth_numerator.allocate(1,Nsizebins);
growth_denominator.allocate(1,Nsizebins);
for (area=1; area<=Nareas; area++){
for(spp=1; spp<=Nspecies; spp++){
for(yr=1; yr<=Nyrs; yr++){
switch (growthtype (spp)){
case 1: //exponential no covariates
// these yimes of growing out of bin relative to size zero. SGaichas
delta_t = pow((lbinmax(spp)/growth_psi(area, spp)),(1.0/growth_kappa(area, spp)));
// these are "probabilities" of growing into size bin, r given in size bin r-1. ABeet
growthprob_phi(area, spp, yr,1) = 1/delta_t(1);
for (int isize=2;isize<=Nsizebins; isize++) {
growthprob_phi(area, spp, yr, isize) = 1/(delta_t(isize) - delta_t(isize-1));
}
break;
case 2: //exponential with covariates
// these "probabilitlies of growing out of bin relative to size zero. SGaichas
delta_t = pow((lbinmax(spp)/growth_psi(area, spp)* mfexp(growth_covwt(spp)*trans(growth_cov)(yr))),
(1.0/growth_kappa(area, spp)));
// these are "probabilities" of growing into size bin, r given in size bin r-1. ABeet
growthprob_phi(area, spp, yr,1) = 1/delta_t(1);
for (int isize=2;isize<=Nsizebins; isize++) {
growthprob_phi(area, spp, yr, isize) = 1/(delta_t(isize) - delta_t(isize-1));
}
break;
case 3: //VonB no covariates
for (size=1;size<=Nsizebins;size++) {
if (lbinmin(spp,size)>=vonB_Linf(area, spp) || lbinmax(spp,size)>=vonB_Linf(area, spp)) {
growthprob_phi(area, spp, yr, size) = 0.0;
}
if (lbinmax(spp,size)<vonB_Linf(area, spp)) {
growthprob_phi(area, spp, yr, size) = vonB_k(area, spp)/log(
(vonB_Linf(area, spp)-lbinmin(spp,size))/
(vonB_Linf(area, spp)-lbinmax(spp,size)));
}
}
break;
case 4: //VonB with covariates
////////// 2026-08-10 GAVIN FAY, added this trap because as growth varies over time bin mins/maxs may not align with adjusted Linfinitys. This may not be the best way to do it.
growth_numerator = (vonB_Linf(area, spp)*mfexp(growth_covwt(spp)*trans(growth_cov)(yr))-lbinmin(spp));
growth_denominator = (vonB_Linf(area, spp)*mfexp(growth_covwt(spp)*trans(growth_cov)(yr))-lbinmax(spp));
growthprob_phi(area, spp, yr) = vonB_k(area, spp)/log(
elem_div(growth_numerator,growth_denominator));
for (size=1;size<Nsizebins;size++) {
if(growth_denominator(size)<0. || growth_numerator(size)<0.) growthprob_phi(area,spp,yr)(size) = 0.;
}
break;
default:
cout<<"undefined growth type, check .dat file"<<endl;
exit(1);
}
growthprob_phi(area, spp, yr)(Nsizebins) = 0.0; //set prob of outgrowing highest bin to 0
double tempmax = max(growthprob_phi(area, spp, yr));
phimax = max(tempmax,phimax);
cout << "Growthprob " << spp << " " << yr << " " << growthprob_phi(area,spp,yr) << endl;
}
}
growthprob_phi(area) /= phimax; //rescale so no group has >1 prob growing out
}
// growthprob_phi /= phimax; //rescale so no group has >1 prob growing out--not working on 4d array
Nstepsyr = round(phimax); //set model timestep to phimax
Tottimesteps = Nstepsyr*Nyrs; //for scaling state variable arrays
intake_alpha.allocate(1,Nareas,1,Nspecies,"intake_alpha");
intake_beta.allocate(1,Nareas,1,Nspecies,"intake_beta");
intake.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins);
for (area=1; area<=Nareas; area++){
for(spp=1; spp<=Nspecies; spp++){
for(yr=1; yr<=Nyrs; yr++){
intake(area, spp, yr) = 24.0 * (intake_alpha (area, spp) *
mfexp(intake_beta (area, spp) * obs_temp (area,yr))) *
mean_stomwt(area, spp,yr) * //daily intake in g
365.0 / //annual intake
Nstepsyr; //intake per model timestep
}
}
}
isprey.allocate(1,Nareas,1,Nspecies,1,Nspecies,"isprey");
Npreypar = 0;
Npred = 0;
Npreypar = sum(isprey(1));
for (spp=1;spp<=Nspecies;spp++) {
if(sum(extract_column(isprey(1),spp))>0) Npred += 1;
}
preferred_wtratio.allocate(1,Nareas,1,Nspecies,"preferred_wtratio");
sd_sizepref.allocate(1,Nspecies,"sd_sizepref");
wtratio.allocate(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins);
for (area=1; area<=Nareas; area++){
for (pred=1; pred<=Nspecies; pred++){
for(prey=1; prey<=Nspecies; prey++){
dmatrix wttemp = outer_prod(wtatlbinmidpt(prey), 1.0/wtatlbinmidpt(pred));// ijth = prey size i/pred size j
wttemp.rowshift(prey*Nsizebins-(Nsizebins-1));
// since wttemp is inserted into a larger matrix you need to set the .rowmin() property to the row it will be inseted into
wtratio(area, pred).sub(prey*Nsizebins-(Nsizebins-1), prey*Nsizebins) = wttemp;
}
}
} //
sizepref.allocate(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins);
// log normal distribution mu's and sigmas, read in. wtratioprey variable.
for (area=1; area<=Nareas; area++){
for (pred=1; pred<=Nspecies; pred++){
for(prey=1; prey<=Totsizebins; prey++){
for(int isize=1; isize<=Nsizebins; isize++){
double wtratioprey = wtratio(area, pred, prey, isize);
sizepref(area, pred, prey, isize) =
1/(wtratioprey*sd_sizepref(pred)*sqrt(2*M_PI))*exp(-square(log(wtratioprey)-preferred_wtratio(area, pred))/(2*square(sd_sizepref(pred))));
}
}
}
} //ok
B0.allocate(1,Nareas,1,Nspecies,"B0");
Nguilds.allocate("Nguilds");
catchToDiscardsGuild.allocate(1,Nareas,1,Nguilds);
catchToDiscardsSpecies.allocate(1,Nareas,1,Nspecies);
maxGuildThreshold.allocate(1,Nareas,1,Nguilds);
maxSpeciesThreshold.allocate(1,Nareas,1,Nspecies);
guildMembers.allocate(1,Nspecies,"guildMembers");
fleetMembers.allocate(1,Nguilds,"fleetMembers");
AssessmentPeriod.allocate("AssessmentPeriod");
B0_guilds.allocate(1,Nareas,1,Nguilds);
for (area=1; area<=Nareas; area++) {
for (iguild=1; iguild<=Nguilds; iguild++ ) {
for (spp=1; spp<=Nspecies; spp++) {
if (guildMembers(spp)== iguild) {
// sum up equilibr biomass for each guild
B0_guilds(area,iguild) += B0(area,spp);
}
}
}
}
flagRamp.allocate("flagRamp");
minExploitation.allocate(1,Nfleets,"minExploitation");
maxExploitation.allocate(1,Nfleets,"maxExploitation");
minMaxExploitation.allocate(1,2,"minMaxExploitation");
minMaxThreshold.allocate(1,2,"minMaxThreshold");
Nthresholds.allocate("Nthresholds");
threshold_proportion.allocate(1,Nthresholds,"threshold_proportion");
exploitation_levels.allocate(1,Nthresholds,"exploitation_levels");
threshold_species.allocate(1,Nspecies,"threshold_species");
AssessmentOn.allocate("AssessmentOn");
speciesDetection.allocate("speciesDetection");
LFI_size.allocate("LFI_size");
scaleInitialN.allocate("scaleInitialN");
effortScaled.allocate(1,Nareas,1,Nspecies,"effortScaled");
discard_Coef.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins,"discard_Coef");
discardSurvival_Coef.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins,"discardSurvival_Coef");
predOrPrey.allocate(1,Nspecies,"predOrPrey");
bandwidth_metric.allocate("bandwidth_metric");
baseline_threshold.allocate("baseline_threshold");
indicator_fishery_q.allocate(1,Nareas,1,Nfleets,1,Nspecies,"indicator_fishery_q");
Nqpars = sum(indicator_fishery_q)-(Nfleets*Nareas);
f_map.allocate(1,Nareas,1,Nfleets);
dim2 = Nqpars;
if (dim2 == 0) dim2 = 1;
q_map.allocate(1,dim2,1,3);
f_map = 0;
q_map = 0;
dum = 0;
for(int area=1;area<=Nareas;area++) {
for (int ifleet=1;ifleet<=Nfleets;ifleet++) {
for (int species=1;species<=Nspecies;species++) {
if (Nqpars >0) {
if (f_map(area,ifleet)!=0 && indicator_fishery_q(area,ifleet,species) == 1) {
dum += 1;
q_map(dum,1) = area;
q_map(dum,2) = species;
q_map(dum,3) = ifleet;
}
}
if (f_map(area,ifleet)==0 && indicator_fishery_q(area,ifleet,species) == 1) f_map(area,ifleet) = species;
}
}
}
cout << "q par map" << endl;
cout << Nqpars << endl;
cout << f_map << endl;
cout << q_map << endl;
AR_parameters.allocate(1,3,"AR_parameters");
rho_AR_Survey = AR_parameters(1);
rho_AR_Recruitment = AR_parameters(2);
rho_AR_Catch = AR_parameters(3);
sim_survey_error.allocate(1,Nareas,1,Nspecies,1,Nyrs);
sim_recruit_error.allocate(1,Nareas,1,Nspecies,1,Nyrs);
sim_catch_error.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs);
sim_extreme_recruit_error.allocate(1,Nareas,1,Nspecies,1,Nyrs);
flagMSE.allocate("flagMSE");
residentTime.allocate(1,Nareas,1,Nspecies,"residentTime");
areaMortality.allocate(1,Nareas,1,Nspecies,"areaMortality");
m1_change_yr.allocate("m1_change_yr");
m1_multiplier.allocate("m1_multiplier");
of_change_yr.allocate("of_change_yr");
of_multiplier.allocate("of_multiplier");
flag_tvar_q.allocate("flag_tvar_q");
Nqpar_vec = 1;
if(flag_tvar_q==1) Nqpar_vec = Nyrs;
eof.allocate("eof");
ad_comm::change_datafile_name(datfilename);
Nsurvey_obs.allocate("Nsurvey_obs");
cout << Nsurvey_obs << endl;
obs_survey_biomass.allocate(1,Nsurvey_obs,1,5,"obs_survey_biomass");
Nsurvey_size_obs.allocate("Nsurvey_size_obs");
int ncol = Nsizebins+5;
obs_survey_size.allocate(1,Nsurvey_size_obs,1,ncol,"obs_survey_size");
Ncatch_obs.allocate("Ncatch_obs");
obs_catch_biomass.allocate(1,Ncatch_obs,1,6,"obs_catch_biomass");
Ncatch_size_obs.allocate("Ncatch_size_obs");
ncol = Nsizebins+6;
obs_catch_size.allocate(1,Ncatch_size_obs,1,ncol,"obs_catch_size");
Ndietprop_obs.allocate("Ndietprop_obs");
ncol = Nspecies+6;
obs_dietprop.allocate(1,Ndietprop_obs,1,ncol,"obs_dietprop");
if (debug == 1)
{
cout<<"Nyrs\n"<<Nyrs<<endl;
cout<<"Nspecies\n"<<Nspecies<<endl;
cout<<"Nsizebins\n"<<Nsizebins<<endl;
cout<<"Nareas\n"<<Nareas<<endl;
cout<<"Nfleets\n"<<Nfleets<<endl;
cout<<"wtconv\n"<<wtconv<<endl;
cout<<"Totsizebins\n"<<Totsizebins<<endl;
cout<<"binwidth\n"<<binwidth<<endl;
cout<<"lenwt_a\n"<<lenwt_a<<endl;
cout<<"lenwt_b\n"<<lenwt_b<<endl;
cout<<"lbinmax\n"<<lbinmax<<endl;
cout<<"lbinmin\n"<<lbinmin<<endl;
cout<<"lbinmidpt\n"<<lbinmidpt<<endl;
cout<<"wtbinmax\n"<<wtbinmax<<endl;
cout<<"wtbinmin\n"<<wtbinmin<<endl;
cout<<"wtatlbinmidpt\n"<<wtatlbinmidpt<<endl;
cout<<"binavgwt\n"<<binavgwt<<endl;
cout<<"Nrecruitment_cov\n"<<Nrecruitment_cov<<endl;
cout<<"Nmaturity_cov\n"<<Nmaturity_cov<<endl;
cout<<"Ngrowth_cov\n"<<Ngrowth_cov<<endl;
cout<<"recruitment_cov\n"<<recruitment_cov<<endl;
cout<<"maturity_cov\n"<<maturity_cov<<endl;
cout<<"growth_cov\n"<<growth_cov<<endl;
cout<<"obs_survey_biomass\n"<<obs_survey_biomass<<endl;
cout<<"obs_survey_size\n"<<obs_survey_size<<endl;
cout<<"obs_catch_biomass\n"<<obs_catch_biomass<<endl;
cout<<"obs_catch_size\n"<<obs_catch_size<<endl;
cout<<"obs_dietprop\n"<<obs_dietprop<<endl;
cout<<"mean_stomwt\n"<<mean_stomwt<<endl;
cout<<"obs_temp\n"<<obs_temp<<endl;
cout<<"recruitment_covwt\n"<<recruitment_covwt<<endl;
cout<<"rectype\n"<<rectype<<endl;
cout<<"stochrec\n"<<stochrec<<endl;
cout<<"rec_alpha\n"<<rec_alpha<<endl;
cout<<"rec_shape\n"<<rec_shape<<endl;
cout<<"rec_beta\n"<<rec_beta<<endl;
cout<<"fecund_d\n"<<fecund_d<<endl;
cout<<"fecund_h\n"<<fecund_h<<endl;
cout<<"fecund_theta\n"<<fecund_theta<<endl;
cout<<"fecundity\n"<<fecundity<<endl;
cout<<"maturity_nu\n"<<maturity_nu<<endl;
cout<<"maturity_omega\n"<<maturity_omega<<endl;
cout<<"maturity_covwt\n"<<maturity_covwt<<endl;
cout<<"growth_psi\n"<<growth_psi<<endl;
cout<<"growth_kappa\n"<<growth_kappa<<endl;
cout<<"growth_covwt\n"<<growth_covwt<<endl;
cout<<"vonB_Linf\n"<<vonB_Linf<<endl;
cout<<"vonB_k\n"<<vonB_k<<endl;
cout<<"growthtype (1 power, 2 power/covariates, 3 vonB, 4 vonB covariates)\n"<<growthtype<<endl;
cout<<"growthprob_phi\n"<<growthprob_phi<<endl;
cout<<"phimax\n"<<phimax<<endl;
cout<<"Nstepsyr\n"<<Nstepsyr<<endl;
cout<<"Tottimesteps\n"<<Tottimesteps<<endl;
cout<<"intake_alpha\n"<<intake_alpha<<endl;
cout<<"intake_beta\n"<<intake_beta<<endl;
cout<<"intake\n"<<intake<<endl;
// cout<<"M1ann\n"<<M1ann<<endl;
// cout<<"M1\n"<<M1<<endl;
cout<<"isprey\n"<<isprey<<endl;
cout<<"Npred\n"<<Npred<<endl;
cout<<"preferred_wtratio\n"<<preferred_wtratio<<endl;
cout<<"sd_sizepref\n"<<sd_sizepref<<endl;
cout<<"wtratio\n"<<wtratio<<endl;
cout<<"sizepref\n"<<sizepref<<endl;
//cout<<"suitability\n"<<suitability<<endl;
cout<<"B0\n"<<B0<<endl;
cout<<"Nguilds\n"<<Nguilds<<endl;
cout<<"guildMembers\n"<<guildMembers<<endl;
cout<<"AssessmentPeriod\n"<<AssessmentPeriod<<endl;
cout<<"eof\n"<<eof<<endl;
}
if(eof != 54321) {cout<<"Stop, data input failed"<<endl<<"eof: "<<eof<<endl; exit(1);}
if (debug == 1) {cout<<"\nManually exiting at end of data section..."<<endl; exit(-1);}
}
void model_parameters::initializationfunction(void)
{
if (global_datafile)
{
delete global_datafile;
global_datafile = NULL;
}
}
model_parameters::model_parameters(int sz,int argc,char * argv[]) :
model_data(argc,argv) , function_minimizer(sz)
{
initializationfunction();
effort_updated.allocate(1,Nareas,1,Nfleets,"effort_updated");
#ifndef NO_AD_INITIALIZE
effort_updated.initialize();
#endif
obs_effortAssess.allocate(1,Nareas,1,Nfleets,1,Nyrs,"obs_effortAssess");
#ifndef NO_AD_INITIALIZE
obs_effortAssess.initialize();
#endif
obs_effortAssess = obs_effort;
ln_yr1N.allocate(1,Nareas,1,Nspecies,1,Nsizebins,yr1Nphase,"ln_yr1N");
yr1N.allocate(1,Nareas,1,Nspecies,1,Nsizebins,"yr1N");
#ifndef NO_AD_INITIALIZE
yr1N.initialize();
#endif
recruitment_alpha.allocate(1,Nareas,1,Nspecies,recphase,"recruitment_alpha");
recruitment_shape.allocate(1,Nareas,1,Nspecies,recphase,"recruitment_shape");
recruitment_beta.allocate(1,Nareas,1,Nspecies,recphase,"recruitment_beta");
propmature.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"propmature");
#ifndef NO_AD_INITIALIZE
propmature.initialize();
#endif
eggprod.allocate(1,Nareas,1,Nspecies,1,Nyrs,"eggprod");
#ifndef NO_AD_INITIALIZE
eggprod.initialize();
#endif
ln_avg_recruitment.allocate(1,Nareas,1,Nspecies,avg_rec_phase,"ln_avg_recruitment");
avg_recruitment.allocate(1,Nareas,1,Nspecies,"avg_recruitment");
#ifndef NO_AD_INITIALIZE
avg_recruitment.initialize();
#endif
recruitment_devs.allocate(1,Nareas,1,Nspecies,2,Nyrs,dev_rec_phase,"recruitment_devs");
recruitment.allocate(1,Nareas,1,Nspecies,2,Nyrs,"recruitment");
#ifndef NO_AD_INITIALIZE
recruitment.initialize();
#endif
ln_recsigma.allocate(1,Nareas,1,Nspecies,recsigmaphase,"ln_recsigma");
recsigma.allocate(1,Nareas,1,Nspecies,"recsigma");
#ifndef NO_AD_INITIALIZE
recsigma.initialize();
#endif
rec_procError.allocate(1,Nareas,1,Nspecies,1,Nyrs,"rec_procError");
#ifndef NO_AD_INITIALIZE
rec_procError.initialize();
#endif
avg_F.allocate(1,Nareas,1,Nfleets,avg_F_phase,"avg_F");
F_devs.allocate(1,Nareas,1,Nfleets,1,Nyrs,dev_F_phase,"F_devs");
Fyr.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs,"Fyr");
#ifndef NO_AD_INITIALIZE
Fyr.initialize();
#endif
suitpreybio.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"suitpreybio");
#ifndef NO_AD_INITIALIZE
suitpreybio.initialize();
#endif
cout << "Nprey " << Nprey << endl;
logit_vuln.allocate(1,Npreypar,-10,10,vuln_phase,"logit_vuln");
vulnerability.allocate(1,Nareas,1,Nspecies,1,Nspecies,"vulnerability");
#ifndef NO_AD_INITIALIZE
vulnerability.initialize();
#endif
suitability.allocate(1,Nareas,1,Nspecies,1,Totsizebins,1,Nsizebins,"suitability");
#ifndef NO_AD_INITIALIZE
suitability.initialize();
#endif
biomass_prey_avail_no_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,1,Nprey,"biomass_prey_avail_no_size");
#ifndef NO_AD_INITIALIZE
biomass_prey_avail_no_size.initialize();
#endif
N.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"N");
#ifndef NO_AD_INITIALIZE
N.initialize();
#endif
Narea.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"Narea");
#ifndef NO_AD_INITIALIZE
Narea.initialize();
#endif
Nnotarea.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"Nnotarea");
#ifndef NO_AD_INITIALIZE
Nnotarea.initialize();
#endif
B.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"B");
#ifndef NO_AD_INITIALIZE
B.initialize();
#endif
F.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"F");
#ifndef NO_AD_INITIALIZE
F.initialize();
#endif
C.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"C");
#ifndef NO_AD_INITIALIZE
C.initialize();
#endif
Z.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"Z");
#ifndef NO_AD_INITIALIZE
Z.initialize();
#endif
M2.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"M2");
#ifndef NO_AD_INITIALIZE
M2.initialize();
#endif
eatN.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"eatN");
#ifndef NO_AD_INITIALIZE
eatN.initialize();
#endif
discardN.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"discardN");
#ifndef NO_AD_INITIALIZE
discardN.initialize();
#endif
otherDead.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"otherDead");
#ifndef NO_AD_INITIALIZE
otherDead.initialize();
#endif
D.allocate(1,Nareas,1,Nspecies,1,Tottimesteps,1,Nsizebins,"D");
#ifndef NO_AD_INITIALIZE
D.initialize();
#endif
fishsel_pars.allocate(1,2,1,Nfleets,fsphase,"fishsel_pars");
fishsel_c.allocate(1,Nspecies,1,Nfleets,"fishsel_c");
#ifndef NO_AD_INITIALIZE
fishsel_c.initialize();
#endif
fishsel_d.allocate(1,Nspecies,1,Nfleets,"fishsel_d");
#ifndef NO_AD_INITIALIZE
fishsel_d.initialize();
#endif
fishsel.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nsizebins,"fishsel");
#ifndef NO_AD_INITIALIZE
fishsel.initialize();
#endif
Ffl.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins,"Ffl");
#ifndef NO_AD_INITIALIZE
Ffl.initialize();
#endif
Dfl.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins,"Dfl");
#ifndef NO_AD_INITIALIZE
Dfl.initialize();
#endif
Cfl.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Tottimesteps,1,Nsizebins,"Cfl");
#ifndef NO_AD_INITIALIZE
Cfl.initialize();
#endif
ln_fishery_q.allocate(1,Nqpar_vec,1,Nqpars,fqphase,"ln_fishery_q");
fishery_q.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs,"fishery_q");
#ifndef NO_AD_INITIALIZE
fishery_q.initialize();
#endif
mean_guild_fishery_q.allocate(1,Nareas,1,Nguilds,1,Nfleets,"mean_guild_fishery_q");
#ifndef NO_AD_INITIALIZE
mean_guild_fishery_q.initialize();
#endif
ln_survey_q.allocate(1,Nsurveys,1,Nspecies,-30,2,sqphase,"ln_survey_q");
survey_q.allocate(1,Nsurveys,1,Nspecies,"survey_q");
#ifndef NO_AD_INITIALIZE
survey_q.initialize();
#endif
survey_selpars.allocate(1,2,1,Nsurveys,ssphase,"survey_selpars");
survey_sel.allocate(1,Nsurveys,1,Nspecies,1,Nsizebins,"survey_sel");
#ifndef NO_AD_INITIALIZE
survey_sel.initialize();
#endif
avByr.allocate(1,Nareas,1,Nspecies,1,Nyrs,"avByr");
#ifndef NO_AD_INITIALIZE
avByr.initialize();
#endif
SSB.allocate(1,Nareas,1,Nspecies,1,Nyrs,"SSB");
#ifndef NO_AD_INITIALIZE
SSB.initialize();
#endif
eaten_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"eaten_biomass");
#ifndef NO_AD_INITIALIZE
eaten_biomass.initialize();
#endif
discard_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"discard_biomass");
#ifndef NO_AD_INITIALIZE
discard_biomass.initialize();
#endif
otherDead_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"otherDead_biomass");
#ifndef NO_AD_INITIALIZE
otherDead_biomass.initialize();
#endif
total_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"total_biomass");
#ifndef NO_AD_INITIALIZE
total_biomass.initialize();
#endif
eaten_biomass_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"eaten_biomass_size");
#ifndef NO_AD_INITIALIZE
eaten_biomass_size.initialize();
#endif
discard_biomass_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"discard_biomass_size");
#ifndef NO_AD_INITIALIZE
discard_biomass_size.initialize();
#endif
otherDead_biomass_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"otherDead_biomass_size");
#ifndef NO_AD_INITIALIZE
otherDead_biomass_size.initialize();
#endif
total_biomass_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"total_biomass_size");
#ifndef NO_AD_INITIALIZE
total_biomass_size.initialize();
#endif
catch_biomass_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"catch_biomass_size");
#ifndef NO_AD_INITIALIZE
catch_biomass_size.initialize();
#endif
predation_mortality.allocate(1,Nareas,1,Nspecies,1,Nyrs,"predation_mortality");
#ifndef NO_AD_INITIALIZE
predation_mortality.initialize();
#endif
fishing_mortality.allocate(1,Nareas,1,Nspecies,1,Nyrs,"fishing_mortality");
#ifndef NO_AD_INITIALIZE
fishing_mortality.initialize();
#endif
predation_mortality_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"predation_mortality_size");
#ifndef NO_AD_INITIALIZE
predation_mortality_size.initialize();
#endif
fishing_mortality_size.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"fishing_mortality_size");
#ifndef NO_AD_INITIALIZE
fishing_mortality_size.initialize();
#endif
catch_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"catch_biomass");
#ifndef NO_AD_INITIALIZE
catch_biomass.initialize();
#endif
fleet_catch_biomass.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs,"fleet_catch_biomass");
#ifndef NO_AD_INITIALIZE
fleet_catch_biomass.initialize();
#endif
resid_bio.allocate(1,Nareas,1,Nspecies,1,Nyrs,"resid_bio");
#ifndef NO_AD_INITIALIZE
resid_bio.initialize();
#endif
totcatch_fit.allocate(1,Nareas,1,Nspecies,"totcatch_fit");
#ifndef NO_AD_INITIALIZE
totcatch_fit.initialize();
#endif
catchcomp_fit.allocate(1,Nareas,1,Nspecies,"catchcomp_fit");
#ifndef NO_AD_INITIALIZE
catchcomp_fit.initialize();
#endif
totbio_fit.allocate(1,Nareas,1,Nspecies,"totbio_fit");
#ifndef NO_AD_INITIALIZE
totbio_fit.initialize();
#endif
biocomp_fit.allocate(1,Nareas,1,Nspecies,"biocomp_fit");
#ifndef NO_AD_INITIALIZE
biocomp_fit.initialize();
#endif
pred_catch_biomass.allocate(1,Ncatch_obs,"pred_catch_biomass");
#ifndef NO_AD_INITIALIZE
pred_catch_biomass.initialize();
#endif
resid_catch.allocate(1,Ncatch_obs,"resid_catch");
#ifndef NO_AD_INITIALIZE
resid_catch.initialize();
#endif
nll_catch.allocate(1,Ncatch_obs,"nll_catch");
#ifndef NO_AD_INITIALIZE
nll_catch.initialize();
#endif
int Nsize_obs = 0;
for (int i=1;i<=Ncatch_size_obs;i++) {
for (int ilen=1;ilen<=Nsizebins;ilen++)
if (obs_catch_size(i,6+ilen)>=0) Nsize_obs += 1;
}
pred_catch_size.allocate(1,Nsize_obs,"pred_catch_size");
#ifndef NO_AD_INITIALIZE
pred_catch_size.initialize();
#endif
nll_catch_size.allocate(1,Nsize_obs,"nll_catch_size");
#ifndef NO_AD_INITIALIZE
nll_catch_size.initialize();
#endif
pred_survey_index.allocate(1,Nsurvey_obs,"pred_survey_index");
#ifndef NO_AD_INITIALIZE
pred_survey_index.initialize();
#endif
resid_survey.allocate(1,Nsurvey_obs,"resid_survey");
#ifndef NO_AD_INITIALIZE
resid_survey.initialize();
#endif
nll_survey.allocate(1,Nsurvey_obs,"nll_survey");
#ifndef NO_AD_INITIALIZE
nll_survey.initialize();
#endif
Nsize_obs = 0;
for (int i=1;i<=Nsurvey_size_obs;i++) {
for (int ilen=1;ilen<=Nsizebins;ilen++)
if (obs_survey_size(i,5+ilen)>=0) Nsize_obs += 1;
}
pred_survey_size.allocate(1,Nsize_obs,"pred_survey_size");
#ifndef NO_AD_INITIALIZE
pred_survey_size.initialize();
#endif
nll_survey_size.allocate(1,Nsize_obs,"nll_survey_size");
#ifndef NO_AD_INITIALIZE
nll_survey_size.initialize();
#endif
Nsize_obs = 0;
for (int i=1;i<=Ndietprop_obs;i++) {
for (int ilen=1;ilen<=Nspecies;ilen++)
if (obs_dietprop(i,5+ilen)>=0) Nsize_obs += 1;
if (obs_dietprop(i,6+Nspecies)>=0) Nsize_obs += 1;
}
pred_dietprop.allocate(1,Nsize_obs,"pred_dietprop");
#ifndef NO_AD_INITIALIZE
pred_dietprop.initialize();
#endif
nll_dietprop.allocate(1,Nsize_obs,"nll_dietprop");
#ifndef NO_AD_INITIALIZE
nll_dietprop.initialize();
#endif
Nsize_obs = Nspecies*Nareas*Nyrs;
recdev.allocate(1,Nsize_obs,"recdev");
#ifndef NO_AD_INITIALIZE
recdev.initialize();
#endif
nll_recruit.allocate("nll_recruit");
#ifndef NO_AD_INITIALIZE
nll_recruit.initialize();
#endif
index_Simpsons_N.allocate(1,Nareas,1,Nyrs,"index_Simpsons_N");
#ifndef NO_AD_INITIALIZE
index_Simpsons_N.initialize();
#endif
index_Simpsons_Nrecip.allocate(1,Nareas,1,Nyrs,"index_Simpsons_Nrecip");
#ifndef NO_AD_INITIALIZE
index_Simpsons_Nrecip.initialize();
#endif
index_Simpsons_C.allocate(1,Nareas,1,Nyrs,"index_Simpsons_C");
#ifndef NO_AD_INITIALIZE
index_Simpsons_C.initialize();
#endif
index_Simpsons_Crecip.allocate(1,Nareas,1,Nyrs,"index_Simpsons_Crecip");
#ifndef NO_AD_INITIALIZE
index_Simpsons_Crecip.initialize();
#endif
index_LFI_Biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_LFI_Biomass");
#ifndef NO_AD_INITIALIZE
index_LFI_Biomass.initialize();
#endif
index_LFI_Catch.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_LFI_Catch");
#ifndef NO_AD_INITIALIZE
index_LFI_Catch.initialize();
#endif
index_LFI_N.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_LFI_N");
#ifndef NO_AD_INITIALIZE
index_LFI_N.initialize();
#endif
LFI_threshold.allocate(1,Nareas,1,Tottimesteps,"LFI_threshold");
#ifndef NO_AD_INITIALIZE
LFI_threshold.initialize();
#endif
prob_species.allocate(1,Nspecies,"prob_species");
#ifndef NO_AD_INITIALIZE
prob_species.initialize();
#endif
LF_Biomass.allocate("LF_Biomass");
#ifndef NO_AD_INITIALIZE
LF_Biomass.initialize();
#endif
B_total.allocate(1,Nspecies,"B_total");
#ifndef NO_AD_INITIALIZE
B_total.initialize();
#endif
B_largestClass.allocate(1,Nspecies,"B_largestClass");
#ifndef NO_AD_INITIALIZE
B_largestClass.initialize();
#endif
N_tot.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"N_tot");
#ifndef NO_AD_INITIALIZE
N_tot.initialize();
#endif
B_tot.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"B_tot");
#ifndef NO_AD_INITIALIZE
B_tot.initialize();
#endif
C_tot.allocate(1,Nareas,1,Nspecies,1,Nyrs,1,Nsizebins,"C_tot");
#ifndef NO_AD_INITIALIZE
C_tot.initialize();
#endif
Cfl_tot.allocate(1,Nareas,1,Nspecies,1,Nfleets,1,Nyrs,1,Nsizebins,"Cfl_tot");
#ifndef NO_AD_INITIALIZE
Cfl_tot.initialize();
#endif
index_predBio.allocate(1,Nareas,1,Nyrs,"index_predBio");
#ifndef NO_AD_INITIALIZE
index_predBio.initialize();
#endif
index_preyBio.allocate(1,Nareas,1,Nyrs,"index_preyBio");
#ifndef NO_AD_INITIALIZE
index_preyBio.initialize();
#endif
index_predToPreyRatio.allocate(1,Nareas,1,Nyrs,"index_predToPreyRatio");
#ifndef NO_AD_INITIALIZE
index_predToPreyRatio.initialize();
#endif
index_plankToPiscRatio.allocate(1,Nareas,1,Nyrs,"index_plankToPiscRatio");
#ifndef NO_AD_INITIALIZE
index_plankToPiscRatio.initialize();
#endif
index_catch.allocate(1,bandwidth_metric,"index_catch");
#ifndef NO_AD_INITIALIZE
index_catch.initialize();
#endif
index_biomass.allocate(1,bandwidth_metric,"index_biomass");
#ifndef NO_AD_INITIALIZE
index_biomass.initialize();
#endif
index_stdev_catch.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_stdev_catch");
#ifndef NO_AD_INITIALIZE
index_stdev_catch.initialize();
#endif
index_stdev_biomass.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_stdev_biomass");
#ifndef NO_AD_INITIALIZE
index_stdev_biomass.initialize();
#endif
index_ExploitationRate.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_ExploitationRate");
#ifndef NO_AD_INITIALIZE
index_ExploitationRate.initialize();
#endif
index_SystemExploitationRate.allocate(1,Nareas,1,Nyrs,"index_SystemExploitationRate");
#ifndef NO_AD_INITIALIZE
index_SystemExploitationRate.initialize();
#endif
exploitation_update.allocate(1,Nareas,1,Nfleets,1,Nyrs,"exploitation_update");
#ifndef NO_AD_INITIALIZE
exploitation_update.initialize();
#endif
index_status_species.allocate(1,Nareas,1,Nspecies,1,Nyrs,"index_status_species");
#ifndef NO_AD_INITIALIZE
index_status_species.initialize();
#endif
index_status_guild.allocate(1,Nareas,1,Nguilds,1,Nyrs,"index_status_guild");
#ifndef NO_AD_INITIALIZE
index_status_guild.initialize();
#endif
exploitationLevelSpecies.allocate(1,Nareas,1,Nspecies,"exploitationLevelSpecies");
#ifndef NO_AD_INITIALIZE
exploitationLevelSpecies.initialize();
#endif
exploitationLevelGuild.allocate(1,Nareas,1,Nguilds,"exploitationLevelGuild");
#ifndef NO_AD_INITIALIZE
exploitationLevelGuild.initialize();
#endif
newExploitationLevel.allocate(1,Nareas,1,Nfleets,"newExploitationLevel");
#ifndef NO_AD_INITIALIZE
newExploitationLevel.initialize();