diff --git a/R/ghack.R b/R/ghack.R
deleted file mode 100644
index 24f2cb5..0000000
--- a/R/ghack.R
+++ /dev/null
@@ -1,14 +0,0 @@
-remotes::install_github("nmfs-fish-tools/ghactions4r")
-ghactions4r::use_r_cmd_check()
-✔ Setting active project to '/Users/jim/_mymods/afsc-assessments/spmR'
-✔ Saving 'nmfs-fish-tools/ghactions4r/inst/templates/call-r-cmd-check.yml@main' to '.github/workflows/call-r-cmd-check.yml'
-ghactions4r::use_calc_coverage()
-✔ Saving 'nmfs-fish-tools/ghactions4r/inst/templates/call-calc-coverage.yml@main' to '.github/workflows/call-calc-coverage.yml'
-ghactions4r::use_update_roxygen_docs()
-✔ Saving 'nmfs-fish-tools/ghactions4r/inst/templates/call-update-docs.yml@main' to '.github/workflows/call-update-docs.yml'
-✔ Adding '*.rds' to '.github/.gitignore'
-ghactions4r::use_style_r_code()
-✔ Saving 'nmfs-fish-tools/ghactions4r/inst/templates/call-style.yml@main' to '.github/workflows/call-style.yml'
-ghactions4r::use_update_pkgdown()
-✔ Saving 'nmfs-fish-tools/ghactions4r/inst/templates/call-update-pkgdown.yml@main' to '.github/workflows/call-update-pkgdown.yml'
-ghactions4r::use_update_readme()
diff --git a/README.Rmd b/README.Rmd
index 545816c..0f55037 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -25,5 +25,112 @@ These are the steps to run the projection code:\
2. Within spm.dat specify the location of the assessment input file relative to the folder with spm.exe\
3. From the command line pointed to the folder with these inputs, type "spm"\
+
+
+```{r setup, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>",
+ fig.path = "man/figures/README-",
+ out.width = "100%"
+)
+```
+
+# East Bering Sea pollock
+
+The R package `spmR` was developed for doing
+stock projections for groundfish at the AFSC.
+The model was coded using the Autodif (`AD`) Model
+Builder (`ADMB`) software.
+
+## Cloning the repository (optional)
+
+The R package `spmR` lives on a public GitHub repository. The repository can be
+cloned to your computer from the command line or using a user interface. From
+the command line using Linux the repository can be cloned using:
+
+``` r
+git clone https://github.com/afsc-assessments/spmR
+```
+
+## Installation
+
+There are several options for installing the `spmR` R package.
+
+### Option 1
+
+The `spmR` package can be installed from within R using:
+
+``` r
+devtools::install_github(repo = "afsc-assessments/spmR", dependencies = TRUE,
+ build_vignettes = TRUE, auth_token = "your_PAT")
+```
+
+### Option 2
+
+The GitHub repository can be cloned to your computer and the package installed
+from the command line. From Linux this would involve:
+
+``` r
+git clone https://github.com/afsc-assessments/spmR
+R CMD INSTALL spmR
+```
+
+### Option 3
+
+This time from within R using:
+
+``` r
+devtools::install("spmR")
+```
+
+## Help
+
+Help for all `spmR` functions and data sets can be found on the R help pages
+associated with each function and data set. Help for a specific function can be
+viewed using `?function_name`, for example:
+
+``` r
+?run_model
+?tab_fit
+?plot_sel
+```
+
+Alternatively, to see a list of all available functions and data sets use:
+
+``` r
+help(package = "spmR")
+```
+
+## Examples
+
+The package vignettes are a great place to see what `spmR` can do. You can view
+the package vignettes from within R using:
+
+``` r
+browseVignettes(package = "spmR")
+vignette(topic = "spmR", package = "spmR")
+```
+
+## Website
+
+All of the vignettes and the help pages for each function are bundled together
+and published on the website https://afsc-assessments.github.io/spmR/.
+
+## Developers
+
+Developers will want to do things slightly differently. See the
+`Model development` vignette.
+
+# Acronymns
+
+NOAA: National Oceanic and Atmospheric Administration
+NMFS: National Marine Fisheries Service
+AFSC: Alaska Fisheries Science Center
+REFM: Resource and Ecology and Fisheries Management
+
+# Legal disclaimer
+This repository is a software product and is not official communication of the National Oceanic and Atmospheric Administration (NOAA), or the United States Department of Commerce (DOC). All NOAA GitHub project code is provided on an ‘as is’ basis and the user assumes responsibility for its use. Any claims against the DOC or DOC bureaus stemming from the use of this GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation, or favoring by the DOC. The DOC seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by the DOC or the United States Government.
+
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index fc532fc..e793915 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -4,5 +4,5 @@ pkgdown_sha: ~
articles:
00-spm-example: 00-spm-example.html
01-Background: 01-Background.html
-last_built: 2024-02-28T22:42Z
+last_built: 2024-02-28T22:47Z
diff --git a/src/spm.cpp b/src/spm.cpp
deleted file mode 100644
index 43058d8..0000000
--- a/src/spm.cpp
+++ /dev/null
@@ -1,2909 +0,0 @@
-#ifdef DEBUG
- #ifndef __SUNPRO_C
- #include
- #include
- #endif
-#endif
- #include
- adstring xspname;
- adstring_array targsppname(1,20);
- adstring_array spp_file_name(1,20);
- adstring_array gearname(1,8);
- adstring_array spname(1,90);
- adstring_array areaname(1,8);
- adstring run_name;
- ofstream write_log("Input_Log.rep");
- #undef write_log
- #define write_log(object) write_log << #object "\n" << object << endl;
- // A routine to get transpose, sort and return a matrix ----
- dmatrix TranSort (const dmatrix m1)
- {
- RETURN_ARRAYS_INCREMENT();
- dmatrix vtmp=trans(m1);
- int npro=m1.colmax();
- int nsim=m1.rowmax();
- for (int i=1;i<=npro;i++)
- vtmp(i) = sort(vtmp(i),nsim);
- RETURN_ARRAYS_DECREMENT();
- return(vtmp);
- }
- // #include
-#ifdef DEBUG
- #include
-#endif
-#include
-#ifdef USE_ADMB_CONTRIBS
-#include
-
-#endif
- extern "C" {
- void ad_boundf(int i);
- }
-#include
-
-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;
- }
- pad_means_out = new ofstream("means.out");
- pad_alts_proj = new ofstream("alt_proj.out");
- pad_percent_out = new ofstream("percentiles.out");
- pad_percent_db = new ofstream("percentdb.out");
- pad_detail_out = new ofstream("spm_detail.csv");
- pad_prof_F = new ofstream("F_profile.out");;
- pad_elasticity = new ofstream("elasticity.csv");;
- condition_SR = 0;//
- rnseed = 123;
- *(ad_comm::global_datafile) >> run_name; // Read in the name of this run
- Tier.allocate("Tier");
- rec_vector.allocate(1,300);
- wtd_rec.allocate(1,25);
- wtd_div.allocate(1,25);
- nalts.allocate("nalts");
- alt_list.allocate(1,nalts,"alt_list");
- TAC_ABC.allocate("TAC_ABC");
- SrType.allocate("SrType");
- Rec_Gen.allocate("Rec_Gen");
- Fmsy_F35.allocate("Fmsy_F35");
- Rec_Cond.allocate("Rec_Cond");
- Write_Big.allocate("Write_Big");
- npro.allocate("npro");
- nsims.allocate("nsims");
- styr.allocate("styr");
- cout<< "First year:\t"<> spp_file_name(i);
- write_log(nyrs_catch_in);
- write_log(nspp);
- write_log(OY_min);
- write_log(OY_max);
- write_log(spp_file_name);
- cout <<"OYMax "<> bzero_in;
- *(ad_comm::global_datafile) >> phizero_in;
- *(ad_comm::global_datafile) >> alpha_in;
- *(ad_comm::global_datafile) >> sigmar_in;
- *(ad_comm::global_datafile) >> rho_in;
- // rho_in=0.82;
- }
- // Open up tac-model parameters
- ad_comm::change_datafile_name("tacpar.dat");
- nntmp.allocate("nntmp");
- nnodes.allocate("nnodes");
- maxabc.allocate(1,ntacspp,"maxabc");
- theta.allocate(0,nnodes,1,ntacspp,"theta");
- cout<<"read tacpar"<> spname(i); // 1
- cout<> SSL_spp(i); // 2
- *(ad_comm::global_datafile) >> Const_Buffer(i); // 3
- *(ad_comm::global_datafile) >> ngear(i); // 4
- *(ad_comm::global_datafile) >> nsexes(i); // 6
- *(ad_comm::global_datafile) >> avg_5yrF(i); // 7
- *(ad_comm::global_datafile) >> FABC_Adj(i); // 8
- *(ad_comm::global_datafile) >> SPR_abc(i); // 9
- *(ad_comm::global_datafile) >> SPR_ofl(i); // 10
- *(ad_comm::global_datafile) >> spawnmo(i); // 11
- *(ad_comm::global_datafile) >> nages(i); // 12
- cout<<"nages: "<> Fratiotmp(i,j); // 13
- write_log( Fratiotmp(i));
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> M_Ftmp(i,k); // 14
- if (nsexes(i)==2)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> M_Mtmp(i,k); // 15
- write_log( M_Ftmp(i));
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> pmaturetmp_F(i,k); // 16
- write_log( pmaturetmp_F(i));
- if (nsexes(i)==2)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> pmaturetmp_M(i,k); // 15
- write_log( pmaturetmp_M(i));
- cout << "Mature: "<< pmaturetmp_F(i)(1,nages(i)) <> wt_Ftmp(i,k); // 17
- write_log( wt_Ftmp(i));
- for (int j=1;j<=ngear(i);j++)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> wt_gear_Ftmp(i,j,k); // 18
- write_log( wt_gear_Ftmp(i));
- if (nsexes(i)==2)
- for (int j=1;j<=ngear(i);j++)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> wt_gear_Mtmp(i,j,k);// 19
- write_log( wt_gear_Mtmp(i));
-
- for (int j=1;j<=ngear(i);j++)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> sel_Ftmp(i,j,k); // 20
- write_log( sel_Ftmp(i));
- if (nsexes(i)==2)
- for (int j=1;j<=ngear(i);j++)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> sel_Mtmp(i,j,k); // 21
- write_log( sel_Mtmp(i));
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> n0_Ftmp(i,k); // 22
- write_log( n0_Ftmp(i));
- if (nsexes(i)==2)
- for (int k=1;k<=nages(i);k++)
- *(ad_comm::global_datafile) >> n0_Mtmp(i,k); // 23
- write_log( n0_Mtmp(i));
- cout<<"N: "<> nrec(i); // 24
- cout<<"nrec: "<> Rtmp(i,j); // 25
- cout<<"Rec: "<> SSBtmp(i,j); // 26
- cout<<"SSB: "<> Rsim(ispp,i,j);
- Rsim(ispp,i,j) *= exp(rnorms(i,j)*.375); // about 15% CV to get historical mean
- }
- if (nsims<=5) Rsim(ispp,i,j) = AMeanRec(ispp); // XXX constant recruitment
- }
- }
- envin.close();
- AMeanRec(ispp) *= .5; // Goes to females only
- cout <<"Mean recruits "<< AMeanRec(ispp) < 0 )
- F_begin_yr(k,ispp) = SolveF2(n0_F(ispp), n0_M(ispp), Obs_Catch(k,ispp),ispp); // F_yr_one(ispp) = SolveF2(n0_F(ispp), n0_M(ispp), yr_one_catch(ispp),ispp);
- else
- F_begin_yr(ispp) = 0; // F_yr_one(ispp) = 0; // cout< 1) // Debugging if LP to be done or not
- {
- int on=0;
- if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-nolp"))>-1)
- dolp=0;
- else
- dolp=1;
- }
-}
-
-void model_parameters::preliminary_calculations(void)
-{
-
-#if defined(USE_ADPVM)
-
- admaster_slave_variable_interface(*this);
-
-#endif
- double tmp1;
- write_alts_hdr();
- get_SB100();
- cout<<"SSB, Biomass at unfished: "<GRAD_STACK1->total() << " out of " << gradient_structure::get_GRADSTACK_BUFFER_SIZE() << std::endl;;
- std::cout << "DEBUG: Total dvariable address used is " << gradient_structure::get()->GRAD_LIST->total_addresses() << " out of " << gradient_structure::get_MAX_DLINKS() << std::endl;;
- std::cout << "DEBUG: Total dvariable address used is " << gradient_structure::get()->ARR_LIST1->get_max_last_offset() << " out of " << gradient_structure::get_ARRAY_MEMBLOCK_SIZE() << std::endl;;
-#endif
-}
-
-void model_parameters::Run_Sim(void)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- detail_out<<"Stock,Alternative,Sim,Yr,SSB,Rec,Tot_biom,SPR_Implied,F,Ntot,Catch,ABC,OFL,AvgAge,AvgAgeTot,SexRatio,B100,B40,B35"<1)
- nyrs_catch = nyrs_catch_in;
- //else
- // nyrs_catch = 1;// NOTA BUENO: this is changed under the new EIS Alternatives (May 06)
- Do_Sims();
- // if (alt==2) write_alts();
- write_alts();
- }
-}
-
-void model_parameters::compute_obj_fun(void)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- dvariable tmp1;
- dvariable tmp2;
- tmp1.initialize();
- for (int ispp=1;ispp<=nspp;ispp++)
- {
- Get_Bzero(ispp);
- // write_srec();exit(1);
- if(Fmsy_F35>0)
- {
- get_msy(ispp);
- switch (current_phase())
- {
- case 1 : tmp1 = 1.e1*square(log(Fmsy(ispp))-log(F35(ispp))); break;
- case 2 : tmp1 = 1.e2*square(log(Fmsy(ispp))-log(F35(ispp))); break;
- case 3 : tmp1 = 1.e2*square(log(Fmsy(ispp))-log(F35(ispp))); break;
- case 4 : tmp1 = 1.e3*square(log(Fmsy(ispp))-log(F35(ispp))); break;
- default: tmp1 = 1.e3*square(log(Fmsy(ispp))-log(F35(ispp))); break;
- }
- if(Fmsy_F35==2)
- switch (current_phase())
- {
- case 1 : tmp1 += 1.e1*square(log(Bmsy(ispp))-log(0.35 * SB100(ispp))); break;
- case 2 : tmp1 += 1.e2*square(log(Bmsy(ispp))-log(0.35 * SB100(ispp))); break;
- case 3 : tmp1 += 1.e2*square(log(Bmsy(ispp))-log(0.35 * SB100(ispp))); break;
- case 4 : tmp1 += 1.e3*square(log(Bmsy(ispp))-log(0.35 * SB100(ispp))); break;
- default : tmp1+= 1.e3*square(log(Bmsy(ispp))-log(0.35 * SB100(ispp))); break;
- }
- obj_fun += tmp1;
- }
- if (Rec_Cond>0.)
- {
- // More conditioning here--make mean recruitment consistent with half and double
- // recruitment at avg spawning biomass...
- double vartmp = 2.*Rec_Cond*Rec_Cond;
- /*
- double ssb1 = AMeanSSB(ispp) * 0.5;
- double ssb2 = AMeanSSB(ispp) ;
- double ssb3 = AMeanSSB(ispp) * 2.0;
- // double ssb4 = value(Bzero(ispp)) ;
- tmp2.initialize();
- tmp2 += square(log(AMeanRec(ispp)) - log(SRecruit( ssb1, ispp)))/ vartmp;
- tmp2 += square(log(AMeanRec(ispp)) - log(SRecruit( ssb2, ispp)))/ vartmp;
- tmp2 += square(log(AMeanRec(ispp)) - log(SRecruit( ssb3, ispp)))/ vartmp;
- // tmp2 += 24.* square(log(AMeanRec(ispp)) - log(SRecruit( ssb4, ispp)));
- // tmp2 += 24.* square(log(AMeanSSB(ispp)) - log( ssb4 ));
- */
- tmp2 = square(log(Bzero(ispp)) - log(SB100(ispp)))/ vartmp;
- obj_fun += tmp2;
- // cout << "SSB "<OY_max)
- Actual_Catch = TAC/sum(TAC)*OY_max;
- else
- Actual_Catch = TAC;
- }
- /* ////////////////////////////////////////////////////////////////////////////// //int use_max = 1; // Need to move this into the setup file... double max_catch=1500.;// EBS POllock special case (CHANGE THIS) //if (use_max==1) for (int ispp=1;ispp<=nspp;ispp++) Actual_Catch(ispp) = min(TAC(ispp),max_catch); // cout<<"AC: "<3)
- {
- Alt4_Fcalc = 1;
- double diff;
- double ssl_sum=0.;
- diff = OY_min-sumabc;
- // if so, sum up SSL ABCs
- ssl_sum = SSL_spp*ABC;
- for (int ispp=1;ispp<=nspp;ispp++)
- {
- // then apportion them to difference between current ABC and target (OY_min) difference
- if (SSL_spp(ispp))
- {
- TAC(ispp) = ABC(ispp) + diff * ABC(ispp)/ssl_sum;
- // Special for BSAI Pcod to subtract off 3%...and get the totals to match up
- // if (ispp==2) TAC(ispp) /= 0.97; For EIS work
- }
- else
- {
- TAC(ispp) = ABC(ispp);
- }
- }
- // cout << ipro<<" "<0.01) ftmp = SolveF2(N_F(ispp),N_M(ispp),TAC(ispp),ispp);
- // cout <= 0.2 *SBzero(ispp) & SBtmp < SBKink(ispp) ) // NOTE Same as Am 56 here (until 20% bzero reached)
- Ftmp = (Fabc(ispp)*(1/(1-alpha ))*(SBtmp/SBKink(ispp) - alpha ));
- if (SBtmp > SBKink(ispp) )
- Ftmp = (Fabc(ispp));
- SBtmp = N_females * elem_prod( wt_mature_F(ispp), mfexp( -yrfrac(ispp)*(M_F(ispp) + Ftmp*F_age )));
- }
- return(Ftmp);
-}
-
-double model_parameters::Get_F_Am56(const dvector& F_age, const dvector& N_females, const int ispp )
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- double Ftmp; // cout<< spname(ispp)<< endl;
- {
- for (ii=1;ii<=3;ii++) // Iterate to get month of spawning correct
- {
- if (SBtmp < alpha*SBKink(ispp))
- Ftmp = 0.;
- if (SBtmp >= alpha*SBKink(ispp) & SBtmp < SBKink(ispp) )
- Ftmp = (Fabc(ispp)*(1/(1-alpha))*(SBtmp/SBKink(ispp) - alpha));
- if (SBtmp > SBKink(ispp) )
- Ftmp = (Fabc(ispp));
- SBtmp = N_females * elem_prod( wt_mature_F(ispp), mfexp( -yrfrac(ispp)*(M_F(ispp) + Ftmp*F_age )));
- }
- }
- return(Ftmp);
-}
-
-double model_parameters::Get_Fofl_t2(const dvector& F_age, const dvector& N_females, const int ispp )
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- double Ftmp; // cout<< spname(ispp)<< endl;
- {
- for (ii=1;ii<=3;ii++) // Iterate to get month of spawning correct
- {
- if (SBtmp < alpha*SBKink(ispp))
- Ftmp = 0.;
- if (SBtmp >= alpha*SBKink(ispp) & SBtmp < SBKink(ispp) )
- Ftmp = (Fofl(ispp)*(1/(1-alpha))*(SBtmp/SBKink(ispp) - alpha));
- if (SBtmp > SBKink(ispp) )
- Ftmp = (Fofl(ispp));
- SBtmp = N_females * elem_prod( wt_mature_F(ispp), mfexp( -yrfrac(ispp)*(M_F(ispp) + Ftmp*F_age )));
- }
- }
- return(Ftmp);
-}
-
-double model_parameters::Get_Fofl_t(const dvector& F_age, const dvector& N_females, const int ispp )
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- double Ftmp; // cout<< spname(ispp)<< endl;
- {
- for (ii=1;ii<=3;ii++) // Iterate to get month of spawning correct
- {
- if (SBtmp < alpha*SBKink(ispp))
- Ftmp = 0.;
- if (SBtmp >= alpha*SBKink(ispp) & SBtmp < SBKink(ispp) )
- Ftmp = (Fofl(ispp)*(1/(1-alpha))*(SBtmp/SBKink(ispp) - alpha));
- if (SBtmp > SBKink(ispp) )
- Ftmp = (Fofl(ispp));
- SBtmp = N_females * elem_prod( wt_mature_F(ispp), mfexp( -yrfrac(ispp)*(M_F(ispp) + Ftmp*F_age )));
- }
- }
- return(Ftmp);
-}
-
-double model_parameters::Get_F_t(const dvector& F_age, const dvector& N_females, const int ispp )
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- double Ftmp; // cout<< spname(ispp)<< endl;
- if (SSL_spp(ispp))
- {
- Ftmp = Get_F_SSL_prey(F_age, N_females, ispp);
- }
- else
- {
- Ftmp = Get_F_Am56(F_age, N_females, ispp);
- }
- return(Ftmp);
-}
-
-void model_parameters::Project_Pops(const int& isim, const int& i)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- double ctmp;
- if ( i == npro && isim%int(nsims/4)==0) cout << "Year "< 0)
- {
- if (i <= nyrs_catch || TAC_ABC==0) // Use TAC setting algorithm for alt 2 only, for all others, set TAC==ABC
- {
- Ftmp = SolveF2(N_F(ispp),N_M(ispp),Actual_Catch(ispp),ispp);
- }
- else
- {
- if (alt==7 && i<=3)
- Ftmp = Get_F(1,ispp); // Set to the F rather than solving every time...
- else
- if (alt==77 && i<=2)
- Ftmp = Get_F(1,ispp); // Set to the F rather than solving every time...
- else
- {
- // if (alt==2 && sum(TAC)>OY_max)
- if ((alt==2 ||alt==98||alt==97) && sum(TAC)>OY_max)
- {
- Ftmp = SolveF2(N_F(ispp),N_M(ispp),OY_max*TAC(ispp)/sum(TAC),ispp);
- // cout<<"HERE "<< Ftmp<<" "< 0.)
- {
- for (m=1;m<=ngear(ispp);m++)
- {
- Ftottmp_F = Ftmp*Frat(ispp,m)*sel_F(ispp,m);
- Ftottmp_spr += Ftottmp_F ;
- Ftottmp_M = Ftmp*Frat(ispp,m)*sel_M(ispp,m);
- ctmp += (wt_gear_F(ispp,m) * elem_prod(elem_div(Ftottmp_F, Z_F(ispp)),elem_prod(1.-S_F(ispp),N_F(ispp)))); // Catch equation (vectors)
- ctmp += (wt_gear_M(ispp,m) * elem_prod(elem_div(Ftottmp_M, Z_M(ispp)),elem_prod(1.-S_M(ispp),N_M(ispp)))); // Catch equation (vectors)
- }
- SPRsim(ispp,isim,i) = Implied_SPR(Ftottmp_spr,ispp);
- // cout <NUL ");
- ifstream tac("tac.dat");
- tac>>TAC;
- tac.close(); /* */
- for (int ispp=1;ispp<=nspp;ispp++)
- Actual_Catch(ispp) = min(TAC(ispp),ABC(ispp));
- }
-}
-
-void model_parameters::Avg_Age(void)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- Avg_Age_End.initialize();
- Avg_Age_Mat.initialize();
- for (int ispp=1;ispp<=nspp;ispp++)
- {
- // if(!isit_const(ispp) )
- {
- dvector age_seq(1,nages(ispp));
- age_seq.initialize();
- age_seq.fill_seqadd(1,1);
- dvector ntmp(1,nages(ispp));
- ntmp = N_F(ispp);
- Avg_Age_End(ispp) += age_seq * ntmp /sum(ntmp);
- Avg_Age_sum(ispp) += Avg_Age_End(ispp) ;
- ntmp = elem_prod(ntmp,pmature_F(ispp)) ;
- Avg_Age_Mat(ispp) += elem_prod(ntmp,pmature_F(ispp)) * age_seq/sum(ntmp);
- // cout< 1e-6)
- {
- iter++;
- ftmp += (TACin-cc) / btmp;
- Ftottmp_F.initialize();
- Ftottmp_M.initialize();
- for (m=1;m<=ngear(ispp);m++)
- {
- Ftottmp_F += ftmp*Fratsel_F(m);
- Ftottmp_M += ftmp*Fratsel_M(m);
- }
- Z_F = Ftottmp_F + M_F(ispp);
- Z_M = Ftottmp_M + M_M(ispp);
- S_F = mfexp( -Z_F );
- S_M = mfexp( -Z_M );
- cc = 0.0;
- for (m=1;m<=ngear(ispp);m++)
- {
- cc += (wt_gear_F(ispp,m) * elem_prod(elem_div(ftmp*Fratsel_F(m), Z_F),elem_prod(1.-S_F,N_F))); // Catch equation (vectors)
- cc += (wt_gear_M(ispp,m) * elem_prod(elem_div(ftmp*Fratsel_M(m), Z_M),elem_prod(1.-S_M,N_M))); // Catch equation (vectors)
- }
- dd = cc / TACin - 1.;
- //cout << ispp<<" "<< ftmp << " "<< cc << " "<100) {cerr<<"Bombed on catch solver--check scales for "<nages(ispp))
- {
- Tg += double(ii) * wt_mature_F(ispp,nages(ispp)) * ntmp;
- tmp += wt_mature_F(ispp,nages(ispp)) * ntmp;
- ntmp *= exp(-M_F(ispp,nages(ispp)));
- }
- else
- {
- Tg += double(ii) * wt_mature_F(ispp,ii) * ntmp;
- tmp += wt_mature_F(ispp,ii) * ntmp;
- ntmp *= exp(-M_F(ispp,ii));
- }
- }
- // Tg /= value(phizero(ispp));
- Tg /= tmp;
- report << Tg<< " ";
- }
- report << endl;
- report << "Options SR_Type Project_Recr_Assmption SR_Condition"<2)
- write_sim("Alternative ",ispp);
- }
- write_by_time();
- // Writing routines here ....
-}
-
-void model_parameters::write_by_time(void)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- write_sim("Catch", Csim,Cabc); // Total Catch
- cout< 1e-6)
- means_out << mean_value <<" ";
- else
- means_out << " NA ";
- }
- means_out << endl;
- }
- means_out << endl;
-}
-
-void model_parameters::write_TACs(const adstring& Title)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- // This one prints out species over time (means only), but without headings
- means_out <<"Alternative "< 1e-6)
- means_out << mean_value <<" ";
- else
- means_out << " NA ";
- }
- means_out << endl;
- }
- means_out << endl;
-}
-
-void model_parameters::write_sim(const adstring& Title, d3_array& Outtmp)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- // This one prints out species over time (means only), but without headings
- d3_array mtmp(1,nspp,1,npro,1,nsims);
- for (int ispp=1;ispp<=nspp;ispp++) for (int i=1;i<=npro;i++) for (int k=1;k<=nsims;k++)
- mtmp(ispp,i,k)=Outtmp(ispp,k,i);
- means_out <<"Alternative "< 1e-6)
- means_out << mean_value <<" ";
- else
- means_out << " NA ";
- }
- means_out << endl;
- }
- means_out << endl;
-}
-
-void model_parameters::write_sim(const adstring& Title,const d3_array& Outtmp,const dvar_vector& bb)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- // This one prints out species over time (means only)
- d3_array mtmp(1,nspp,1,npro,1,nsims);
- for (int ispp=1;ispp<=nspp;ispp++) for (int i=1;i<=npro;i++) for (int k=1;k<=nsims;k++)
- mtmp(ispp,i,k)=Outtmp(ispp,k,i);
- means_out <<"Alternative "<1e-6)
- means_out << mean_value <<" ";
- else
- means_out << " NA ";
- }
- means_out << endl;
- }
- means_out << endl;
-}
-
-void model_parameters::write_sim(const adstring& Title,const int& ispp)
-{
- ofstream& means_out= *pad_means_out;
- ofstream& alts_proj= *pad_alts_proj;
- ofstream& percent_out= *pad_percent_out;
- ofstream& percent_db= *pad_percent_db;
- ofstream& detail_out= *pad_detail_out;
- ofstream& prof_F= *pad_prof_F;
- ofstream& elasticity= *pad_elasticity;
- // For each species separately
- percent_out <<"Alternative "<5||F1<0.01))
- // {
- // ii=5;
- // F1=M(ispp,nages(ispp)); // When things bomb (F <0 or F really big then just set it to F35...)
- // }
- // else
- {
- F2 = F1 + df*.5;
- F3 = F2 - df; //F1 = double(ii)/100;
- yld1 = yield(F1,Stmp,Rtmp,ispp); //cout <(std::chrono::high_resolution_clock::now() - start).count() << " microseconds." << endl;
- #ifndef __SUNPRO_C
-bool failedtest = false;
-if (std::fetestexcept(FE_DIVBYZERO))
- { cerr << "Error: Detected division by zero." << endl; failedtest = true; }
-if (std::fetestexcept(FE_INVALID))
- { cerr << "Error: Detected invalid argument." << endl; failedtest = true; }
-if (std::fetestexcept(FE_OVERFLOW))
- { cerr << "Error: Detected overflow." << endl; failedtest = true; }
-if (std::fetestexcept(FE_UNDERFLOW))
- { cerr << "Error: Detected underflow." << endl; }
-if (failedtest) { std::abort(); }
- #endif
-#endif
- return 0;
-}
-
-extern "C" {
- void ad_boundf(int i)
- {
- /* so we can stop here */
- exit(i);
- }
-}
diff --git a/src/spm.htp b/src/spm.htp
deleted file mode 100644
index d975a92..0000000
--- a/src/spm.htp
+++ /dev/null
@@ -1,326 +0,0 @@
-#if !defined(_spm_)
-# define _spm_
-
-class model_data : public ad_comm{
- ofstream * pad_means_out;
- ofstream * pad_alts_proj;
- ofstream * pad_percent_out;
- ofstream * pad_percent_db;
- ofstream * pad_detail_out;
- ofstream * pad_prof_F;
- ofstream * pad_elasticity;
- int condition_SR;
- int ipro;
- int isim;
- double kink_adj;
- int rnseed;
- data_int Tier;
- int alt;
- dvector rec_vector;
- dvector wtd_rec;
- dvector wtd_div;
- data_int nalts;
- data_ivector alt_list;
- data_int TAC_ABC;
- data_int SrType;
- data_int Rec_Gen;
- data_int Fmsy_F35;
- data_number Rec_Cond;
- data_int Write_Big;
- data_int npro;
- data_int nsims;
- data_int styr;
- double bzero_in;
- double phizero_in;
- double alpha_in;
- double sigmar_in;
- double rho_in;
- dmatrix rnorms;
- dmatrix unifs;
- dvector sst;
- int nyrs_catch;
- data_int nyrs_catch_in;
- data_int nspp;
- data_number OY_min;
- data_number OY_max;
- data_vector ABC_Multiplier;
- data_vector N_scalar;
- data_vector Alt4_SPR;
- dvector Alt4_Fabc;
- int Alt4_Fcalc;
- dvector Alt3b_obj_fun;
- data_int ntacspp;
- data_ivector tac_ind;
- dvector model_tacs;
- data_matrix Obs_Catch;
- data_int nntmp;
- data_int nnodes;
- data_vector maxabc;
- data_matrix theta;
- dvector agg_abc;
- dvector agg_cat;
- dvector agg_tac;
- int i;
- int k;
- int dolp;
- ivector SSL_spp;
- ivector Const_Buffer;
- double srprior_a;
- double srprior_b;
- ivector ngear;
- ivector isit_const;
- dvector FABC_Adj;
- dvector spawnmo;
- ivector nages;
- dmatrix Fratiotmp;
- dmatrix M_Ftmp;
- dmatrix M_Mtmp;
- dmatrix pmaturetmp_F;
- dmatrix pmaturetmp_M;
- dmatrix wt_Ftmp;
- d3_array wt_gear_Ftmp;
- d3_array wt_gear_Mtmp;
- d3_array sel_Ftmp;
- d3_array sel_Mtmp;
- dmatrix n0_Ftmp;
- dmatrix n0_Mtmp;
- dmatrix Rtmp;
- dmatrix SSBtmp;
- ivector nrec;
- dvector Expl_Biom;
- int ntargspp;
- dvector reserved;
- ivector nsexes;
- dvector avg_5yrF;
- dvector SPR_abc;
- dvector SPR_ofl;
- dvector targ_SPR;
- dmatrix M_F;
- dmatrix M_M;
- dmatrix pmature_F;
- dmatrix pmature_M;
- dmatrix wt_F;
- dmatrix wt_M;
- dmatrix Frat;
- d3_array wt_gear_F;
- d3_array wt_gear_M;
- d3_array sel_F;
- d3_array sel_M;
- dmatrix n0_F;
- dmatrix n0_M;
- dmatrix R;
- dmatrix SSB;
- dmatrix wt_mature_F;
- dmatrix wt_mature_M;
- dvector yrfrac;
- dvector Actual_Catch;
- d3_array Rsim;
- d3_array Fsim;
- d3_array Bsim;
- d3_array Nsim;
- d3_array SRsim;
- d3_array SBsim;
- d3_array SPRsim;
- d3_array Csim;
- dmatrix TACs_by_yr;
- dmatrix ABCs_by_yr;
- dmatrix OFLs_by_yr;
- dmatrix FABCs_by_yr;
- dmatrix FOFLs_by_yr;
- double gi_beta;
- double gamma;
- dvector cvrec;
- double delta;
- dvector TAC;
- dvector ABC;
- dvector OFL;
- dvector AMeanSSB;
- dvector AMeanRec;
- dvector AMaxSSB;
- dvector HMeanRec;
- dvector Bcurrent;
- double alpha;
- int ii;
- int m;
- int j;
- double alphaCI;
- int UCI;
- int LCI;
- dmatrix N_F;
- dmatrix N_M;
- dmatrix Nnext_F;
- dmatrix Nnext_M;
- double chi_prev;
- double chi;
- dmatrix Z_F;
- dmatrix Z_M;
- dmatrix S_F;
- dmatrix S_M;
- dvector Cabc;
- dvector Cofl;
- dvector F35;
- dvector Ftarg;
- double Btmp;
- double SBtmp;
- d3_array C_F;
- d3_array C_M;
- dvector F_yr_one;
- dmatrix F_begin_yr;
- dvector Fabc;
- dvector F40;
- dvector Fofl;
- dmatrix Ftotabc;
- dmatrix Ftot40;
- dmatrix Ftotofl;
- dmatrix N;
- dmatrix NsprF0;
- dmatrix NsprM0;
- dmatrix NsprFabc;
- dmatrix NsprMabc;
- dmatrix NsprF40;
- dmatrix NsprM40;
- dmatrix NsprFofl;
- dmatrix NsprMofl;
- dvector SB100;
- dvector SBzero;
- dvector SBFabc;
- dvector SBF40;
- dvector SBKink;
- dvector SBFofl;
- dvector Avg_Age_Mabc;
- dvector Avg_Age_M0;
- dvector Avg_Age_Fabc;
- dvector Avg_Age_F0;
- dvector Avg_Age_End;
- dvector Avg_Age_Mat;
- dvector Avg_Age_sum;
- dvector BFabc;
- dvector BF40;
- dvector BFofl;
- dvector B100;
- double R_guess;
- double phase_sr;
- ~model_data();
- model_data(int argc,char * argv[]);
- friend class model_parameters;
-};
-
-class model_parameters : public model_data ,
- public function_minimizer
-{
-public:
- ~model_parameters();
- void preliminary_calculations(void);
- void set_runtime(void);
- static int mc_phase(void)
- {
- return initial_params::mc_phase;
- }
- static int mceval_phase(void)
- {
- return initial_params::mceval_phase;
- }
- static int hessian_phase(void)
- {
- return initial_params::in_hessian_phase;
- }
- static int sd_phase(void)
- {
- return initial_params::sd_phase;
- }
- static int current_phase(void)
- {
- return initial_params::current_phase;
- }
- static int last_phase(void)
- {
- return (initial_params::current_phase
- >=initial_params::max_number_phases);
- }
- static prevariable& current_feval(void)
- {
- return *objective_function_value::pobjfun;
- }
-private:
- dvariable adromb(dvariable(model_parameters::*f)(const dvariable&), double a, double b, int ns)
- {
- using namespace std::placeholders;
- _func func = std::bind(f, this, _1);
- return function_minimizer::adromb(func, a, b, ns);
- }
- ivector integer_control_flags;
- dvector double_control_flags;
- param_init_bounded_vector log_Rzero;
- param_init_bounded_vector steepness;
- param_init_bounded_vector sigr;
- param_init_number dummy;
- param_vector sr_alpha;
- param_vector beta;
- param_vector Rzero;
- param_vector rec_like;
- param_stddev_vector Bzero;
- param_vector phizero;
- param_vector phi;
- param_vector sigmaRsq;
- param_vector MSY;
- param_vector Fmsy;
- param_vector Bmsy;
- param_vector Rmsy;
- param_vector sigmar;
- param_number prior_function_value;
- param_number likelihood_function_value;
- objective_function_value obj_fun;
-public:
- virtual void userfunction(void);
- virtual void report(const dvector& gradients);
- virtual void final_calcs(void);
- model_parameters(int sz,int argc, char * argv[]);
- virtual void initializationfunction(void);
- void Run_Sim(void);
- void compute_obj_fun(void);
- void opt_sim(void);
- void Mainloop(int& isim);
- void Alt4_TAC(void);
- double Get_Catch(const int& thisalt, const int& ispp);
- double Get_F(const int& thisalt,const int& ispp);
- double Get_F_SSL_prey(const dvector& F_age, const dvector& N_females, const int ispp );
- double Get_F_Am56(const dvector& F_age, const dvector& N_females, const int ispp );
- double Get_Fofl_t2(const dvector& F_age, const dvector& N_females, const int ispp );
- double Get_Fofl_t(const dvector& F_age, const dvector& N_females, const int ispp );
- double Get_F_t(const dvector& F_age, const dvector& N_females, const int ispp );
- void Project_Pops(const int& isim, const int& i);
- void Status_Determ(void);
- void Fit_TAC(void);
- void Avg_Age(void);
- void get_SB100(void);
- void compute_spr_rates(void);
- double Implied_SPR( const dvector& F_age, const int& ispp);
- double SolveF2(const dvector& N_F, const dvector& N_M, const double& TACin, const int& ispp);
- void Get_SPR_Catches(const int& ispp);
- void write_srec(void);
- void Do_Sims(void);
- void write_by_time(void);
- void write_avg_age(const adstring& Title);
- void write_alts(void);
- void write_alts_hdr(void);
- void write_ABCs(const adstring& Title);
- void write_TACs(const adstring& Title);
- void write_sim(const adstring& Title, d3_array& Outtmp);
- void write_sim(const adstring& Title,const d3_array& Outtmp,const dvar_vector& bb);
- void write_sim(const adstring& Title,const int& ispp);
- void write_sim_hdr(const int& ispp);
- void write_spp(const int& ispp);
- dvariable SRecruit(const dvariable& Stmp,const int& ispp);
- dvar_vector SRecruit(const dvar_vector& Stmp,const int& ispp);
- dvariable Requil(const dvariable& phi,const int& ispp);
- void Get_Bzero(const int& ispp);
- void Recruitment_Likelihood(const int& ispp);
- void Profile_F(const int& ispp);
- void get_msy(const int& ispp);
- dvariable yield(const dvariable& Ftmp, dvariable& Stmp,dvariable& Rtmp,const int& ispp);
- double get_spr_rates(double spr_percent,int& ispp);
- double spr_ratio(double& trial_F,dmatrix& sel_tmp_F, int& ispp);
- void do_elasticity();
-
-};
-#endif