diff --git a/NAMESPACE b/NAMESPACE index 8bde9cb..3792ba9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,4 +7,3 @@ export(confint_Deriv) export(get_Breaks) export(refit_Growth) import(mgcv) -useDynLib(sptlVB_Sel_Sigma) diff --git a/src/sptlVB_Sel_Sigma.cpp b/src/sptlVB_Sel_Sigma.cpp deleted file mode 100644 index 3565729..0000000 --- a/src/sptlVB_Sel_Sigma.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#define TMB_LIB_INIT R_init_growthbreaks -#include -#include -// https://kaskr.github.io/adcomp/register_atomic_8cpp-example.html#a3 -// Similar to example 'adaptive_integration' using CppAD Romberg integration. REGISTER_ATOMIC is used to reduce tape size. -// #include // per https://github.com/mlysy/TMBtools this shouldn't be here -template Type selex(Type x){return 1/(1+exp( 52.976 - x)) ;} - - -template -struct univariate { - Type Linf, k, Age, t0, Sigma; // variables in integrand, - Type operator() (Type u) { - Type yfit = 0; - Type selPred = 0; - Type ans = 0; - yfit = Linf*(1-exp(-k*(Age - t0))); // generate predicted length - selPred = selex(yfit); //1.0 for testing - // ans = selPred * exp(-(yfit - u)/(2*pow(Sigma*Age,2.0))); // u is what is plugged a and b - ans = selPred * dnorm(yfit,u,Sigma,false); // just hardcode the individuals - return ans; - } -}; - -template -vector mydenom(vector input) { - Type Linf = input[0], k = input[1]; // Data - Type Age = input[2], t0 = input[3]; Type Sigma = input[4]; // Parameters - univariate f = {Linf, k, Age, t0, Sigma}; - Type a = 0, b = 200; // max obs was 160 - vector res(1); // a place to store this output - res[0] = romberg::integrate(f, a, b); - return res; -} -REGISTER_ATOMIC(mydenom) - template - Type objective_function::operator() () - { - - DATA_VECTOR(Length_cm); // observed lengths - DATA_VECTOR(Age); // observed ages - DATA_VECTOR(Sel); // selectivity at observed length - DATA_IVECTOR(selType); // turns selectivity on/off for DFO data - DATA_IVECTOR(DES); // to organize data - DATA_INTEGER(nStrata); - DATA_INTEGER(a2); // fixed, for reporing L1/L2 - - PARAMETER_VECTOR(t0); // t0 can be negative - - PARAMETER_VECTOR(log_Sigma); - vector Sigma(nStrata); //nstrata - Sigma = exp(log_Sigma); - // Type Sigma = exp(log_Sigma); // use exponentiated here - - PARAMETER_VECTOR(log_Linf); - vector Linf(nStrata); //nstrata - Linf = exp(log_Linf); - - PARAMETER_VECTOR(log_k); - vector k(nStrata); - k = exp(log_k); - - // things to calculate - vector ypreds(Age.rows()); - // Type selPred = 0.0; - Type selObs = 0.0; - Type yfit = 0; - Type ans = 0; - // Type tiny = 0.0; // Set to 1e-12 for robustness - - Type numerator = 0.0; // will be the same for everyone - Type denominator = 0.0; - - vector L1(nStrata); - vector L2(nStrata); - - for(int i=0; i < Age.rows(); i++) { - yfit = Linf(DES(i))*(1-exp(-k(DES(i))*(Age(i) - t0(DES(i))))); - - - if(selType(i) != 2){ - selObs = 1.0; // coerce to 1.0 for non DFO regions - numerator = selObs*dnorm(Length_cm(i),yfit,Sigma(DES(i)),false) ; // typical dnorm, sel obs is 1 - denominator = 1.0; - } - if(selType(i) == 2){ - selObs = selex(Length_cm(i)); // selex of OBSERVED value - numerator = selObs*dnorm(Length_cm(i),yfit,Sigma(DES(i)),false); // typical dnorm, sel obs is 1 - - vector input(5); - input << Linf(DES(i)), k(DES(i)), Age(DES(i)), t0(DES(i)), Sigma(DES(i)); // bundle the current estimates - denominator = mydenom(input)[0]; // calc denominator based on curr estimates - - // ans -= log( mydenom(input)[0] + tiny ); - } - ans -= log(numerator + 1e-5)-log(denominator + 1e-5); // will just be numerator for denom = 1 - ypreds(i) = yfit; // store estimated length - - - L1(DES(i)) = Linf(DES(i))*(1-exp(-k(DES(i))*(4.0 - t0(DES(i))))); // change 0, 0.5 - L2(DES(i)) = Linf(DES(i))*(1-exp(-k(DES(i))*(a2 - t0(DES(i))))); - - - } // end rows - - REPORT(ypreds); - ADREPORT(ypreds); - REPORT(denominator) - ADREPORT(t0); - ADREPORT(k); - ADREPORT(Linf); - ADREPORT(L1); - ADREPORT(L2); - ADREPORT(Sigma); - return(ans); - } diff --git a/src/sptlVB_Sel_Sigma.dll b/src/sptlVB_Sel_Sigma.dll deleted file mode 100644 index da4c3d5..0000000 Binary files a/src/sptlVB_Sel_Sigma.dll and /dev/null differ diff --git a/src/sptlVB_Sel_Sigma.o b/src/sptlVB_Sel_Sigma.o deleted file mode 100644 index 393df6b..0000000 Binary files a/src/sptlVB_Sel_Sigma.o and /dev/null differ