From bd2d83202887555d9c28d98f2c45835d09df5a5e Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Sun, 29 Mar 2015 12:06:50 -0700 Subject: [PATCH 01/61] Added qdev parameters --- src/admb-code/iscam.tpl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index ad4a550f..6268d647 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1556,6 +1556,12 @@ PARAMETER_SECTION //init_bounded_vector log_m_nodes(1,n_m_devs,-5.0,5.0,m_dev_phz); init_bounded_vector log_m_nodes(1,nMdev,-5.0,5.0,Mdev_phz); + // |---------------------------------------------------------------------------------| + // | DEVIATIONS IN CATCHABILITY COEFFICIENTS ASSUMING A RANDOM WALK | + // |---------------------------------------------------------------------------------| + // | + init_bounded_matrix log_q_devs(1,nItNobs,1,n_it_nobs,-5.0,5.0,-1); + // |---------------------------------------------------------------------------------| // | CORRELATION COEFFICIENTS FOR AGE COMPOSITION DATA USED IN LOGISTIC NORMAL | // |---------------------------------------------------------------------------------| @@ -1630,7 +1636,7 @@ PARAMETER_SECTION vector varphi(1,ngroup); vector sig(1,ngroup); vector tau(1,ngroup); - vector sigma_r(1,ngroup); + vector sigma_r(1,ngroup); // |---------------------------------------------------------------------------------| // | MATRIX OBJECTS From 2723e76f1933c7ec67ece868bb887aa462e6f673 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 10:03:59 -0700 Subject: [PATCH 02/61] Implemented time-varying q with random walk parameters estimated, revamped survey q controls --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 26 +-- fba/HALIBUT/DATA/Halibut2014.dat | 210 +++++++++++----------- src/admb-code/iscam.tpl | 134 ++++++++------ 3 files changed, 202 insertions(+), 168 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 94eaed55..3bb8bcc6 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -83,7 +83,7 @@ 1888 1888 1888 -## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## TIME VARYING NATURAL MORTALIIY RATES ## ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -104,18 +104,20 @@ ## ———————————————————————————————————————————————————————————————————————————————————— ## ## ## -## ------------------------------------------------------------------------- ## -## PRIORS FOR SURVEY Q ## -## Prior type: ## -## 0 - uninformative prior ## -## 1 - normal prior density for log(q) ## -## 2 - random walk in q ## -## ------------------------------------------------------------------------- ## -2 # -number of surveys (nits) -0 0 # -prior type (see legend above +## ———————————————————————————————————————————————————————————————————————————————————— ## +## ABUNDANCE OBSERVATION MODELS +## ———————————————————————————————————————————————————————————————————————————————————— ## +## QTYPE: +## 0 = FIXED SURVEY Q (specify log(mean) for prior log(mean)) +## 1 = CONSTANT Q (use MLE for q and optional informative prior) +## 2 = RANDOM WALK Q (use prior mean & sd for penalized random walk) +## ———————————————————————————————————————————————————————————————————————————————————— ## +2 # -number of surveys (n_it_nobs) +2 2 # -QTYPE (see legend above) 0 0 # -prior log(mean) -0 0 # -prior sd -## ------------------------------------------------------------------------- ## +0 0 # -prior sd (set to 0 for uniformative prior) +2 2 # -Estimation phase +## ———————————————————————————————————————————————————————————————————————————————————— ## ## ## ------------------------------------------------------------------------- ## diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index 42cd972d..c52a7dbb 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -384,111 +384,111 @@ ## commercial_data: ## survey ## iyr index(it) gear area group sex log(SE) log(PE) timing - 1907 280 1 1 1 0 0.100 0.010 0.5 - 1910 271 1 1 1 0 0.100 0.010 0.5 - 1911 237 1 1 1 0 0.100 0.010 0.5 - 1912 176 1 1 1 0 0.100 0.010 0.5 - 1913 129 1 1 1 0 0.100 0.010 0.5 - 1914 124 1 1 1 0 0.100 0.010 0.5 - 1915 118 1 1 1 0 0.100 0.010 0.5 - 1916 137 1 1 1 0 0.100 0.010 0.5 - 1917 98 1 1 1 0 0.100 0.010 0.5 - 1918 96 1 1 1 0 0.100 0.010 0.5 - 1919 93 1 1 1 0 0.100 0.010 0.5 - 1920 96 1 1 1 0 0.100 0.010 0.5 - 1921 88 1 1 1 0 0.100 0.010 0.5 - 1922 73 1 1 1 0 0.100 0.010 0.5 - 1923 78 1 1 1 0 0.100 0.010 0.5 - 1924 74 1 1 1 0 0.100 0.010 0.5 - 1925 68 1 1 1 0 0.100 0.010 0.5 - 1926 67 1 1 1 0 0.100 0.010 0.5 - 1927 65 1 1 1 0 0.100 0.010 0.5 - 1928 58 1 1 1 0 0.100 0.010 0.5 - 1929 51 1 1 1 0 0.100 0.010 0.5 - 1930 46 1 1 1 0 0.100 0.010 0.5 - 1931 50 1 1 1 0 0.100 0.010 0.5 - 1932 60 1 1 1 0 0.100 0.010 0.5 - 1933 63 1 1 1 0 0.100 0.010 0.5 - 1934 62 1 1 1 0 0.100 0.010 0.5 - 1935 76 1 1 1 0 0.100 0.010 0.5 - 1936 71 1 1 1 0 0.100 0.010 0.5 - 1937 80 1 1 1 0 0.100 0.010 0.5 - 1938 88 1 1 1 0 0.100 0.010 0.5 - 1939 80 1 1 1 0 0.100 0.010 0.5 - 1940 81 1 1 1 0 0.100 0.010 0.5 - 1941 85 1 1 1 0 0.100 0.010 0.5 - 1942 90 1 1 1 0 0.100 0.010 0.5 - 1943 95 1 1 1 0 0.100 0.010 0.5 - 1944 110 1 1 1 0 0.100 0.010 0.5 - 1945 102 1 1 1 0 0.100 0.010 0.5 - 1946 101 1 1 1 0 0.100 0.010 0.5 - 1947 99 1 1 1 0 0.100 0.010 0.5 - 1948 99 1 1 1 0 0.100 0.010 0.5 - 1949 95 1 1 1 0 0.100 0.010 0.5 - 1950 95 1 1 1 0 0.100 0.010 0.5 - 1951 96 1 1 1 0 0.100 0.010 0.5 - 1952 110 1 1 1 0 0.100 0.010 0.5 - 1953 131 1 1 1 0 0.100 0.010 0.5 - 1954 133 1 1 1 0 0.100 0.010 0.5 - 1955 119 1 1 1 0 0.100 0.010 0.5 - 1956 129 1 1 1 0 0.100 0.010 0.5 - 1957 110 1 1 1 0 0.100 0.010 0.5 - 1958 121 1 1 1 0 0.100 0.010 0.5 - 1959 129 1 1 1 0 0.100 0.010 0.5 - 1960 132 1 1 1 0 0.100 0.010 0.5 - 1961 127 1 1 1 0 0.100 0.010 0.5 - 1962 115 1 1 1 0 0.100 0.010 0.5 - 1963 105 1 1 1 0 0.100 0.010 0.5 - 1964 100 1 1 1 0 0.100 0.010 0.5 - 1965 99 1 1 1 0 0.100 0.010 0.5 - 1966 100 1 1 1 0 0.100 0.010 0.5 - 1967 101 1 1 1 0 0.100 0.010 0.5 - 1968 103 1 1 1 0 0.100 0.010 0.5 - 1969 95 1 1 1 0 0.100 0.010 0.5 - 1970 91 1 1 1 0 0.100 0.010 0.5 - 1971 89 1 1 1 0 0.100 0.010 0.5 - 1972 78 1 1 1 0 0.100 0.010 0.5 - 1973 63 1 1 1 0 0.100 0.010 0.5 - 1974 61 1 1 1 0 0.100 0.010 0.5 - 1975 61 1 1 1 0 0.100 0.010 0.5 - 1976 55 1 1 1 0 0.100 0.010 0.5 - 1977 63 1 1 1 0 0.100 0.010 0.5 - 1978 71 1 1 1 0 0.100 0.010 0.5 - 1979 75 1 1 1 0 0.100 0.010 0.5 - 1980 94 1 1 1 0 0.100 0.010 0.5 - 1981 111 1 1 1 0 0.100 0.010 0.5 - 1982 127 1 1 1 0 0.100 0.010 0.5 - 1984 291 1 1 1 0 0.100 0.010 0.5 - 1985 357 1 1 1 0 0.036 0.010 0.5 - 1986 320 1 1 1 0 0.041 0.010 0.5 - 1987 321 1 1 1 0 0.040 0.010 0.5 - 1988 368 1 1 1 0 0.035 0.010 0.5 - 1989 358 1 1 1 0 0.025 0.010 0.5 - 1990 319 1 1 1 0 0.028 0.010 0.5 - 1991 318 1 1 1 0 0.038 0.010 0.5 - 1992 319 1 1 1 0 0.034 0.010 0.5 - 1993 373 1 1 1 0 0.099 0.010 0.5 - 1994 306 1 1 1 0 0.072 0.010 0.5 - 1995 330 1 1 1 0 0.036 0.010 0.5 - 1996 392 1 1 1 0 0.038 0.010 0.5 - 1997 405 1 1 1 0 0.025 0.010 0.5 - 1998 408 1 1 1 0 0.025 0.010 0.5 - 1999 393 1 1 1 0 0.023 0.010 0.5 - 2000 403 1 1 1 0 0.022 0.010 0.5 - 2001 362 1 1 1 0 0.041 0.010 0.5 - 2002 360 1 1 1 0 0.019 0.010 0.5 - 2003 329 1 1 1 0 0.018 0.010 0.5 - 2004 319 1 1 1 0 0.019 0.010 0.5 - 2005 296 1 1 1 0 0.017 0.010 0.5 - 2006 270 1 1 1 0 0.019 0.010 0.5 - 2007 252 1 1 1 0 0.020 0.010 0.5 - 2008 232 1 1 1 0 0.017 0.010 0.5 - 2009 222 1 1 1 0 0.018 0.010 0.5 - 2010 204 1 1 1 0 0.020 0.010 0.5 - 2011 198 1 1 1 0 0.015 0.010 0.5 - 2012 195 1 1 1 0 0.021 0.010 0.5 - 2013 179 1 1 1 0 0.017 0.010 0.5 - 2014 191 1 1 1 0 0.052 0.010 0.5 + 1907 280 1 1 1 0 0.100 0.050 0.5 + 1910 271 1 1 1 0 0.100 0.050 0.5 + 1911 237 1 1 1 0 0.100 0.050 0.5 + 1912 176 1 1 1 0 0.100 0.050 0.5 + 1913 129 1 1 1 0 0.100 0.050 0.5 + 1914 124 1 1 1 0 0.100 0.050 0.5 + 1915 118 1 1 1 0 0.100 0.050 0.5 + 1916 137 1 1 1 0 0.100 0.050 0.5 + 1917 98 1 1 1 0 0.100 0.050 0.5 + 1918 96 1 1 1 0 0.100 0.050 0.5 + 1919 93 1 1 1 0 0.100 0.050 0.5 + 1920 96 1 1 1 0 0.100 0.050 0.5 + 1921 88 1 1 1 0 0.100 0.050 0.5 + 1922 73 1 1 1 0 0.100 0.050 0.5 + 1923 78 1 1 1 0 0.100 0.050 0.5 + 1924 74 1 1 1 0 0.100 0.050 0.5 + 1925 68 1 1 1 0 0.100 0.050 0.5 + 1926 67 1 1 1 0 0.100 0.050 0.5 + 1927 65 1 1 1 0 0.100 0.050 0.5 + 1928 58 1 1 1 0 0.100 0.050 0.5 + 1929 51 1 1 1 0 0.100 0.050 0.5 + 1930 46 1 1 1 0 0.100 0.050 0.5 + 1931 50 1 1 1 0 0.100 0.050 0.5 + 1932 60 1 1 1 0 0.100 0.050 0.5 + 1933 63 1 1 1 0 0.100 0.050 0.5 + 1934 62 1 1 1 0 0.100 0.050 0.5 + 1935 76 1 1 1 0 0.100 0.050 0.5 + 1936 71 1 1 1 0 0.100 0.050 0.5 + 1937 80 1 1 1 0 0.100 0.050 0.5 + 1938 88 1 1 1 0 0.100 0.050 0.5 + 1939 80 1 1 1 0 0.100 0.050 0.5 + 1940 81 1 1 1 0 0.100 0.050 0.5 + 1941 85 1 1 1 0 0.100 0.050 0.5 + 1942 90 1 1 1 0 0.100 0.050 0.5 + 1943 95 1 1 1 0 0.100 0.050 0.5 + 1944 110 1 1 1 0 0.100 0.050 0.5 + 1945 102 1 1 1 0 0.100 0.050 0.5 + 1946 101 1 1 1 0 0.100 0.050 0.5 + 1947 99 1 1 1 0 0.100 0.050 0.5 + 1948 99 1 1 1 0 0.100 0.050 0.5 + 1949 95 1 1 1 0 0.100 0.050 0.5 + 1950 95 1 1 1 0 0.100 0.050 0.5 + 1951 96 1 1 1 0 0.100 0.050 0.5 + 1952 110 1 1 1 0 0.100 0.050 0.5 + 1953 131 1 1 1 0 0.100 0.050 0.5 + 1954 133 1 1 1 0 0.100 0.050 0.5 + 1955 119 1 1 1 0 0.100 0.050 0.5 + 1956 129 1 1 1 0 0.100 0.050 0.5 + 1957 110 1 1 1 0 0.100 0.050 0.5 + 1958 121 1 1 1 0 0.100 0.050 0.5 + 1959 129 1 1 1 0 0.100 0.050 0.5 + 1960 132 1 1 1 0 0.100 0.050 0.5 + 1961 127 1 1 1 0 0.100 0.050 0.5 + 1962 115 1 1 1 0 0.100 0.050 0.5 + 1963 105 1 1 1 0 0.100 0.050 0.5 + 1964 100 1 1 1 0 0.100 0.050 0.5 + 1965 99 1 1 1 0 0.100 0.050 0.5 + 1966 100 1 1 1 0 0.100 0.050 0.5 + 1967 101 1 1 1 0 0.100 0.050 0.5 + 1968 103 1 1 1 0 0.100 0.050 0.5 + 1969 95 1 1 1 0 0.100 0.050 0.5 + 1970 91 1 1 1 0 0.100 0.050 0.5 + 1971 89 1 1 1 0 0.100 0.050 0.5 + 1972 78 1 1 1 0 0.100 0.050 0.5 + 1973 63 1 1 1 0 0.100 0.050 0.5 + 1974 61 1 1 1 0 0.100 0.050 0.5 + 1975 61 1 1 1 0 0.100 0.050 0.5 + 1976 55 1 1 1 0 0.100 0.050 0.5 + 1977 63 1 1 1 0 0.100 0.050 0.5 + 1978 71 1 1 1 0 0.100 0.050 0.5 + 1979 75 1 1 1 0 0.100 0.050 0.5 + 1980 94 1 1 1 0 0.100 0.050 0.5 + 1981 111 1 1 1 0 0.100 0.050 0.5 + 1982 127 1 1 1 0 0.100 0.050 0.5 + 1984 291 1 1 1 0 0.100 1.050 0.5 + 1985 357 1 1 1 0 0.036 0.050 0.5 + 1986 320 1 1 1 0 0.041 0.050 0.5 + 1987 321 1 1 1 0 0.040 0.050 0.5 + 1988 368 1 1 1 0 0.035 0.050 0.5 + 1989 358 1 1 1 0 0.025 0.050 0.5 + 1990 319 1 1 1 0 0.028 0.050 0.5 + 1991 318 1 1 1 0 0.038 0.050 0.5 + 1992 319 1 1 1 0 0.034 0.050 0.5 + 1993 373 1 1 1 0 0.099 0.050 0.5 + 1994 306 1 1 1 0 0.072 0.050 0.5 + 1995 330 1 1 1 0 0.036 0.050 0.5 + 1996 392 1 1 1 0 0.038 0.050 0.5 + 1997 405 1 1 1 0 0.025 0.050 0.5 + 1998 408 1 1 1 0 0.025 0.050 0.5 + 1999 393 1 1 1 0 0.023 0.050 0.5 + 2000 403 1 1 1 0 0.022 0.050 0.5 + 2001 362 1 1 1 0 0.041 0.050 0.5 + 2002 360 1 1 1 0 0.019 0.050 0.5 + 2003 329 1 1 1 0 0.018 0.050 0.5 + 2004 319 1 1 1 0 0.019 0.050 0.5 + 2005 296 1 1 1 0 0.017 0.050 0.5 + 2006 270 1 1 1 0 0.019 0.050 0.5 + 2007 252 1 1 1 0 0.020 0.050 0.5 + 2008 232 1 1 1 0 0.017 0.050 0.5 + 2009 222 1 1 1 0 0.018 0.050 0.5 + 2010 204 1 1 1 0 0.020 0.050 0.5 + 2011 198 1 1 1 0 0.015 0.050 0.5 + 2012 195 1 1 1 0 0.021 0.050 0.5 + 2013 179 1 1 1 0 0.017 0.050 0.5 + 2014 191 1 1 1 0 0.052 0.050 0.5 ## survey_data: 1977 1.4713 6 1 1 0 0.100 0.010 0.5 1978 1.1112 6 1 1 0 0.100 0.010 0.5 diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 6268d647..e95a5e1c 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1233,6 +1233,7 @@ DATA_SECTION init_ivector q_prior(1,nits); init_vector mu_log_q(1,nits); init_vector sd_log_q(1,nits); + init_ivector q_phz(1,nits); // |---------------------------------------------------------------------------------| // | Miscellaneous controls | @@ -1560,7 +1561,7 @@ PARAMETER_SECTION // | DEVIATIONS IN CATCHABILITY COEFFICIENTS ASSUMING A RANDOM WALK | // |---------------------------------------------------------------------------------| // | - init_bounded_matrix log_q_devs(1,nItNobs,1,n_it_nobs,-5.0,5.0,-1); + init_bounded_vector_vector log_q_devs(1,nItNobs,1,n_it_nobs,-5.1,5.0,q_phz); // |---------------------------------------------------------------------------------| // | CORRELATION COEFFICIENTS FOR AGE COMPOSITION DATA USED IN LOGISTIC NORMAL | @@ -1876,7 +1877,7 @@ FUNCTION void initParameters() steepness = theta(2); m = mfexp(theta(3)); rho = theta(6); - sigma_r = theta(7); + sigma_r = theta(7); //varphi = sqrt(1.0/theta(7)); sig = elem_prod(sqrt(rho) , varphi); //tau = elem_prod(sqrt(1.0-rho) , varphi); @@ -1966,23 +1967,7 @@ FUNCTION dvector cubic_spline(const dvector& spline_coffs, const dvector& la) //return(1.0*la); } -// FUNCTION dvar_matrix cubic_spline_matrix(const dvar_matrix& spline_coffs) -// { -// RETURN_ARRAYS_INCREMENT(); -// int nodes= spline_coffs.colmax()-spline_coffs.colmin()+1; -// int rmin = spline_coffs.rowmin(); -// int rmax = spline_coffs.rowmax(); - -// dvector ia(1,nodes); -// dvector fa(sage,nage); -// ia.fill_seqadd(0,1./(nodes-1)); -// //fa.fill_seqadd(sage,1); -// fa.fill_seqadd(0,1./(nage-sage)); -// vcubic_spline_function_array fna(rmin,rmax,ia,spline_coffs); -// RETURN_ARRAYS_DECREMENT(); -// return(fna(fa)); - -// } + /** @@ -2767,6 +2752,7 @@ FUNCTION calcTotalCatch fishery that would remove potential spawn that would not be surveyed. - d3_survey_data: (iyr index(it) gear area group sex wt timing) - for MLE of survey q, using weighted mean of zt to calculate q. + - March 30, 2015. Added deviation in q for random walk. TODO list: [] - add capability to accomodate priors for survey q's. @@ -2779,11 +2765,12 @@ FUNCTION calcSurveyObservations int ii,kk,ig,nz; double di; - dvariable ftmp; + dvariable ftmp,zbar; dvar_vector Na(sage,nage); dvar_vector va(sage,nage); dvar_vector sa(sage,nage); epsilon.initialize(); + qt.initialize(); xi.initialize(); it_hat.initialize(); @@ -2845,42 +2832,87 @@ FUNCTION calcSurveyObservations dvar_vector t1 = rowsum(V); - dvar_vector zt = log(it) - log(t1(iz,nz)); - dvariable zbar = sum(elem_prod(zt,wt)); - q(kk) = mfexp(zbar); - - // | survey residuals - epsilon(kk).sub(iz,nz) = elem_div(zt - zbar,it_log_se(kk)(iz,nz)); - it_hat(kk).sub(iz,nz) = q(kk) * t1(iz,nz); + dvar_vector zt = log(it); + - // | SPECIAL CASE: penalized random walk in q process error only. - if( q_prior(kk)==2 ) + // | March 30, 2015. Issue #37. + // | Added switch for 3 q_prior(kk) options. + // | q_prior(kk) = 0 = constant fixed Q + // | q_prior(kk) = 1 = constant MLE Q + // | q_prior(kk) = 2 = penalized random walk in Q + switch( q_prior(kk) ) { - epsilon(kk).initialize(); - dvar_vector fd_zt = first_difference(zt); - dvariable zw_bar = sum(elem_prod(fd_zt,wt(iz,nz-1))); - epsilon(kk).sub(iz,nz-1) = elem_div(fd_zt - zw_bar,it_log_se(kk)(iz,nz-1)); - qt(kk)(iz) = exp(zt(iz)); - for(ii=iz+1;ii<=nz;ii++) - { - qt(kk)(ii) = qt(kk)(ii-1) * exp(fd_zt(ii-1)); - } - it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); + case 0: // Constant fixed Q + q(kk) = exp(mu_log_q(kk)); + it_hat(kk).sub(iz,nz) = q(kk) * t1(iz,nz); + zt -= log(it_hat(kk).sub(iz,nz)); + break; + + case 1: // Constant MLE Q + zt -= log(t1(iz,nz)); + zbar = sum(elem_prod(zt,wt)); + q(kk) = mfexp(zbar); + + // | survey residuals + it_hat(kk).sub(iz,nz) = q(kk) * t1(iz,nz); + zt -= zbar; + //epsilon(kk).sub(iz,nz) = elem_div(zt,it_log_se(kk)(iz,nz)); + break; + + case 2: // Penalized random walk in Q + zt -= log(t1(iz,nz)); + qt(kk)(iz) = exp( zt(iz) + log_q_devs(kk)(iz) ); + for(ii=iz+1; ii<=nz; ii++) + { + COUT(ii); + qt(kk)(ii) = qt(kk)(ii-1) * exp(log_q_devs(kk)(ii)); + } + it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); + zt -= log(qt(kk)(iz,nz)); + //epsilon(kk).sub(iz,nz)= elem_div(zt,it_log_se(kk)(iz,nz)); + break; } - // | MIXED ERROR MODEL for random walk in q - if( q_prior(kk)==3 ) + // Standardized observation error residuals. + COUT(qt); + epsilon(kk).sub(iz,nz) = elem_div(zt,it_log_se(kk)(iz,nz)); + + // Standardized process error residuals. + if(active(log_q_devs(kk))) { - dvar_vector proerr = zt - zbar; - qt(kk)(ii) = exp(zbar + proerr(iz)); - for(ii=iz+1;ii<=nz;ii++) - { - proerr(ii) = zt(ii) - zt(ii-1); - qt(kk)(ii) = qt(kk)(ii-1) * exp(proerr(ii)); - } - xi(kk).sub(iz,nz) = elem_div(proerr,it_log_pe(kk)(iz,nz)); - it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); + dvar_vector fd_qt = first_difference( log(qt(kk)(iz,nz)) ); + xi(kk).sub(iz,nz-1) = elem_div(fd_qt,it_log_pe(kk)(iz,nz-1)); } + +// TO BE DEPRECATED +// // | SPECIAL CASE: penalized random walk in q process error only. +// if( q_prior(kk)==2 ) +// { +// epsilon(kk).initialize(); +// dvar_vector fd_zt = first_difference(zt); +// dvariable zw_bar = sum(elem_prod(fd_zt,wt(iz,nz-1))); +// epsilon(kk).sub(iz,nz-1) = elem_div(fd_zt - zw_bar,it_log_se(kk)(iz,nz-1)); +// qt(kk)(iz) = exp(zt(iz)); +// for(ii=iz+1;ii<=nz;ii++) +// { +// qt(kk)(ii) = qt(kk)(ii-1) * exp(fd_zt(ii-1)); +// } +// it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); +// } +// +// // | MIXED ERROR MODEL for random walk in q +// if( q_prior(kk)==3 ) +// { +// dvar_vector proerr = zt - zbar; +// qt(kk)(ii) = exp(zbar + proerr(iz)); +// for(ii=iz+1;ii<=nz;ii++) +// { +// proerr(ii) = zt(ii) - zt(ii-1); +// qt(kk)(ii) = qt(kk)(ii-1) * exp(proerr(ii)); +// } +// xi(kk).sub(iz,nz) = elem_div(proerr,it_log_pe(kk)(iz,nz)); +// it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); +// } } if(verbose)cout<<"**** Ok after calcSurveyObservations ****"< Date: Mon, 30 Mar 2015 10:25:03 -0700 Subject: [PATCH 03/61] q_dev parameters now estimable --- fba/HALIBUT/DATA/Halibut2014.dat | 58 ++++++++++++++++---------------- src/admb-code/iscam.tpl | 8 ++--- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index c52a7dbb..e831c7da 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -458,7 +458,7 @@ 1980 94 1 1 1 0 0.100 0.050 0.5 1981 111 1 1 1 0 0.100 0.050 0.5 1982 127 1 1 1 0 0.100 0.050 0.5 - 1984 291 1 1 1 0 0.100 1.050 0.5 + 1984 291 1 1 1 0 0.100 1.000 0.5 1985 357 1 1 1 0 0.036 0.050 0.5 1986 320 1 1 1 0 0.041 0.050 0.5 1987 321 1 1 1 0 0.040 0.050 0.5 @@ -490,34 +490,34 @@ 2013 179 1 1 1 0 0.017 0.050 0.5 2014 191 1 1 1 0 0.052 0.050 0.5 ## survey_data: - 1977 1.4713 6 1 1 0 0.100 0.010 0.5 - 1978 1.1112 6 1 1 0 0.100 0.010 0.5 - 1980 2.0090 6 1 1 0 0.100 0.010 0.5 - 1981 2.6670 6 1 1 0 0.100 0.010 0.5 - 1982 2.8739 6 1 1 0 0.100 0.010 0.5 - 1983 2.8816 6 1 1 0 0.100 0.010 0.5 - 1984 9.3014 6 1 1 0 0.100 0.010 0.5 - 1985 8.9419 6 1 1 0 0.100 0.010 0.5 - 1986 6.2568 6 1 1 0 0.100 0.010 0.5 - 1996 12.8858 6 1 1 0 0.100 0.010 0.5 - 1997 7.7841 6 1 1 0 0.034 0.010 0.5 - 1998 6.9727 6 1 1 0 0.034 0.010 0.5 - 1999 6.2649 6 1 1 0 0.034 0.010 0.5 - 2000 6.6265 6 1 1 0 0.034 0.010 0.5 - 2001 6.3842 6 1 1 0 0.028 0.010 0.5 - 2002 6.3893 6 1 1 0 0.026 0.010 0.5 - 2003 5.7876 6 1 1 0 0.027 0.010 0.5 - 2004 6.4579 6 1 1 0 0.026 0.010 0.5 - 2005 5.9282 6 1 1 0 0.027 0.010 0.5 - 2006 5.4306 6 1 1 0 0.027 0.010 0.5 - 2007 5.7267 6 1 1 0 0.027 0.010 0.5 - 2008 5.6536 6 1 1 0 0.026 0.010 0.5 - 2009 5.4952 6 1 1 0 0.027 0.010 0.5 - 2010 5.1239 6 1 1 0 0.029 0.010 0.5 - 2011 5.0435 6 1 1 0 0.029 0.010 0.5 - 2012 5.5606 6 1 1 0 0.030 0.010 0.5 - 2013 4.7301 6 1 1 0 0.034 0.010 0.5 - 2014 5.1645 6 1 1 0 0.032 0.010 0.5 + 1977 1.4713 6 1 1 0 0.100 0.050 0.5 + 1978 1.1112 6 1 1 0 0.100 0.050 0.5 + 1980 2.0090 6 1 1 0 0.100 0.050 0.5 + 1981 2.6670 6 1 1 0 0.100 0.050 0.5 + 1982 2.8739 6 1 1 0 0.100 1.000 0.5 + 1983 2.8816 6 1 1 0 0.100 0.050 0.5 + 1984 9.3014 6 1 1 0 0.100 1.000 0.5 + 1985 8.9419 6 1 1 0 0.100 0.050 0.5 + 1986 6.2568 6 1 1 0 0.100 0.050 0.5 + 1996 12.8858 6 1 1 0 0.100 0.050 0.5 + 1997 7.7841 6 1 1 0 0.034 1.000 0.5 + 1998 6.9727 6 1 1 0 0.034 0.050 0.5 + 1999 6.2649 6 1 1 0 0.034 0.050 0.5 + 2000 6.6265 6 1 1 0 0.034 0.050 0.5 + 2001 6.3842 6 1 1 0 0.028 0.050 0.5 + 2002 6.3893 6 1 1 0 0.026 0.050 0.5 + 2003 5.7876 6 1 1 0 0.027 0.050 0.5 + 2004 6.4579 6 1 1 0 0.026 0.050 0.5 + 2005 5.9282 6 1 1 0 0.027 0.050 0.5 + 2006 5.4306 6 1 1 0 0.027 0.050 0.5 + 2007 5.7267 6 1 1 0 0.027 0.050 0.5 + 2008 5.6536 6 1 1 0 0.026 0.050 0.5 + 2009 5.4952 6 1 1 0 0.027 0.050 0.5 + 2010 5.1239 6 1 1 0 0.029 0.050 0.5 + 2011 5.0435 6 1 1 0 0.029 0.050 0.5 + 2012 5.5606 6 1 1 0 0.030 0.050 0.5 + 2013 4.7301 6 1 1 0 0.034 0.100 0.5 + 2014 5.1645 6 1 1 0 0.032 0.100 0.5 ## ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index e95a5e1c..d63697e1 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1561,7 +1561,7 @@ PARAMETER_SECTION // | DEVIATIONS IN CATCHABILITY COEFFICIENTS ASSUMING A RANDOM WALK | // |---------------------------------------------------------------------------------| // | - init_bounded_vector_vector log_q_devs(1,nItNobs,1,n_it_nobs,-5.1,5.0,q_phz); + init_bounded_vector_vector log_q_devs(1,nItNobs,1,n_it_nobs,-5.0,5.0,q_phz); // |---------------------------------------------------------------------------------| // | CORRELATION COEFFICIENTS FOR AGE COMPOSITION DATA USED IN LOGISTIC NORMAL | @@ -2864,7 +2864,6 @@ FUNCTION calcSurveyObservations qt(kk)(iz) = exp( zt(iz) + log_q_devs(kk)(iz) ); for(ii=iz+1; ii<=nz; ii++) { - COUT(ii); qt(kk)(ii) = qt(kk)(ii-1) * exp(log_q_devs(kk)(ii)); } it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); @@ -2874,13 +2873,12 @@ FUNCTION calcSurveyObservations } // Standardized observation error residuals. - COUT(qt); epsilon(kk).sub(iz,nz) = elem_div(zt,it_log_se(kk)(iz,nz)); // Standardized process error residuals. if(active(log_q_devs(kk))) { - dvar_vector fd_qt = first_difference( log(qt(kk)(iz,nz)) ); + dvar_vector fd_qt = first_difference( log_q_devs(kk)(iz,nz) ); xi(kk).sub(iz,nz-1) = elem_div(fd_qt,it_log_pe(kk)(iz,nz-1)); } @@ -3139,7 +3137,7 @@ FUNCTION calcObjectiveFunction // } // nlvec(2,k)=dnorm(epsilon(k),sig_it); nlvec(2,k)=dnorm(epsilon(k),1.0); - nlvec(2,k)=dnorm(xi(k),1.0); + nlvec(2,k)+=dnorm(xi(k),1.0); } // |---------------------------------------------------------------------------------| From 9cef2267940db6879099bd9126eda5f87d9aff5d Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 10:28:14 -0700 Subject: [PATCH 04/61] Extended nlvec to accomodate process errors in catchability --- src/admb-code/iscam.tpl | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index d63697e1..0466a5d8 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1656,7 +1656,7 @@ PARAMETER_SECTION // | - delta -> residuals between estimated R and R from S-R curve (process err) // | matrix log_rt(1,n_ag,syr-nage+sage,nyr); - matrix nlvec(1,7,1,ilvec); + matrix nlvec(1,8,1,ilvec); matrix epsilon(1,nItNobs,1,n_it_nobs); matrix xi(1,nItNobs,1,n_it_nobs); matrix it_hat(1,nItNobs,1,n_it_nobs); @@ -3079,10 +3079,11 @@ FUNCTION calcObjectiveFunction Likelihoods (nlvec): -1) likelihood of the catch data -2) likelihood of the survey abundance index - -3) likelihood of age composition data - -4) likelihood for stock-recruitment relationship - -5) penalized likelihood for fishery selectivities + -3) likelihood component for random walk in q. + -4) likelihood of age composition data + -5) likelihood for stock-recruitment relationship -6) penalized likelihood for fishery selectivities + -7) penalized likelihood for fishery selectivities TODO list: @@ -3137,7 +3138,7 @@ FUNCTION calcObjectiveFunction // } // nlvec(2,k)=dnorm(epsilon(k),sig_it); nlvec(2,k)=dnorm(epsilon(k),1.0); - nlvec(2,k)+=dnorm(xi(k),1.0); + nlvec(3,k)=dnorm(xi(k),1.0); } // |---------------------------------------------------------------------------------| @@ -3196,19 +3197,19 @@ FUNCTION calcObjectiveFunction switch( int(nCompLikelihood(k)) ) { case 1: - nlvec(3,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); + nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); break; case 2: - nlvec(3,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); + nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); break; case 3: if( !active(log_age_tau2(k)) ) // LN1 Model { - nlvec(3,k) = cLN_Age(); + nlvec(4,k) = cLN_Age(); } else { - nlvec(3,k) = cLN_Age( exp(log_age_tau2(k)) ); + nlvec(4,k) = cLN_Age( exp(log_age_tau2(k)) ); } // Residual @@ -3223,11 +3224,11 @@ FUNCTION calcObjectiveFunction //logistic_normal cLN_Age( O,P,dMinP(k),dEps(k) ); if( active(phi1(k)) && !active(phi2(k)) ) // LN2 Model { - nlvec(3,k) = cLN_Age(exp(log_age_tau2(k)),phi1(k)); + nlvec(4,k) = cLN_Age(exp(log_age_tau2(k)),phi1(k)); } if( active(phi1(k)) && active(phi2(k)) ) // LN3 Model { - nlvec(3,k) = cLN_Age(exp(log_age_tau2(k)),phi1(k),phi2(k)); + nlvec(4,k) = cLN_Age(exp(log_age_tau2(k)),phi1(k),phi2(k)); } // Residual @@ -3242,11 +3243,11 @@ FUNCTION calcObjectiveFunction case 5: // Logistic-normal with student-t if( !active(log_degrees_of_freedom(k)) ) { - nlvec(3,k) = cLST_Age(); + nlvec(4,k) = cLST_Age(); } else { - nlvec(3,k) = cLST_Age(exp(log_degrees_of_freedom(k))); + nlvec(4,k) = cLST_Age(exp(log_degrees_of_freedom(k))); } // Residual @@ -3257,10 +3258,10 @@ FUNCTION calcObjectiveFunction } break; case 6: // Multinomial with estimated effective sample size. - nlvec(3,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); + nlvec(4,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); break; case 7: // Multivariate-t - nlvec(3,k) = multivariate_t_likelihood(O,P,log_age_tau2(k), + nlvec(4,k) = multivariate_t_likelihood(O,P,log_age_tau2(k), log_degrees_of_freedom(k), phi1(k),nu); age_tau2(k) = exp(value(log_age_tau2(k))); @@ -3292,7 +3293,7 @@ FUNCTION calcObjectiveFunction { for(g=1;g<=ngroup;g++) { - nlvec(4,g) = dnorm(delta(g),sigma_r(g)); + nlvec(5,g) = dnorm(delta(g),sigma_r(g)); } } @@ -3322,12 +3323,12 @@ FUNCTION calcObjectiveFunction { //curvature in selectivity parameters dvar_vector df2 = first_difference(first_difference(log_sel(k)(ig)(i))); - nlvec(5,k) += lambda_1(k)/(nage-sage+1)*df2*df2; + nlvec(6,k) += lambda_1(k)/(nage-sage+1)*df2*df2; //penalty for dome-shapeness for(j=sage;j<=nage-1;j++) if(log_sel(k,ig,i,j)>log_sel(k,ig,i,j+1)) - nlvec(6,k)+=lambda_2(k) + nlvec(7,k)+=lambda_2(k) *square( log_sel(k,ig,i,j)-log_sel(k,ig,i,j+1) ); } } @@ -3348,7 +3349,7 @@ FUNCTION calcObjectiveFunction for(j=sage;j<=nage;j++) { dvar_vector df2 = first_difference(first_difference(trans_log_sel(j))); - nlvec(7,k) += lambda_3(k)/(nage-sage+1)*norm2(df2); + nlvec(8,k) += lambda_3(k)/(nage-sage+1)*norm2(df2); } } } From dad1c07035d17d66474c61ee9f3e88c718e1fb46 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 10:33:11 -0700 Subject: [PATCH 05/61] Time varying q, close #37 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a9e55825..618bc7a4 100644 --- a/README.md +++ b/README.md @@ -279,3 +279,6 @@ _____________________________________________________________ Last changed on: Source code: https://github.com/smartell/iSCAM _____________________________________________________________ + +## Code Changes + - March 30, 2015. Added time varying catchbility options (random walk). From 5dd148fe23ce747951e5fecf63fe54728771ef31 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 10:50:42 -0700 Subject: [PATCH 06/61] Fixed array out of bounds error --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 8 ++-- fba/HALIBUT/DATA/Halibut2014.dat | 50 +++++++++++------------ src/admb-code/iscam.tpl | 31 ++++---------- 3 files changed, 38 insertions(+), 51 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 3bb8bcc6..7507c5ff 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -113,10 +113,10 @@ ## 2 = RANDOM WALK Q (use prior mean & sd for penalized random walk) ## ———————————————————————————————————————————————————————————————————————————————————— ## 2 # -number of surveys (n_it_nobs) -2 2 # -QTYPE (see legend above) -0 0 # -prior log(mean) -0 0 # -prior sd (set to 0 for uniformative prior) -2 2 # -Estimation phase + 1 1 # -QTYPE (see legend above) + 0 0 # -prior log(mean) + 0 0 # -prior sd (set to 0 for uniformative prior) +-2 -2 # -Estimation phase ## ———————————————————————————————————————————————————————————————————————————————————— ## ## diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index e831c7da..9715bca7 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -490,34 +490,34 @@ 2013 179 1 1 1 0 0.017 0.050 0.5 2014 191 1 1 1 0 0.052 0.050 0.5 ## survey_data: - 1977 1.4713 6 1 1 0 0.100 0.050 0.5 - 1978 1.1112 6 1 1 0 0.100 0.050 0.5 - 1980 2.0090 6 1 1 0 0.100 0.050 0.5 - 1981 2.6670 6 1 1 0 0.100 0.050 0.5 + 1977 1.4713 6 1 1 0 0.100 0.010 0.5 + 1978 1.1112 6 1 1 0 0.100 0.010 0.5 + 1980 2.0090 6 1 1 0 0.100 0.010 0.5 + 1981 2.6670 6 1 1 0 0.100 0.010 0.5 1982 2.8739 6 1 1 0 0.100 1.000 0.5 - 1983 2.8816 6 1 1 0 0.100 0.050 0.5 + 1983 2.8816 6 1 1 0 0.100 0.010 0.5 1984 9.3014 6 1 1 0 0.100 1.000 0.5 - 1985 8.9419 6 1 1 0 0.100 0.050 0.5 - 1986 6.2568 6 1 1 0 0.100 0.050 0.5 - 1996 12.8858 6 1 1 0 0.100 0.050 0.5 + 1985 8.9419 6 1 1 0 0.100 0.010 0.5 + 1986 6.2568 6 1 1 0 0.100 0.010 0.5 + 1996 12.8858 6 1 1 0 0.100 0.010 0.5 1997 7.7841 6 1 1 0 0.034 1.000 0.5 - 1998 6.9727 6 1 1 0 0.034 0.050 0.5 - 1999 6.2649 6 1 1 0 0.034 0.050 0.5 - 2000 6.6265 6 1 1 0 0.034 0.050 0.5 - 2001 6.3842 6 1 1 0 0.028 0.050 0.5 - 2002 6.3893 6 1 1 0 0.026 0.050 0.5 - 2003 5.7876 6 1 1 0 0.027 0.050 0.5 - 2004 6.4579 6 1 1 0 0.026 0.050 0.5 - 2005 5.9282 6 1 1 0 0.027 0.050 0.5 - 2006 5.4306 6 1 1 0 0.027 0.050 0.5 - 2007 5.7267 6 1 1 0 0.027 0.050 0.5 - 2008 5.6536 6 1 1 0 0.026 0.050 0.5 - 2009 5.4952 6 1 1 0 0.027 0.050 0.5 - 2010 5.1239 6 1 1 0 0.029 0.050 0.5 - 2011 5.0435 6 1 1 0 0.029 0.050 0.5 - 2012 5.5606 6 1 1 0 0.030 0.050 0.5 - 2013 4.7301 6 1 1 0 0.034 0.100 0.5 - 2014 5.1645 6 1 1 0 0.032 0.100 0.5 + 1998 6.9727 6 1 1 0 0.034 0.010 0.5 + 1999 6.2649 6 1 1 0 0.034 0.010 0.5 + 2000 6.6265 6 1 1 0 0.034 0.010 0.5 + 2001 6.3842 6 1 1 0 0.028 0.010 0.5 + 2002 6.3893 6 1 1 0 0.026 0.010 0.5 + 2003 5.7876 6 1 1 0 0.027 0.010 0.5 + 2004 6.4579 6 1 1 0 0.026 0.010 0.5 + 2005 5.9282 6 1 1 0 0.027 0.010 0.5 + 2006 5.4306 6 1 1 0 0.027 0.010 0.5 + 2007 5.7267 6 1 1 0 0.027 0.010 0.5 + 2008 5.6536 6 1 1 0 0.026 0.010 0.5 + 2009 5.4952 6 1 1 0 0.027 0.010 0.5 + 2010 5.1239 6 1 1 0 0.029 0.010 0.5 + 2011 5.0435 6 1 1 0 0.029 0.010 0.5 + 2012 5.5606 6 1 1 0 0.030 0.010 0.5 + 2013 4.7301 6 1 1 0 0.034 0.010 0.5 + 2014 5.1645 6 1 1 0 0.032 0.010 0.5 ## ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 0466a5d8..66a6aef1 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1292,12 +1292,13 @@ DATA_SECTION // | ilvec[2] -> number of surveys (nItNobs) // | ilvec[3] -> number of age-compisition data sets (nAgears) // | ilvec[4] -> container for recruitment deviations. - ivector ilvec(1,7); + ivector ilvec(1,8); !! ilvec = ngear; !! ilvec(1) = 1; !! ilvec(2) = nItNobs; - !! ilvec(3) = nAgears; - !! ilvec(4) = ngroup; + !! ilvec(3) = nItNobs; + !! ilvec(4) = nAgears; + !! ilvec(5) = ngroup; // |---------------------------------------------------------------------------------| @@ -1409,29 +1410,16 @@ DATA_SECTION // | MANAGEMENT STRATEGY EVALUATION INPUTS // |---------------------------------------------------------------------------------| // | - - - //LOC_CALCS - // ifstream ifile("Halibut2012.mse"); - // if(ifile) - // { - // cout<<"Vader is happy"< Date: Mon, 30 Mar 2015 13:06:18 -0700 Subject: [PATCH 07/61] Control file change --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 7507c5ff..b92d97ab 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -113,10 +113,10 @@ ## 2 = RANDOM WALK Q (use prior mean & sd for penalized random walk) ## ———————————————————————————————————————————————————————————————————————————————————— ## 2 # -number of surveys (n_it_nobs) - 1 1 # -QTYPE (see legend above) + 2 2 # -QTYPE (see legend above) 0 0 # -prior log(mean) 0 0 # -prior sd (set to 0 for uniformative prior) --2 -2 # -Estimation phase + 1 1 # -Estimation phase ## ———————————————————————————————————————————————————————————————————————————————————— ## ## From ad781e430dc81ce46b362fabffabdb9786de0b46 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 14:14:56 -0700 Subject: [PATCH 08/61] added compositionLikelihoods.hpp --- .../include/compositionLikelihoods.hpp | 37 +++++++++++++++++++ src/admb-code/include/lib_iscam.h | 1 + src/admb-code/iscam.tpl | 9 +++-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/admb-code/include/compositionLikelihoods.hpp diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp new file mode 100644 index 00000000..d3f2ed77 --- /dev/null +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -0,0 +1,37 @@ +// compositionLikelihoods.hpp +#include + +#ifndef COMPOSITIONLIKELIHOODS_H +#define COMPOSITIONLIKELIHOODS_H + +/** + * @file compositionLikelihoods.hpp + * @defgroup Likelihoods + * @author Steven Martell + * @namespace acl + * @date Feb 10, 2014 + * @title Selectivity functions + * @details Uses abstract base class for computing negative loglikelihoods + */ +namespace acl +{ + + template + class compositionLikelihoods + { + private: + T m_x; + public: + virtual const T nloglike(const T & x) const = 0; + virtual const T residual(const T & x) const = 0; + virtual ~compositionLikelihoods(){}; + + void set_x(T & x) { this -> m_x = x; } + T get_x() const{ return m_x; } + + }; + + +} + +#endif \ No newline at end of file diff --git a/src/admb-code/include/lib_iscam.h b/src/admb-code/include/lib_iscam.h index 650b961a..600579d5 100644 --- a/src/admb-code/include/lib_iscam.h +++ b/src/admb-code/include/lib_iscam.h @@ -8,6 +8,7 @@ #include "growthModels.hpp" #include "multinomial.h" #include "selex.hpp" +#include "compositionLikelihoods.hpp" #endif \ No newline at end of file diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 66a6aef1..64736891 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2558,9 +2558,9 @@ FUNCTION calcComposition dvar_vector pred_ca = ca * age_age(e); A_hat(kk)(ii) = pred_ca(n_A_sage(kk),n_A_nage(kk)); if( n_A_nage(kk) < nage ) - { - A_hat(kk)(ii)(n_A_nage(kk)) += sum( pred_ca(n_A_nage(kk)+1,nage) ); - } + { + A_hat(kk)(ii)(n_A_nage(kk)) += sum( pred_ca(n_A_nage(kk)+1,nage) ); + } } else { @@ -3167,6 +3167,9 @@ FUNCTION calcObjectiveFunction { O(ii) = d3_A_obs(k)(i).sub(n_A_sage(k),n_A_nage(k)); P(ii) = A_hat(k)(i).sub(n_A_sage(k),n_A_nage(k)); + COUT(O(ii)); + COUT(P(ii)); + exit(1); ii ++; } //if( iyr <= nyr ) naa++; From f262f639f89411434fe5617a126ecc8a61088c97 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 15:29:06 -0700 Subject: [PATCH 09/61] Working on compositionLikelihoods.hpp --- .../include/compositionLikelihoods.hpp | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index d3f2ed77..86f6e2ec 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -20,18 +20,66 @@ namespace acl class compositionLikelihoods { private: - T m_x; + int r1,r2; /// index for first and last row. + int c1,c2; /// index for rist and last column. + ivector m_jmin; /// index for ragged start columns. + ivector m_jmax; /// index for ragged end columns. + + T m_O; /// observed composition object + public: - virtual const T nloglike(const T & x) const = 0; - virtual const T residual(const T & x) const = 0; + virtual const T nloglike(const T & _O) const = 0; + virtual const T residual(const T & _O) const = 0; virtual ~compositionLikelihoods(){}; - void set_x(T & x) { this -> m_x = x; } - T get_x() const{ return m_x; } + void set_O(T & O) { this -> m_O = O; } + T get_O() const{ return m_O; } + void tail_compression_indexes(); }; + void acl::test(); + + + + // |--------------------------------------------------------------------------------| + // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | + // |--------------------------------------------------------------------------------| + template + inline + const T dmvlogistic(const T& O, const T& P) + { + + } + + /** + * @brief Negative loglikelihood for compostion data using multivaritae logistic + * @author Steve Martell + * @param T usually a dmatrix + */ + template + class multivariteLogistic: public compositionLikelihoods + { + private: + T m_P; /// predicted composition object. + + public: + multivariteLogistic(T _P): m_P(_P) {} + + const T nloglike(const T &O) const + { + return acl::dmvlogistic(O, this->get_P()); + } + + T get_P() const {return m_P; } + void set_P(T P) {this->m_P=P;} + + }; + } + + + #endif \ No newline at end of file From 4e0ef7ace34d19292cefebc294cea1e5162c3b79 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 30 Mar 2015 15:40:43 -0700 Subject: [PATCH 10/61] Still working out methods for abstract base class --- .../include/compositionLikelihoods.hpp | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 86f6e2ec..13047e44 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -16,6 +16,12 @@ namespace acl { + /** + * @brief Base class for composition likelihoods. + * @details Virtual methods for negative loglikelihood and standardized residuals. + * + * @tparam T [description] + */ template class compositionLikelihoods { @@ -28,17 +34,35 @@ namespace acl T m_O; /// observed composition object public: + // constructors + compositionLikelihoods(){} + compositionLikelihoods(const T& _O) + :m_O(_O) + { + r1 = m_O.rowmin(); + r2 = m_O.rowmax(); + c1 = m_O.colmin(); + c2 = m_O.colmax(); + } + + // virtual methods + virtual ~compositionLikelihoods(){}; virtual const T nloglike(const T & _O) const = 0; virtual const T residual(const T & _O) const = 0; - virtual ~compositionLikelihoods(){}; + // getters & setters void set_O(T & O) { this -> m_O = O; } T get_O() const{ return m_O; } + // methods void tail_compression_indexes(); + }; - void acl::test(); + // void comtail_compression_indexes() + // { + + // } @@ -64,7 +88,8 @@ namespace acl T m_P; /// predicted composition object. public: - multivariteLogistic(T _P): m_P(_P) {} + multivariteLogistic(T &_O, T &_P) + :compositionLikelihoods(_O),m_P(_P) {} const T nloglike(const T &O) const { From a1113a872c02386ae018e18f92314425d39e6e77 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 09:36:21 -0700 Subject: [PATCH 11/61] Creating DATA and DVAR typenames for composition likelihoods --- .../include/compositionLikelihoods.hpp | 78 ++++++++++++++++--- src/admb-code/iscam.tpl | 14 +++- 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 13047e44..d00ff35e 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -16,6 +16,53 @@ namespace acl { + template + inline + const T tailCompression(const T &_M, const double pmin=0.0) + { + int r1,r2,c1,c2; + r1 = _M.rowmin(); + r2 = _M.rowmax(); + c1 = _M.colmin(); + c2 = _M.colmax(); + + ivector jmin(r1,r2); + ivector jmax(r1,r2); + for(int i = r1; i <= r2; i++ ) + { + auto o = _M(i); + + jmin(i) = c1+1; // index for min column + jmax(i) = c2; // index for max column + auto cumsum = o/sum(o); + for(int j = c1+1; j <= c2; j++ ) + { + cumsum(j) += cumsum(j-1); + cumsum(j) <= pmin ? jmin(i)++ : NULL; + j != c2 ? 1.0 - cumsum(j) < pmin ? jmax(i)-- : NULL : NULL; + } + } + + // Now compress the matrix. + T M_; + T M = _M; + M_.allocate(r1,r2,jmin,jmax); + M_.initialize(); + + // fill ragged array M_ + for(int i = r1; i <= r2; i++ ) + { + M(i) /= sum(M(i)); + M_(i)(jmin(i),jmax(i)) = M(i)(jmin(i),jmax(i)); + + // add cumulative sum to tails. + M_(i)(jmin(i)) = sum(M(i)(c1,jmin(i))); + M_(i)(jmax(i)) = sum(M(i)(jmax(i),c2)); + } + return M_; + + } + /** * @brief Base class for composition likelihoods. * @details Virtual methods for negative loglikelihood and standardized residuals. @@ -53,19 +100,11 @@ namespace acl // getters & setters void set_O(T & O) { this -> m_O = O; } T get_O() const{ return m_O; } - - // methods - void tail_compression_indexes(); - + }; - // void comtail_compression_indexes() - // { - - // } - // |--------------------------------------------------------------------------------| // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | // |--------------------------------------------------------------------------------| @@ -73,7 +112,16 @@ namespace acl inline const T dmvlogistic(const T& O, const T& P) { + T nll; + return nll; + } + template + inline + const T dmvlogisticResidual(const T& O, const T& P) + { + T nu; + return nu; } /** @@ -81,20 +129,26 @@ namespace acl * @author Steve Martell * @param T usually a dmatrix */ - template + template class multivariteLogistic: public compositionLikelihoods { private: T m_P; /// predicted composition object. public: - multivariteLogistic(T &_O, T &_P) - :compositionLikelihoods(_O),m_P(_P) {} + multivariteLogistic(const DATA &_O, const DVAR &_P) + :compositionLikelihoods(_O),m_P(_P) {} const T nloglike(const T &O) const { + T rO = tailCompression(O); return acl::dmvlogistic(O, this->get_P()); } + + const T residual(const T &O) const + { + return acl::dmvlogisticResidual(O, this->get_P()); + } T get_P() const {return m_P; } void set_P(T P) {this->m_P=P;} diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 64736891..dccf4b96 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3144,6 +3144,15 @@ FUNCTION calcObjectiveFunction // | TODO: // | [ ] - change A_nu to data-type variable, does not need to be differentiable. // | [ ] - issue 29. Fix submatrix O, P for prospective analysis & sex/area/group. + + // Testing new abstract compositionLikelihood class. + + acl::compositionLikelihoods *ptr_AgeCompLike; + + + // delete *ptr_AgeComeLike; + + A_nu.initialize(); for(k=1;k<=nAgears;k++) { @@ -3167,14 +3176,13 @@ FUNCTION calcObjectiveFunction { O(ii) = d3_A_obs(k)(i).sub(n_A_sage(k),n_A_nage(k)); P(ii) = A_hat(k)(i).sub(n_A_sage(k),n_A_nage(k)); - COUT(O(ii)); - COUT(P(ii)); - exit(1); ii ++; } //if( iyr <= nyr ) naa++; //if( iyr < syr ) iaa++; } + ptr_AgeCompLike = new acl::multivariteLogistic(O,P); + dvar_matrix ell = ptr_AgeCompLike->nloglike(P); //dmatrix O = trans(trans(d3_A_obs(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); //dvar_matrix P = trans(trans(A_hat(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); From 72e61cdb58278e1b845c982b2693952a2ccede92 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 11:25:49 -0700 Subject: [PATCH 12/61] Still developing negLogLikelihood abstract class --- .../include/compositionLikelihoods.hpp | 220 +++++++++++------- src/admb-code/iscam.tpl | 6 +- 2 files changed, 145 insertions(+), 81 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index d00ff35e..d6946a35 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -1,11 +1,11 @@ -// compositionLikelihoods.hpp +// negLogLikelihood.hpp #include -#ifndef COMPOSITIONLIKELIHOODS_H -#define COMPOSITIONLIKELIHOODS_H +#ifndef negLogLikelihood_H +#define negLogLikelihood_H /** - * @file compositionLikelihoods.hpp + * @file negLogLikelihood.hpp * @defgroup Likelihoods * @author Steven Martell * @namespace acl @@ -16,61 +16,62 @@ namespace acl { - template - inline - const T tailCompression(const T &_M, const double pmin=0.0) - { - int r1,r2,c1,c2; - r1 = _M.rowmin(); - r2 = _M.rowmax(); - c1 = _M.colmin(); - c2 = _M.colmax(); - - ivector jmin(r1,r2); - ivector jmax(r1,r2); - for(int i = r1; i <= r2; i++ ) - { - auto o = _M(i); - - jmin(i) = c1+1; // index for min column - jmax(i) = c2; // index for max column - auto cumsum = o/sum(o); - for(int j = c1+1; j <= c2; j++ ) - { - cumsum(j) += cumsum(j-1); - cumsum(j) <= pmin ? jmin(i)++ : NULL; - j != c2 ? 1.0 - cumsum(j) < pmin ? jmax(i)-- : NULL : NULL; - } - } - - // Now compress the matrix. - T M_; - T M = _M; - M_.allocate(r1,r2,jmin,jmax); - M_.initialize(); - - // fill ragged array M_ - for(int i = r1; i <= r2; i++ ) - { - M(i) /= sum(M(i)); - M_(i)(jmin(i),jmax(i)) = M(i)(jmin(i),jmax(i)); - - // add cumulative sum to tails. - M_(i)(jmin(i)) = sum(M(i)(c1,jmin(i))); - M_(i)(jmax(i)) = sum(M(i)(jmax(i),c2)); - } - return M_; - - } + // template + // inline + // const T tailCompression(const T &_M, const double pmin=0.0) + // { + // int r1,r2,c1,c2; + // r1 = _M.rowmin(); + // r2 = _M.rowmax(); + // c1 = _M.colmin(); + // c2 = _M.colmax(); + + // ivector jmin(r1,r2); + // ivector jmax(r1,r2); + // for(int i = r1; i <= r2; i++ ) + // { + // auto o = _M(i); + + // jmin(i) = c1+1; // index for min column + // jmax(i) = c2; // index for max column + // auto cumsum = o/sum(o); + // for(int j = c1+1; j <= c2; j++ ) + // { + // cumsum(j) += cumsum(j-1); + // cumsum(j) <= pmin ? jmin(i)++ : NULL; + // j != c2 ? 1.0 - cumsum(j) < pmin ? jmax(i)-- : NULL : NULL; + // } + // } + + // // Now compress the matrix. + // T M_; + // T M = _M; + // M_.allocate(r1,r2,jmin,jmax); + // M_.initialize(); + + // // fill ragged array M_ + // for(int i = r1; i <= r2; i++ ) + // { + // M(i) /= sum(M(i)); + // M_(i)(jmin(i),jmax(i)) = M(i)(jmin(i),jmax(i)); + + // // add cumulative sum to tails. + // M_(i)(jmin(i)) = sum(M(i)(c1,jmin(i))); + // M_(i)(jmax(i)) = sum(M(i)(jmax(i),c2)); + // } + // return M_; + + // } /** * @brief Base class for composition likelihoods. * @details Virtual methods for negative loglikelihood and standardized residuals. * - * @tparam T [description] + * @tparam DATA Data type argument. + * @tparam DVAR Variable type argument. */ - template - class compositionLikelihoods + template + class negLogLikelihood { private: int r1,r2; /// index for first and last row. @@ -78,49 +79,111 @@ namespace acl ivector m_jmin; /// index for ragged start columns. ivector m_jmax; /// index for ragged end columns. - T m_O; /// observed composition object + DATA m_O; /// observed composition object public: // constructors - compositionLikelihoods(){} - compositionLikelihoods(const T& _O) + negLogLikelihood(){} + negLogLikelihood(const DATA& _O) :m_O(_O) { r1 = m_O.rowmin(); r2 = m_O.rowmax(); c1 = m_O.colmin(); c2 = m_O.colmax(); + + getRaggedVectors(); } - // virtual methods - virtual ~compositionLikelihoods(){}; - virtual const T nloglike(const T & _O) const = 0; - virtual const T residual(const T & _O) const = 0; + // pure virtual methods + virtual ~negLogLikelihood(){}; + virtual const DVAR nloglike(const DVAR & _P) const = 0; + virtual const DVAR residual(const DVAR & _P) const = 0; + // virtual methods + inline + const DATA tailCompression(const DATA &_M) const; + + // methods + inline + void getRaggedVectors(double pmin = 0.0); + // getters & setters - void set_O(T & O) { this -> m_O = O; } - T get_O() const{ return m_O; } + void set_O(DATA & O) { this -> m_O = O; } + DATA get_O() const{ return m_O; } }; + template + inline + const DATA acl::negLogLikelihood::tailCompression(const DATA &_M) const + { + DATA R; + DATA M; + R.allocate(r1,r2,m_jmin,m_jmax); + R.initialize(); + // fill ragged array R + for(int i = r1; i <= r2; i++ ) + { + M(i) /= sum(M(i)); + R(i)(m_jmin(i),m_jmax(i)) = M(i)(m_jmin(i),m_jmax(i)); + + // add cumulative sum to tails. + R(i)(m_jmin(i)) = sum(M(i)(c1,m_jmin(i))); + R(i)(m_jmax(i)) = sum(M(i)(m_jmax(i),c2)); + } + return R; + } + + /** + * @brief Get column indicies for each row to compress matrix into ragged array. + * @details Determine the start and end positions of each row in which to compute + * the likelihoods where values < pmin are pooled into the tails of the distribution. + * + * @param pmin value to assume for the minium proportion. + * @return NULL Modifies private member variables: m_jmin and m_jmax. + */ + template + inline + void acl::negLogLikelihood::getRaggedVectors(double pmin) + { + m_jmin.allocate(r1,r2); + m_jmax.allocate(r1,r2); + + for(int i = r1; i <= r2; i++ ) + { + dvector o = m_O(i); + + m_jmin(i) = c1+1; // index for min column + m_jmax(i) = c2; // index for max column + dvector cumsum = o/sum(o); + for(int j = c1+1; j <= c2; j++ ) + { + cumsum(j) += cumsum(j-1); + cumsum(j) <= pmin ? m_jmin(i)++ : NULL; + j != c2 ? 1.0 - cumsum(j) < pmin ? m_jmax(i)-- : NULL : NULL; + } + } + + } // |--------------------------------------------------------------------------------| // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | // |--------------------------------------------------------------------------------| - template + template inline - const T dmvlogistic(const T& O, const T& P) + const DVAR dmvlogistic(const DATA& O, const DVAR& P) { - T nll; + DVAR nll; return nll; } - template + template inline - const T dmvlogisticResidual(const T& O, const T& P) + const DVAR dmvlogisticResidual(const DATA& O, const DVAR& P) { - T nu; + DVAR nu; return nu; } @@ -130,28 +193,29 @@ namespace acl * @param T usually a dmatrix */ template - class multivariteLogistic: public compositionLikelihoods + class multivariteLogistic: public negLogLikelihood { private: - T m_P; /// predicted composition object. + DVAR m_P; /// predicted composition object. public: + // constructor multivariteLogistic(const DATA &_O, const DVAR &_P) - :compositionLikelihoods(_O),m_P(_P) {} + :negLogLikelihood(_O),m_P(_P) {} - const T nloglike(const T &O) const + const DVAR nloglike(const DVAR &P) const { - T rO = tailCompression(O); - return acl::dmvlogistic(O, this->get_P()); + //DATA rO = tailCompression(this->get_O); + return acl::dmvlogistic(this->get_O(), this->get_P()); } - const T residual(const T &O) const + const DVAR residual(const DVAR &P) const { - return acl::dmvlogisticResidual(O, this->get_P()); + return acl::dmvlogisticResidual(this->get_O(), this->get_P()); } - T get_P() const {return m_P; } - void set_P(T P) {this->m_P=P;} + DVAR get_P() const {return m_P; } + void set_P(DVAR P) {this->m_P=P;} }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index dccf4b96..4154e837 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3147,7 +3147,7 @@ FUNCTION calcObjectiveFunction // Testing new abstract compositionLikelihood class. - acl::compositionLikelihoods *ptr_AgeCompLike; + acl::negLogLikelihood *ptr_AgeCompLike; // delete *ptr_AgeComeLike; @@ -3181,8 +3181,8 @@ FUNCTION calcObjectiveFunction //if( iyr <= nyr ) naa++; //if( iyr < syr ) iaa++; } - ptr_AgeCompLike = new acl::multivariteLogistic(O,P); - dvar_matrix ell = ptr_AgeCompLike->nloglike(P); + ptr_AgeCompLike = new acl::multivariteLogistic(O,P); + //dvar_matrix ell = ptr_AgeCompLike->nloglike(P); //dmatrix O = trans(trans(d3_A_obs(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); //dvar_matrix P = trans(trans(A_hat(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); From 6602b5577bdbc1d559cd076362fd481a4f4e1697 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 21:16:07 -0700 Subject: [PATCH 13/61] Fixed minor error in getRaggedVectors --- scripts/Template.ctl | 27 +++-- .../include/compositionLikelihoods.hpp | 113 ++++++++++++------ src/admb-code/iscam.tpl | 4 +- 3 files changed, 92 insertions(+), 52 deletions(-) diff --git a/scripts/Template.ctl b/scripts/Template.ctl index bb28e38d..f3ff2643 100644 --- a/scripts/Template.ctl +++ b/scripts/Template.ctl @@ -100,20 +100,23 @@ ## ———————————————————————————————————————————————————————————————————————————————————— ## ## ## -## ------------------------------------------------------------------------- ## -## PRIORS FOR SURVEY Q ## -## Prior type: ## -## 0 - uninformative prior ## -## 1 - normal prior density for log(q) ## -## 2 - random walk in q ## -## ------------------------------------------------------------------------- ## -1 # -number of surveys (nits) -0 # -prior type (see legend above) -0 # -prior log(mean) -0 # -prior sd -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## ABUNDANCE OBSERVATION MODELS +## ———————————————————————————————————————————————————————————————————————————————————— ## +## QTYPE: +## 0 = FIXED SURVEY Q (specify log(mean) for prior log(mean)) +## 1 = CONSTANT Q (use MLE for q and optional informative prior) +## 2 = RANDOM WALK Q (use prior mean & sd for penalized random walk) +## ———————————————————————————————————————————————————————————————————————————————————— ## +1 # -number of surveys (n_it_nobs) + 2 # -QTYPE (see legend above) + 0 # -prior log(mean) + 0 # -prior sd (set to 0 for uniformative prior) + 1 # -Estimation phase +## ———————————————————————————————————————————————————————————————————————————————————— ## ## + ## ------------------------------------------------------------------------- ## ## OTHER MISCELANEOUS CONTROLS ## ## ------------------------------------------------------------------------- ## diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index d6946a35..fa78f89a 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -80,12 +80,13 @@ namespace acl ivector m_jmax; /// index for ragged end columns. DATA m_O; /// observed composition object + DVAR m_P; /// predicted composition object public: // constructors negLogLikelihood(){} - negLogLikelihood(const DATA& _O) - :m_O(_O) + negLogLikelihood(const DATA& _O, const DVAR& _P) + :m_O(_O), m_P(_P) { r1 = m_O.rowmin(); r2 = m_O.rowmax(); @@ -97,12 +98,14 @@ namespace acl // pure virtual methods virtual ~negLogLikelihood(){}; - virtual const DVAR nloglike(const DVAR & _P) const = 0; - virtual const DVAR residual(const DVAR & _P) const = 0; + virtual const dvariable nloglike() const = 0; + virtual const DVAR residual() const = 0; // virtual methods inline const DATA tailCompression(const DATA &_M) const; + // inline + // const DVAR tailCompression(const DVAR &_M) const; // methods inline @@ -111,29 +114,33 @@ namespace acl // getters & setters void set_O(DATA & O) { this -> m_O = O; } DATA get_O() const{ return m_O; } - - }; - template - inline - const DATA acl::negLogLikelihood::tailCompression(const DATA &_M) const - { - DATA R; - DATA M; - R.allocate(r1,r2,m_jmin,m_jmax); - R.initialize(); - // fill ragged array R - for(int i = r1; i <= r2; i++ ) + DVAR get_P() const {return m_P; } + void set_P(DVAR &P) {this->m_P=P;} + + template + inline + const T compress(const T& _M) const { - M(i) /= sum(M(i)); - R(i)(m_jmin(i),m_jmax(i)) = M(i)(m_jmin(i),m_jmax(i)); + T R; + T M = _M; + R.allocate(r1,r2,m_jmin,m_jmax); + R.initialize(); + // fill ragged array R + for(int i = r1; i <= r2; i++ ) + { + M(i) /= sum(M(i)); + R(i)(m_jmin(i),m_jmax(i)) = M(i)(m_jmin(i),m_jmax(i)); - // add cumulative sum to tails. - R(i)(m_jmin(i)) = sum(M(i)(c1,m_jmin(i))); - R(i)(m_jmax(i)) = sum(M(i)(m_jmax(i),c2)); + // add cumulative sum to tails. + R(i)(m_jmin(i)) = sum(M(i)(c1,m_jmin(i))); + R(i)(m_jmax(i)) = sum(M(i)(m_jmax(i),c2)); + } + + return R; } - return R; - } + + }; /** * @brief Get column indicies for each row to compress matrix into ragged array. @@ -154,28 +161,35 @@ namespace acl { dvector o = m_O(i); - m_jmin(i) = c1+1; // index for min column + m_jmin(i) = c1; // index for min column m_jmax(i) = c2; // index for max column dvector cumsum = o/sum(o); - for(int j = c1+1; j <= c2; j++ ) + for(int j = c1; j < c2; j++ ) { - cumsum(j) += cumsum(j-1); cumsum(j) <= pmin ? m_jmin(i)++ : NULL; - j != c2 ? 1.0 - cumsum(j) < pmin ? m_jmax(i)-- : NULL : NULL; + j != c2 ? 1.0 - cumsum(j) <= pmin ? m_jmax(i)-- : NULL : NULL; + + cumsum(j+1) += cumsum(j); } } - } // |--------------------------------------------------------------------------------| // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | // |--------------------------------------------------------------------------------| - template + template inline - const DVAR dmvlogistic(const DATA& O, const DVAR& P) + const T dmvlogistic(const DATA& O, const DVAR& P) { - DVAR nll; + T nll; + // nll.allocate(P); + // int i; + // for( i = O.rowmin(); i<= O.rowmax(); i++) + // { + // nll(i) = log(O(i)) - log(P(i)); + // nll(i) -= mean(nll(i)); + // } return nll; } @@ -184,6 +198,13 @@ namespace acl const DVAR dmvlogisticResidual(const DATA& O, const DVAR& P) { DVAR nu; + nu.allocate(P); + int i; + for( i = O.rowmin(); i<= O.rowmax(); i++) + { + nu(i) = log(O(i)) - log(P(i)); + nu(i) -= mean(nu(i)); + } return nu; } @@ -196,26 +217,40 @@ namespace acl class multivariteLogistic: public negLogLikelihood { private: - DVAR m_P; /// predicted composition object. + DVAR m_rO; /// ragged observed composition object. + DVAR m_rP; /// ragged predicted composition object. + DVAR m_nu; /// logistic residuals. public: // constructor + // todo: add eps value to constructor. multivariteLogistic(const DATA &_O, const DVAR &_P) - :negLogLikelihood(_O),m_P(_P) {} + :negLogLikelihood(_O,_P) + { + DATA tmp = this->compress(this->get_O()); + cout<compress(_P); + // m_nu = acl::dmvlogisticResidual(m_rO,m_rP); + } - const DVAR nloglike(const DVAR &P) const + + const dvariable nloglike() const { - //DATA rO = tailCompression(this->get_O); - return acl::dmvlogistic(this->get_O(), this->get_P()); + // DATA rO = this->compress(this->get_O()); + // DVAR rP = this->compress(this->get_P()); + // m_nu = acl::dmvlogisticResidual(rO,rP); + // return acl::dmvlogistic(rO, rP); + return 0; } - const DVAR residual(const DVAR &P) const + const DVAR residual() const { return acl::dmvlogisticResidual(this->get_O(), this->get_P()); } - DVAR get_P() const {return m_P; } - void set_P(DVAR P) {this->m_P=P;} + + DVAR get_nu() const {return m_nu; } + void set_nu(DVAR &R){this->m_nu=R;} }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 4154e837..590ad0ef 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3182,7 +3182,9 @@ FUNCTION calcObjectiveFunction //if( iyr < syr ) iaa++; } ptr_AgeCompLike = new acl::multivariteLogistic(O,P); - //dvar_matrix ell = ptr_AgeCompLike->nloglike(P); + dvariable ell = ptr_AgeCompLike->nloglike(); + COUT(ell); + //dmatrix O = trans(trans(d3_A_obs(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); //dvar_matrix P = trans(trans(A_hat(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); From 9fc0b0243f83df2d9266ddd7565e66d801197738 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 22:01:37 -0700 Subject: [PATCH 14/61] More progress on the multivariateLogistic derived class --- .../include/compositionLikelihoods.hpp | 54 ++++++++++--------- src/admb-code/iscam.tpl | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index fa78f89a..e8df0747 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -178,19 +178,20 @@ namespace acl // |--------------------------------------------------------------------------------| // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | // |--------------------------------------------------------------------------------| - template + /** + * @brief multivariate logistic negative log likelihood + * @details The negative log likeihood for the multivariate + * logistic distribution based on the MLE of the variance. + * + * @param NU Matrix of residuals + * @return the negative loglikelihood + */ + template inline - const T dmvlogistic(const DATA& O, const DVAR& P) + const T dmvlogistic(const DVAR& NU) { - T nll; - // nll.allocate(P); - // int i; - // for( i = O.rowmin(); i<= O.rowmax(); i++) - // { - // nll(i) = log(O(i)) - log(P(i)); - // nll(i) -= mean(nll(i)); - // } - return nll; + T var = 1.0/size_count(NU)*norm2(NU); + return size_count(NU) * log(var); } template @@ -213,34 +214,35 @@ namespace acl * @author Steve Martell * @param T usually a dmatrix */ - template + template class multivariteLogistic: public negLogLikelihood { private: - DVAR m_rO; /// ragged observed composition object. + DATA m_rO; /// ragged observed composition object. DVAR m_rP; /// ragged predicted composition object. DVAR m_nu; /// logistic residuals. public: // constructor // todo: add eps value to constructor. - multivariteLogistic(const DATA &_O, const DVAR &_P) + multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=1.e-8) :negLogLikelihood(_O,_P) { + // tail compression DATA tmp = this->compress(this->get_O()); - cout<compress(_P); - // m_nu = acl::dmvlogisticResidual(m_rO,m_rP); + set_rO(tmp); + DVAR vmp = this->compress(this->get_P()); + set_rP(vmp); + + // residuals + DVAR tnu = acl::dmvlogisticResidual(this->get_rO(),this->get_rP()); + set_nu(tnu); } - const dvariable nloglike() const + const T nloglike() const { - // DATA rO = this->compress(this->get_O()); - // DVAR rP = this->compress(this->get_P()); - // m_nu = acl::dmvlogisticResidual(rO,rP); - // return acl::dmvlogistic(rO, rP); - return 0; + return acl::dmvlogistic(this->get_nu()); } const DVAR residual() const @@ -248,8 +250,12 @@ namespace acl return acl::dmvlogisticResidual(this->get_O(), this->get_P()); } - + DATA get_rO() const {return m_rO; } + DVAR get_rP() const {return m_rP; } DVAR get_nu() const {return m_nu; } + + void set_rO(DATA &X){this->m_rO=X;} + void set_rP(DVAR &X){this->m_rP=X;} void set_nu(DVAR &R){this->m_nu=R;} }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 590ad0ef..564d8948 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3181,7 +3181,7 @@ FUNCTION calcObjectiveFunction //if( iyr <= nyr ) naa++; //if( iyr < syr ) iaa++; } - ptr_AgeCompLike = new acl::multivariteLogistic(O,P); + ptr_AgeCompLike = new acl::multivariteLogistic(O,P); dvariable ell = ptr_AgeCompLike->nloglike(); COUT(ell); From c1843f361cf48f200a93fc9bf346717d523afddd Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 22:03:11 -0700 Subject: [PATCH 15/61] More progress on the multivariateLogistic derived class --- src/admb-code/include/compositionLikelihoods.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index e8df0747..2a881be9 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -230,9 +230,10 @@ namespace acl { // tail compression DATA tmp = this->compress(this->get_O()); - set_rO(tmp); + set_rO(tmp+eps); DVAR vmp = this->compress(this->get_P()); - set_rP(vmp); + set_rP(vmp+eps); + // residuals DVAR tnu = acl::dmvlogisticResidual(this->get_rO(),this->get_rP()); From 689b828a0babf3237320e7fd98cf025922955d82 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 22:04:45 -0700 Subject: [PATCH 16/61] Now have an actual likelihood from the derived class multivariateLogistic --- src/admb-code/include/compositionLikelihoods.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 2a881be9..a486b7e2 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -229,10 +229,10 @@ namespace acl :negLogLikelihood(_O,_P) { // tail compression - DATA tmp = this->compress(this->get_O()); - set_rO(tmp+eps); - DVAR vmp = this->compress(this->get_P()); - set_rP(vmp+eps); + DATA tmp = this->compress(this->get_O()) + eps; + set_rO(tmp); + DVAR vmp = this->compress(this->get_P()) + eps; + set_rP(vmp); // residuals From f2c99bcc78308c34bee82398739e27c33c84b8b3 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Tue, 31 Mar 2015 22:36:20 -0700 Subject: [PATCH 17/61] removed old code --- .../include/compositionLikelihoods.hpp | 49 +------------------ src/admb-code/iscam.tpl | 3 +- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index a486b7e2..b229f820 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -16,53 +16,6 @@ namespace acl { - // template - // inline - // const T tailCompression(const T &_M, const double pmin=0.0) - // { - // int r1,r2,c1,c2; - // r1 = _M.rowmin(); - // r2 = _M.rowmax(); - // c1 = _M.colmin(); - // c2 = _M.colmax(); - - // ivector jmin(r1,r2); - // ivector jmax(r1,r2); - // for(int i = r1; i <= r2; i++ ) - // { - // auto o = _M(i); - - // jmin(i) = c1+1; // index for min column - // jmax(i) = c2; // index for max column - // auto cumsum = o/sum(o); - // for(int j = c1+1; j <= c2; j++ ) - // { - // cumsum(j) += cumsum(j-1); - // cumsum(j) <= pmin ? jmin(i)++ : NULL; - // j != c2 ? 1.0 - cumsum(j) < pmin ? jmax(i)-- : NULL : NULL; - // } - // } - - // // Now compress the matrix. - // T M_; - // T M = _M; - // M_.allocate(r1,r2,jmin,jmax); - // M_.initialize(); - - // // fill ragged array M_ - // for(int i = r1; i <= r2; i++ ) - // { - // M(i) /= sum(M(i)); - // M_(i)(jmin(i),jmax(i)) = M(i)(jmin(i),jmax(i)); - - // // add cumulative sum to tails. - // M_(i)(jmin(i)) = sum(M(i)(c1,jmin(i))); - // M_(i)(jmax(i)) = sum(M(i)(jmax(i),c2)); - // } - // return M_; - - // } - /** * @brief Base class for composition likelihoods. * @details Virtual methods for negative loglikelihood and standardized residuals. @@ -248,7 +201,7 @@ namespace acl const DVAR residual() const { - return acl::dmvlogisticResidual(this->get_O(), this->get_P()); + return this->get_nu(); } DATA get_rO() const {return m_rO; } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 564d8948..64afce75 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3183,7 +3183,7 @@ FUNCTION calcObjectiveFunction } ptr_AgeCompLike = new acl::multivariteLogistic(O,P); dvariable ell = ptr_AgeCompLike->nloglike(); - COUT(ell); + //COUT(ell); //dmatrix O = trans(trans(d3_A_obs(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); @@ -3198,6 +3198,7 @@ FUNCTION calcObjectiveFunction { case 1: nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); + cout<<"like: "< Date: Wed, 1 Apr 2015 14:22:17 -0700 Subject: [PATCH 18/61] Have aggregation working for dmvlogistic and abstract base class, results are not the same however --- .../include/compositionLikelihoods.hpp | 98 ++++++++++++++++--- src/admb-code/iscam.tpl | 2 +- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index b229f820..20645429 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -31,9 +31,14 @@ namespace acl int c1,c2; /// index for rist and last column. ivector m_jmin; /// index for ragged start columns. ivector m_jmax; /// index for ragged end columns. + imatrix m_jagg; /// index for aggregation among bins. DATA m_O; /// observed composition object + DATA m_rO; /// observed ragged composition object + DVAR m_P; /// predicted composition object + DVAR m_rP; /// predicted ragged composition object + public: // constructors @@ -57,13 +62,14 @@ namespace acl // virtual methods inline const DATA tailCompression(const DATA &_M) const; - // inline - // const DVAR tailCompression(const DVAR &_M) const; - + // methods inline void getRaggedVectors(double pmin = 0.0); + inline + void aggregate(const double pmin = 0.0); + // getters & setters void set_O(DATA & O) { this -> m_O = O; } DATA get_O() const{ return m_O; } @@ -71,6 +77,13 @@ namespace acl DVAR get_P() const {return m_P; } void set_P(DVAR &P) {this->m_P=P;} + DATA get_rO() const {return m_rO; } + void set_rO(DATA &X){this->m_rO=X;} + + DVAR get_rP() const {return m_rP; } + void set_rP(DVAR &X){this->m_rP=X;} + + template inline const T compress(const T& _M) const @@ -95,6 +108,44 @@ namespace acl }; + template + inline + void acl::negLogLikelihood::aggregate(const double pmin) + { + m_jmin.allocate(r1,r2); + m_jmax.allocate(r1,r2); + ivector n(r1,r2); + n.initialize(); + + // get number of observations > pmin each year. + for(int i = r1; i <= r2; i++ ) + { + dvector oo = m_O(i)/sum(m_O(i)); + for(int j = c1; j <= c2; j++ ) + { + if( oo(j) > pmin ) n(i)++; + } + } + + m_rO.allocate(r1,r2,1,n); + m_rP.allocate(r1,r2,1,n); + m_rO.initialize(); + m_rP.initialize(); + + for(int i = r1; i <= r2; i++ ) + { + int k = 1; + dvector oo = m_O(i)/sum(m_O(i)); + dvar_vector pp = m_P(i)/sum(m_P(i)); + for(int j = c1; j <= c2; j++ ) + { + m_rO(i)(k) += oo(j); + m_rP(i)(k) += pp(j); + if( oo(j)>pmin && k pmin ? n(i)++ : NULL; } } + } + + + + + + + + + + + + + + // |--------------------------------------------------------------------------------| // | MULTIVARIATE LOGISTIC NEGATIVE LOGLIKELIHOOD derived class | // |--------------------------------------------------------------------------------| + /** * @brief multivariate logistic negative log likelihood * @details The negative log likeihood for the multivariate @@ -178,19 +247,22 @@ namespace acl public: // constructor // todo: add eps value to constructor. - multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=1.e-8) + multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=1.e-3) :negLogLikelihood(_O,_P) { // tail compression DATA tmp = this->compress(this->get_O()) + eps; - set_rO(tmp); + this->set_rO(tmp); DVAR vmp = this->compress(this->get_P()) + eps; - set_rP(vmp); + this->set_rP(vmp); + // residuals + this->aggregate(eps); DVAR tnu = acl::dmvlogisticResidual(this->get_rO(),this->get_rP()); set_nu(tnu); + } @@ -204,12 +276,8 @@ namespace acl return this->get_nu(); } - DATA get_rO() const {return m_rO; } - DVAR get_rP() const {return m_rP; } DVAR get_nu() const {return m_nu; } - void set_rO(DATA &X){this->m_rO=X;} - void set_rP(DVAR &X){this->m_rP=X;} void set_nu(DVAR &R){this->m_nu=R;} }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 64afce75..04566ac8 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3181,7 +3181,7 @@ FUNCTION calcObjectiveFunction //if( iyr <= nyr ) naa++; //if( iyr < syr ) iaa++; } - ptr_AgeCompLike = new acl::multivariteLogistic(O,P); + ptr_AgeCompLike = new acl::multivariteLogistic(O,P,dMinP(k)); dvariable ell = ptr_AgeCompLike->nloglike(); //COUT(ell); From b8a9d8af818ee53b641172cc6b3ad5ffc2c38cf0 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Wed, 1 Apr 2015 14:27:02 -0700 Subject: [PATCH 19/61] Now have multivariateLogistic producing the same results with aggregation method --- src/admb-code/include/compositionLikelihoods.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 20645429..185a7e82 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -212,8 +212,9 @@ namespace acl inline const T dmvlogistic(const DVAR& NU) { - T var = 1.0/size_count(NU)*norm2(NU); - return size_count(NU) * log(var); + int n = size_count(NU) - (NU.rowmax()-NU.rowmin()+1); + T var = 1.0/n * norm2(NU); + return n * log(var); } template From d7db4093f41cc1eb418b215b60fb3208ef40a47b Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Wed, 1 Apr 2015 14:33:33 -0700 Subject: [PATCH 20/61] Commented out COUT statements from debugging --- src/admb-code/include/compositionLikelihoods.hpp | 1 + src/admb-code/iscam.tpl | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 185a7e82..8c510356 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -12,6 +12,7 @@ * @date Feb 10, 2014 * @title Selectivity functions * @details Uses abstract base class for computing negative loglikelihoods + * TODO: Still need to fix templates so it works with df1b2variables. */ namespace acl { diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 04566ac8..48c82270 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3181,9 +3181,9 @@ FUNCTION calcObjectiveFunction //if( iyr <= nyr ) naa++; //if( iyr < syr ) iaa++; } - ptr_AgeCompLike = new acl::multivariteLogistic(O,P,dMinP(k)); - dvariable ell = ptr_AgeCompLike->nloglike(); - //COUT(ell); + + + //dmatrix O = trans(trans(d3_A_obs(k)).sub(n_A_sage(k),n_A_nage(k))).sub(iaa,naa); @@ -3197,8 +3197,10 @@ FUNCTION calcObjectiveFunction switch( int(nCompLikelihood(k)) ) { case 1: - nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); - cout<<"like: "<(O,P,dMinP(k)); + nlvec(4,k) = ptr_AgeCompLike->nloglike(); break; case 2: nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); From 3fe5a26175ae44e63d35c770f8fea575a661bb59 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Wed, 1 Apr 2015 21:02:15 -0700 Subject: [PATCH 21/61] tsting multivariateLogistic, need to fix bug in residuals. --- src/R/lib/plotAgeComps.R | 8 ++++---- src/admb-code/include/compositionLikelihoods.hpp | 2 ++ src/admb-code/iscam.tpl | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index f6dbf33b..5b12f99b 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -55,7 +55,7 @@ require(reshape2) p <- ggplot(mdf,aes(factor(Year),variable,col=factor(sign(value)),size=abs(value))) p <- p + geom_point(alpha=0.75) - p <- p + scale_size_area(max_size=6) + p <- p + scale_size_area(max_size=10) p <- p + labs(x="Year",y="Age",size="Residual",colour="Sign") p <- p + facet_wrap(~Model+Sex+Gear,scales="free") print(p + .THEME) @@ -76,19 +76,19 @@ require(reshape2) A <- data.frame(A) A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) agA <- aggregate(A[,-1:-6],by=list(A[,2],A[,3],A[,4],A[,5]),FUN=mean,na.rm=TRUE) - colnames(agA) = c("Gear","Area","Group","Sex",paste(age)) + colnames(agA) = c("Gear","Area","Group","Sex","Err",paste(age)) # Observed data O <- data.frame(M[[i]]$d3_A) O[,-1:-6] <- O[,-1:-6]/rowSums(O[,-1:-6],na.rm=TRUE) agO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],A[,4],O[,5]),FUN=mean,na.rm=TRUE) - colnames(agO) = c("Gear","Area","Group","Sex",paste(age)) + colnames(agO) = c("Gear","Area","Group","Sex","Err",paste(age)) # Create data frame df <- rbind(cbind(type="Predicted",agA),cbind(type="Observed",agO)) # year gear area group sex df <- data.frame(Model=names(M)[i],df) - colnames(df) <- c("Model","Type","Gear","Area","Group","Sex",paste(age)) + colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","Err",paste(age)) mdf <- rbind(mdf,df) } mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex")) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 8c510356..a9ba8cfb 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -275,6 +275,8 @@ namespace acl const DVAR residual() const { + // This should return the residuals for the original container. + // Not the residuals for the ragged object. return this->get_nu(); } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 48c82270..beaf401e 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3200,7 +3200,8 @@ FUNCTION calcObjectiveFunction //nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); //cout<<"like: "<(O,P,dMinP(k)); - nlvec(4,k) = ptr_AgeCompLike->nloglike(); + nlvec(4,k) = ptr_AgeCompLike -> nloglike(); + nu = ptr_AgeCompLike -> residual(); break; case 2: nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); From 2ba25e2de3bead03a8a90e19ff260fc053678634 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Thu, 2 Apr 2015 10:49:53 -0700 Subject: [PATCH 22/61] Deleted pointer for age comps likelihoods --- src/R/lib/plotAgeComps.R | 6 ++-- .../include/compositionLikelihoods.hpp | 32 ++++++++++++++----- src/admb-code/iscam.tpl | 5 ++- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 5b12f99b..50b39ea7 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -75,13 +75,13 @@ require(reshape2) A <- cbind(M[[i]]$d3_A[,1:6],M[[i]]$A_hat) A <- data.frame(A) A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) - agA <- aggregate(A[,-1:-6],by=list(A[,2],A[,3],A[,4],A[,5]),FUN=mean,na.rm=TRUE) + agA <- aggregate(A[,-1:-6],by=list(A[,2],A[,3],A[,4],A[,5],A[,6]),FUN=mean,na.rm=TRUE) colnames(agA) = c("Gear","Area","Group","Sex","Err",paste(age)) # Observed data O <- data.frame(M[[i]]$d3_A) O[,-1:-6] <- O[,-1:-6]/rowSums(O[,-1:-6],na.rm=TRUE) - agO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],A[,4],O[,5]),FUN=mean,na.rm=TRUE) + agO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],A[,4],O[,5],O[,6]),FUN=mean,na.rm=TRUE) colnames(agO) = c("Gear","Area","Group","Sex","Err",paste(age)) # Create data frame @@ -91,7 +91,7 @@ require(reshape2) colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","Err",paste(age)) mdf <- rbind(mdf,df) } - mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex")) + mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex","Err")) print(head(mdf,3)) p <- ggplot( mdf,aes(variable,value,col=Type) ) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index a9ba8cfb..0a3901e7 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -39,7 +39,7 @@ namespace acl DVAR m_P; /// predicted composition object DVAR m_rP; /// predicted ragged composition object - + public: // constructors @@ -84,6 +84,7 @@ namespace acl DVAR get_rP() const {return m_rP; } void set_rP(DVAR &X){this->m_rP=X;} + imatrix get_jagg() const {return m_jagg;} template inline @@ -130,8 +131,10 @@ namespace acl m_rO.allocate(r1,r2,1,n); m_rP.allocate(r1,r2,1,n); + m_jagg.allocate(r1,r2,1,n); m_rO.initialize(); m_rP.initialize(); + m_jagg.initialize(); for(int i = r1; i <= r2; i++ ) { @@ -142,9 +145,11 @@ namespace acl { m_rO(i)(k) += oo(j); m_rP(i)(k) += pp(j); + if(k<=n(i)) m_jagg(i,k) = j; if( oo(j)>pmin && k { private: - DATA m_rO; /// ragged observed composition object. - DVAR m_rP; /// ragged predicted composition object. - DVAR m_nu; /// logistic residuals. + + DVAR m_nu; /// logistic residuals based on ragged object. + DVAR m_NU; /// residuals for rectangular matrix public: // constructor - // todo: add eps value to constructor. multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=1.e-3) :negLogLikelihood(_O,_P) { @@ -259,12 +263,22 @@ namespace acl this->set_rP(vmp); - // residuals this->aggregate(eps); DVAR tnu = acl::dmvlogisticResidual(this->get_rO(),this->get_rP()); set_nu(tnu); + m_NU.allocate(_P); + m_NU.initialize(); + imatrix idx = this->get_jagg(); + for(int i = _O.rowmin(); i <= _O.rowmax(); i++ ) + { + for(int j = 1; j <= size_count(m_nu(i)); j++ ) + { + int jj = idx(i,j); /* code */ + m_NU(i)(jj) = m_nu(i)(j); + } + } } @@ -277,13 +291,15 @@ namespace acl { // This should return the residuals for the original container. // Not the residuals for the ragged object. - return this->get_nu(); + + return this->get_NU(); } DVAR get_nu() const {return m_nu; } - + DVAR get_NU() const {return m_NU; } void set_nu(DVAR &R){this->m_nu=R;} + }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index beaf401e..c6eabaee 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3150,7 +3150,7 @@ FUNCTION calcObjectiveFunction acl::negLogLikelihood *ptr_AgeCompLike; - // delete *ptr_AgeComeLike; + A_nu.initialize(); @@ -3202,6 +3202,7 @@ FUNCTION calcObjectiveFunction ptr_AgeCompLike = new acl::multivariteLogistic(O,P,dMinP(k)); nlvec(4,k) = ptr_AgeCompLike -> nloglike(); nu = ptr_AgeCompLike -> residual(); + break; case 2: nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); @@ -3288,6 +3289,8 @@ FUNCTION calcObjectiveFunction } } } + delete ptr_AgeCompLike; + // |---------------------------------------------------------------------------------| // | STOCK-RECRUITMENT LIKELIHOOD COMPONENT From 91a2bfdc509e4755864ee74f1e1b8d15db00c6ea Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Thu, 2 Apr 2015 16:22:16 -0700 Subject: [PATCH 23/61] Started multinomial base class --- .../include/compositionLikelihoods.hpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 0a3901e7..be56ebc2 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -253,7 +253,7 @@ namespace acl public: // constructor - multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=1.e-3) + multivariteLogistic(const DATA &_O, const DVAR &_P, const double eps=0) :negLogLikelihood(_O,_P) { // tail compression @@ -268,6 +268,7 @@ namespace acl DVAR tnu = acl::dmvlogisticResidual(this->get_rO(),this->get_rP()); set_nu(tnu); + // residuals to return. m_NU.allocate(_P); m_NU.initialize(); imatrix idx = this->get_jagg(); @@ -303,6 +304,24 @@ namespace acl }; + // |-------------------------------------------------------------------------------| + // | MULTINOMIAL DISTRIBUTION | + // |-------------------------------------------------------------------------------| + + template + class multinomial: public negLogLikelihood + { + public: + // constructor + multinomial(const DATA &_O, const DVAR &_P, const double eps=0) + :negLogLikelihood(_O,_P) + { + + } + + + }; + } From 5ea1ad6bf65918520a4626b0609ec309551963bf Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Thu, 2 Apr 2015 16:23:04 -0700 Subject: [PATCH 24/61] Started multinomial base class --- src/admb-code/include/compositionLikelihoods.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index be56ebc2..bd65d383 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -319,7 +319,15 @@ namespace acl } + const T nloglike() const + { + return 0; + } + const DVAR residual() const + { + return 0; + } }; } From e966ce64d84d06776533a172f890b0688081b5d5 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Thu, 2 Apr 2015 21:00:22 -0700 Subject: [PATCH 25/61] Appear to have multinomial working. But still needs testing. --- .../include/compositionLikelihoods.hpp | 103 ++++++++++++++++-- src/admb-code/iscam.tpl | 8 +- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index bd65d383..c8196a78 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -118,14 +118,17 @@ namespace acl m_jmax.allocate(r1,r2); ivector n(r1,r2); n.initialize(); + DATA oo(r1,r2,c1,c2); + DVAR pp(r1,r2,c1,c2); // get number of observations > pmin each year. for(int i = r1; i <= r2; i++ ) { - dvector oo = m_O(i)/sum(m_O(i)); + oo(i) = m_O(i)/sum(m_O(i)); + pp(i) = m_P(i)/sum(m_P(i)); for(int j = c1; j <= c2; j++ ) { - if( oo(j) > pmin ) n(i)++; + if( oo(i)(j) > pmin ) n(i)++; } } @@ -139,14 +142,12 @@ namespace acl for(int i = r1; i <= r2; i++ ) { int k = 1; - dvector oo = m_O(i)/sum(m_O(i)); - dvar_vector pp = m_P(i)/sum(m_P(i)); for(int j = c1; j <= c2; j++ ) { - m_rO(i)(k) += oo(j); - m_rP(i)(k) += pp(j); + m_rO(i)(k) += m_O(i)(j); + m_rP(i)(k) += m_P(i)(j); if(k<=n(i)) m_jagg(i,k) = j; - if( oo(j)>pmin && kpmin && k + T dmultinom(const DATA& x, const DVAR& p) + { + if(x.rowmin() != p.rowmin() || x.colmax() != p.colmax()) + { + cerr << "Index bounds do not macth in" + " dmultinom(const dvector& x, const dvar_vector& p)\n"; + exit(1); + } + + T ell = 0; + for(int i = x.rowmin(); i <= x.rowmax(); i++ ) + { + double n=sum(x(i)); + ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(p(i)/sum(p(i))); + } + return ell; + } + + + template + inline + const DVAR dmultinomialResidual(const DATA& O, const DVAR& P) + { + // dvar_vector t1 = elem_div(o1-p1,sqrt(elem_prod(p1,1.-p1)/Nsamp)); + DVAR nu; + DVAR var; + nu.allocate(P); nu.initialize(); + var.allocate(P); var.initialize(); + + int i; + for( i = O.rowmin(); i<= O.rowmax(); i++) + { + nu(i) = O(i)/sum(O(i)) - P(i)/sum(P(i)); + var(i) = elem_prod(P(i),1.0-P(i)) / sum(O(i)); + nu(i) = elem_div(nu(i),sqrt(var(i))); + } + return nu; + } + + template class multinomial: public negLogLikelihood { + private: + + DVAR m_nu; /// logistic residuals based on ragged object. + DVAR m_NU; /// residuals for rectangular matrix + public: // constructor multinomial(const DATA &_O, const DVAR &_P, const double eps=0) :negLogLikelihood(_O,_P) { + // residuals + this -> aggregate(eps); + DVAR tnu = acl::dmultinomialResidual(this->get_rO(),this->get_rP()); + set_nu(tnu); + // residuals to return. + m_NU.allocate(_P); + m_NU.initialize(); + imatrix idx = this->get_jagg(); + for(int i = _O.rowmin(); i <= _O.rowmax(); i++ ) + { + for(int j = 1; j <= size_count(m_nu(i)); j++ ) + { + int jj = idx(i,j); /* code */ + m_NU(i)(jj) = m_nu(i)(j); + } + } } const T nloglike() const { - return 0; + return acl::dmultinom(this->get_rO(),this->get_rP()); } const DVAR residual() const { - return 0; + return get_NU(); } + + DVAR get_nu() const {return m_nu; } + DVAR get_NU() const {return m_NU; } + void set_nu(DVAR &R){this->m_nu=R;} }; } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index c6eabaee..b3bbc816 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3205,7 +3205,13 @@ FUNCTION calcObjectiveFunction break; case 2: - nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); + ptr_AgeCompLike = new acl::multinomial(O,P,dMinP(k)); + nlvec(4,k) = ptr_AgeCompLike -> nloglike(); + nu = ptr_AgeCompLike -> residual(); + //COUT(nlvec(4,k)); + //nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); + //COUT(nlvec(4,k)); + //exit(1); break; case 3: if( !active(log_age_tau2(k)) ) // LN1 Model From 46af58bbbca656dc3adcfaecbed183a1ce538d76 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 3 Apr 2015 10:58:43 -0700 Subject: [PATCH 26/61] Added multinomial with effective sample size --- .../include/compositionLikelihoods.hpp | 123 ++++++++++++++---- src/admb-code/iscam.tpl | 14 +- 2 files changed, 107 insertions(+), 30 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index c8196a78..23de98cc 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -71,6 +71,9 @@ namespace acl inline void aggregate(const double pmin = 0.0); + inline + DVAR disaggregate(const DVAR &nu); + // getters & setters void set_O(DATA & O) { this -> m_O = O; } DATA get_O() const{ return m_O; } @@ -153,6 +156,26 @@ namespace acl } + template + inline + DVAR acl::negLogLikelihood::disaggregate(const DVAR &nu) + { + // residuals to return. + DVAR NU; + NU.allocate(m_P); + NU.initialize(); + imatrix idx = this->get_jagg(); + for(int i = m_O.rowmin(); i <= m_O.rowmax(); i++ ) + { + for(int j = 1; j <= size_count(nu(i)); j++ ) + { + int jj = idx(i,j); /* code */ + NU(i)(jj) = nu(i)(j); + } + } + return NU; + } + /** * @brief Get column indicies for each row to compress matrix into ragged array. * @details Determine the start and end positions of each row in which to compute @@ -270,17 +293,18 @@ namespace acl set_nu(tnu); // residuals to return. - m_NU.allocate(_P); - m_NU.initialize(); - imatrix idx = this->get_jagg(); - for(int i = _O.rowmin(); i <= _O.rowmax(); i++ ) - { - for(int j = 1; j <= size_count(m_nu(i)); j++ ) - { - int jj = idx(i,j); /* code */ - m_NU(i)(jj) = m_nu(i)(j); - } - } + m_NU = this-> disaggregate(this -> get_nu()); + // m_NU.allocate(_P); + // m_NU.initialize(); + // imatrix idx = this->get_jagg(); + // for(int i = _O.rowmin(); i <= _O.rowmax(); i++ ) + // { + // for(int j = 1; j <= size_count(m_nu(i)); j++ ) + // { + // int jj = idx(i,j); /* code */ + // m_NU(i)(jj) = m_nu(i)(j); + // } + // } } @@ -326,7 +350,7 @@ namespace acl // |-------------------------------------------------------------------------------| template - T dmultinom(const DATA& x, const DVAR& p) + T dmultinom(const DATA& x, const DVAR& p, const double eps) { if(x.rowmin() != p.rowmin() || x.colmax() != p.colmax()) { @@ -339,12 +363,41 @@ namespace acl for(int i = x.rowmin(); i <= x.rowmax(); i++ ) { double n=sum(x(i)); - ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(p(i)/sum(p(i))); + ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(eps + p(i)/sum(p(i))); } return ell; } + template + T dmultinom(const DATA& x, const DVAR& p, const T& log_vn, const double eps) + { + if(x.rowmin() != p.rowmin() || x.colmax() != p.colmax()) + { + cerr << "Index bounds do not macth in" + " dmultinom(const dvector& x, const dvar_vector& p)\n"; + exit(1); + } + + T ell = 0; + T vn = exp(log_vn); + DVAR sobs = x; + for(int i = x.rowmin(); i <= x.rowmax(); i++ ) + { + // double n=sum(x(i)); + // ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(p(i)/sum(p(i))); + ell -= gammln(vn); + sobs(i) = vn * x(i) / sum(sobs(i)); + for(int j = x(i).indexmin(); j <= x(i).indexmax(); j++ ) + { + if( sobs(i,j) > 0.0 ) + ell += gammln(sobs(i,j)); + } + ell -= sobs(i) * log(eps + p(i)/sum(p(i))); + } + return ell; + } + template inline const DVAR dmultinomialResidual(const DATA& O, const DVAR& P) @@ -370,12 +423,12 @@ namespace acl class multinomial: public negLogLikelihood { private: - + T m_nll; DVAR m_nu; /// logistic residuals based on ragged object. DVAR m_NU; /// residuals for rectangular matrix public: - // constructor + // constructor with fixed sample size in _O multinomial(const DATA &_O, const DVAR &_P, const double eps=0) :negLogLikelihood(_O,_P) { @@ -384,23 +437,37 @@ namespace acl DVAR tnu = acl::dmultinomialResidual(this->get_rO(),this->get_rP()); set_nu(tnu); + // compute negative loglikelihood + T negLL = acl::dmultinom(this->get_rO(),this->get_rP(),eps); + set_nll(negLL); + + // residuals to return. + m_NU = this-> disaggregate(this -> get_nu()); + + } + + // constructor with estimated sample size in _O + multinomial(const DATA &_O, const DVAR &_P, const T &log_vn, const double eps=0) + :negLogLikelihood(_O,_P) + { + // residuals + this -> aggregate(eps); + DVAR tnu = acl::dmultinomialResidual(this->get_rO(),this->get_rP()); + set_nu(tnu); + + // compute negative loglikelihood + T negLL = acl::dmultinom(this->get_rO(),this->get_rP(),log_vn,eps); + set_nll(negLL); + + // residuals to return. - m_NU.allocate(_P); - m_NU.initialize(); - imatrix idx = this->get_jagg(); - for(int i = _O.rowmin(); i <= _O.rowmax(); i++ ) - { - for(int j = 1; j <= size_count(m_nu(i)); j++ ) - { - int jj = idx(i,j); /* code */ - m_NU(i)(jj) = m_nu(i)(j); - } - } + m_NU = this-> disaggregate(this -> get_nu()); } const T nloglike() const { - return acl::dmultinom(this->get_rO(),this->get_rP()); + //return acl::dmultinom(this->get_rO(),this->get_rP()); + return get_nll(); } const DVAR residual() const @@ -410,7 +477,9 @@ namespace acl DVAR get_nu() const {return m_nu; } DVAR get_NU() const {return m_NU; } + T get_nll() const {return m_nll; } void set_nu(DVAR &R){this->m_nu=R;} + void set_nll(T &x) {this->m_nll=x; } }; } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index b3bbc816..a3190ebf 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3230,6 +3230,17 @@ FUNCTION calcObjectiveFunction age_tau2(k) = cLN_Age.get_sigma2(); } break; + + case 6: // Multinomial with estimated effective sample size. + + //nlvec(4,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); + //cout<(O,P,log_degrees_of_freedom(k)); + nlvec(4,k) = ptr_AgeCompLike -> nloglike(); + nu = ptr_AgeCompLike -> residual(); + + //cout< Date: Fri, 3 Apr 2015 11:22:19 -0700 Subject: [PATCH 27/61] Multinomial with effective sample size estimated --- .../include/compositionLikelihoods.hpp | 24 ++++++++++++------ src/admb-code/iscam.tpl | 25 +++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index 23de98cc..f8011ce9 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -349,8 +349,19 @@ namespace acl // | MULTINOMIAL DISTRIBUTION | // |-------------------------------------------------------------------------------| + /** + * @brief negative log density for multinomial distribution. + * @details Returns the negative log density for the multinomial distribution. + * Note that the sample size is based on the actual numbers in the matrix X. + * + * @param x Observed numbers in each bin + * @param p Predicted proportions in each bin. + * @param eps A tiny number to prevent log(0) + * @tparam T Templated variable (dvariable or df1b2variable) + * @return negative log density. + */ template - T dmultinom(const DATA& x, const DVAR& p, const double eps) + T dmultinom(const DATA& x, const DVAR& p) { if(x.rowmin() != p.rowmin() || x.colmax() != p.colmax()) { @@ -363,14 +374,14 @@ namespace acl for(int i = x.rowmin(); i <= x.rowmax(); i++ ) { double n=sum(x(i)); - ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(eps + p(i)/sum(p(i))); + ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log( p(i)/sum(p(i)) ); } return ell; } template - T dmultinom(const DATA& x, const DVAR& p, const T& log_vn, const double eps) + T dmultinom(const DATA& x, const DVAR& p, const T& log_vn) { if(x.rowmin() != p.rowmin() || x.colmax() != p.colmax()) { @@ -384,8 +395,7 @@ namespace acl DVAR sobs = x; for(int i = x.rowmin(); i <= x.rowmax(); i++ ) { - // double n=sum(x(i)); - // ell += -gammln(n+1.)+sum(gammln(x(i)+1.))-x(i)*log(p(i)/sum(p(i))); + ell -= gammln(vn); sobs(i) = vn * x(i) / sum(sobs(i)); for(int j = x(i).indexmin(); j <= x(i).indexmax(); j++ ) @@ -393,7 +403,7 @@ namespace acl if( sobs(i,j) > 0.0 ) ell += gammln(sobs(i,j)); } - ell -= sobs(i) * log(eps + p(i)/sum(p(i))); + ell -= sobs(i) * log( p(i)/sum(p(i)) ); } return ell; } @@ -456,7 +466,7 @@ namespace acl set_nu(tnu); // compute negative loglikelihood - T negLL = acl::dmultinom(this->get_rO(),this->get_rP(),log_vn,eps); + T negLL = acl::dmultinom(this->get_rO(),this->get_rP(),log_vn); set_nll(negLL); diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index a3190ebf..a8000135 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1560,7 +1560,7 @@ PARAMETER_SECTION init_bounded_number_vector log_age_tau2(1,nAgears,-4.65,5.30,nPhz_age_tau2); init_bounded_number_vector phi1(1,nAgears,-1.0,1.0,nPhz_phi1); init_bounded_number_vector phi2(1,nAgears,0.0,1.0,nPhz_phi2); - init_bounded_number_vector log_degrees_of_freedom(1,nAgears,0.70,10.0,nPhz_df); + init_bounded_number_vector log_degrees_of_freedom(1,nAgears,-10.0,10.0,nPhz_df); // |---------------------------------------------------------------------------------| // | DEPRECATE AUTOCORRELATION IN RECRUITMENT DEVIATIONS | @@ -3204,6 +3204,7 @@ FUNCTION calcObjectiveFunction nu = ptr_AgeCompLike -> residual(); break; + case 2: ptr_AgeCompLike = new acl::multinomial(O,P,dMinP(k)); nlvec(4,k) = ptr_AgeCompLike -> nloglike(); @@ -3213,6 +3214,18 @@ FUNCTION calcObjectiveFunction //COUT(nlvec(4,k)); //exit(1); break; + + case 6: // Multinomial with estimated effective sample size. + + //nlvec(4,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); + //cout<(O,P,log_degrees_of_freedom(k),dMinP(k)); + nlvec(4,k) = ptr_AgeCompLike -> nloglike(); + nu = ptr_AgeCompLike -> residual(); + + //cout<(O,P,log_degrees_of_freedom(k)); - nlvec(4,k) = ptr_AgeCompLike -> nloglike(); - nu = ptr_AgeCompLike -> residual(); - - //cout< Date: Fri, 3 Apr 2015 13:23:54 -0700 Subject: [PATCH 28/61] Did some speed tests with compositionLikelihoods.hpp. 7X slower, so deprecated --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 2 +- .../include/compositionLikelihoods.hpp | 3 ++ src/admb-code/iscam.tpl | 47 ++++++++++--------- src/admb-code/lib/multivariate_t.cpp | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index b92d97ab..93b966ad 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -38,7 +38,7 @@ ## ------------------------------------------------------------------------- ## ## Number of columns == na_gears. 1 6 6 ## : Gear Index - 6 6 6 ## : Likelihood type + 1 1 1 ## : Likelihood type 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize -1 -1 -1 ## : phase for log_age_tau2 estimation. diff --git a/src/admb-code/include/compositionLikelihoods.hpp b/src/admb-code/include/compositionLikelihoods.hpp index f8011ce9..3e915ab2 100644 --- a/src/admb-code/include/compositionLikelihoods.hpp +++ b/src/admb-code/include/compositionLikelihoods.hpp @@ -497,4 +497,7 @@ namespace acl + + + #endif \ No newline at end of file diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index a8000135..c09c4a59 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3147,7 +3147,7 @@ FUNCTION calcObjectiveFunction // Testing new abstract compositionLikelihood class. - acl::negLogLikelihood *ptr_AgeCompLike; + //acl::negLogLikelihood *ptr_AgeCompLike[nAgears-1]; @@ -3196,36 +3196,34 @@ FUNCTION calcObjectiveFunction logistic_student_t cLST_Age( O,P,dMinP(k),dEps(k) ); switch( int(nCompLikelihood(k)) ) { - case 1: - //nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); + case 1: // multivariate Logistic + nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); //cout<<"like: "<(O,P,dMinP(k)); - nlvec(4,k) = ptr_AgeCompLike -> nloglike(); - nu = ptr_AgeCompLike -> residual(); + //ptr_AgeCompLike[k-1] = new acl::multivariteLogistic(O,P,dMinP(k)); + //nlvec(4,k) = ptr_AgeCompLike[k-1] -> nloglike(); + //nu = ptr_AgeCompLike[k-1] -> residual(); break; - case 2: - ptr_AgeCompLike = new acl::multinomial(O,P,dMinP(k)); - nlvec(4,k) = ptr_AgeCompLike -> nloglike(); - nu = ptr_AgeCompLike -> residual(); + case 2: // multinomial with fixed sample size. + //ptr_AgeCompLike[k-1] = new acl::multinomial(O,P,dMinP(k)); + //nlvec(4,k) = ptr_AgeCompLike[k-1] -> nloglike(); + //nu = ptr_AgeCompLike[k-1] -> residual(); //COUT(nlvec(4,k)); - //nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); + nlvec(4,k) = dmultinom(O,P,nu,age_tau2(k),dMinP(k)); //COUT(nlvec(4,k)); //exit(1); break; case 6: // Multinomial with estimated effective sample size. - - //nlvec(4,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); - //cout<(O,P,log_degrees_of_freedom(k),dMinP(k)); - nlvec(4,k) = ptr_AgeCompLike -> nloglike(); - nu = ptr_AgeCompLike -> residual(); + //ptr_AgeCompLike[k-1] = new acl::multinomial(O,P,log_degrees_of_freedom(k),dMinP(k)); + //nlvec(4,k) = ptr_AgeCompLike[k-1] -> nloglike(); + //nu = ptr_AgeCompLike[k-1] -> residual(); + // deprecate + nlvec(4,k) = mult_likelihood(O,P,nu,log_degrees_of_freedom(k)); - //cout< Date: Fri, 3 Apr 2015 16:48:44 -0700 Subject: [PATCH 29/61] Modification to Halibut Data file to stirp 00s of age comps. --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 18 +-- fba/HALIBUT/DATA/Halibut2014.dat | 146 +++++++++++----------- src/R/lib/plotAgeComps.R | 13 +- src/admb-code/iscam.tpl | 27 ++-- 4 files changed, 108 insertions(+), 96 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 93b966ad..d4d03dbf 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -37,14 +37,14 @@ ## -6 : multinomial with estimated effective sample size. ## ------------------------------------------------------------------------- ## ## Number of columns == na_gears. - 1 6 6 ## : Gear Index - 1 1 1 ## : Likelihood type - 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression - 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize - -1 -1 -1 ## : phase for log_age_tau2 estimation. - -2 -2 -2 ## : phase for phi1 estimation : bounded (-1,1) AR1 - -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 - 2 2 2 ## : phase for degrees of freedom for student T. + 1 1 6 6 ## : Gear Index + 1 1 1 1 ## : Likelihood type + 0.000 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression + 0.0000 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize + -1 -1 -1 -1 ## : phase for log_age_tau2 estimation. + -2 -2 -2 -2 ## : phase for phi1 estimation : bounded (-1,1) AR1 + -2 -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 + 2 2 2 2 ## : phase for degrees of freedom for student T. -12345 ## : int check (-12345) ## ------------------------------------------------------------------------- ## @@ -135,7 +135,7 @@ -3 # 10 -DEPRECATED phase for estimating m_deviations (use -1 to turn off mdevs) 0.1 # 11 -DEPRECATED std in deviations for natural mortality 12 # 12 -DEPRECATED number of estimated nodes for deviations in natural mortality -0.00 # 13 -fraction of total mortality that takes place prior to spawning +1.00 # 13 -fraction of total mortality that takes place prior to spawning 82 # 14 -number of perspective years to start assessment at. 0 # 15 -switch for IFD distribution in selectivity simulations ## diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index 9715bca7..1c1dff78 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -522,85 +522,85 @@ ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## ## ------------------------------------------------------------------------- ## -3 # Number of gears with age-comps int(na_gears) -80 26 26 # Number of rows in the matrix ivector(na_gears) +4 # Number of gears with age-comps int(na_gears) +67 13 26 26 # Number of rows in the matrix ivector(na_gears) ## ivector(na_gears) of youngest age-class -6 6 6 +6 6 6 6 ## ivector(na_gears) of oldest age-class + group -25 25 25 +20 25 25 25 ## Effective sample size from iterative re-weighting (nscaler) -111.4450 28.7800 43.9589 +50 111.4450 28.7800 43.9589 ## Age Flag (0=length comps, 1 = age comps) -1 1 1 +1 1 1 1 ## commercial catches ## year gear area group sex age_err | data columns (numbers or proportions) - 1935 1 1 1 0 4 0.1085 0.1645 0.1479 0.1896 0.1486 0.0762 0.0610 0.0375 0.0225 0.0165 0.0112 0.0055 0.0044 0.0021 0.0041 0.0000 0.0000 0.0000 0.0000 0.0000 - 1936 1 1 1 0 4 0.0729 0.1376 0.1219 0.1225 0.1496 0.1208 0.0864 0.0673 0.0388 0.0261 0.0183 0.0132 0.0099 0.0042 0.0105 0.0000 0.0000 0.0000 0.0000 0.0000 - 1937 1 1 1 0 4 0.0715 0.0929 0.1694 0.1244 0.1129 0.1208 0.1000 0.0802 0.0379 0.0364 0.0168 0.0108 0.0073 0.0060 0.0127 0.0000 0.0000 0.0000 0.0000 0.0000 - 1938 1 1 1 0 4 0.1129 0.1154 0.1649 0.1634 0.0741 0.0772 0.0835 0.0751 0.0559 0.0315 0.0184 0.0100 0.0049 0.0050 0.0080 0.0000 0.0000 0.0000 0.0000 0.0000 - 1939 1 1 1 0 4 0.0883 0.0863 0.1537 0.1421 0.1535 0.0809 0.0819 0.0690 0.0608 0.0323 0.0269 0.0116 0.0074 0.0010 0.0041 0.0000 0.0000 0.0000 0.0000 0.0000 - 1940 1 1 1 0 4 0.1354 0.0819 0.0997 0.1274 0.1618 0.1236 0.0779 0.0485 0.0484 0.0475 0.0202 0.0132 0.0081 0.0016 0.0049 0.0000 0.0000 0.0000 0.0000 0.0000 - 1941 1 1 1 0 4 0.1321 0.0840 0.1386 0.1137 0.1337 0.1125 0.1064 0.0596 0.0347 0.0352 0.0245 0.0127 0.0054 0.0022 0.0046 0.0000 0.0000 0.0000 0.0000 0.0000 - 1942 1 1 1 0 4 0.0924 0.1572 0.1021 0.1197 0.1161 0.1057 0.1015 0.0787 0.0431 0.0260 0.0257 0.0132 0.0100 0.0038 0.0047 0.0000 0.0000 0.0000 0.0000 0.0000 - 1943 1 1 1 0 4 0.0954 0.1839 0.2094 0.0969 0.0855 0.0744 0.0720 0.0754 0.0382 0.0258 0.0190 0.0104 0.0057 0.0036 0.0044 0.0000 0.0000 0.0000 0.0000 0.0000 - 1944 1 1 1 0 4 0.0616 0.0793 0.1749 0.1459 0.1004 0.0857 0.0946 0.0978 0.0637 0.0371 0.0230 0.0160 0.0071 0.0078 0.0051 0.0000 0.0000 0.0000 0.0000 0.0000 - 1945 1 1 1 0 4 0.0892 0.1572 0.1585 0.1452 0.0999 0.0767 0.0744 0.0780 0.0465 0.0273 0.0177 0.0127 0.0056 0.0055 0.0057 0.0000 0.0000 0.0000 0.0000 0.0000 - 1946 1 1 1 0 4 0.0457 0.1226 0.1913 0.1477 0.1363 0.0852 0.0767 0.0761 0.0457 0.0264 0.0177 0.0122 0.0056 0.0051 0.0057 0.0000 0.0000 0.0000 0.0000 0.0000 - 1947 1 1 1 0 4 0.0630 0.0716 0.1631 0.1503 0.1277 0.1112 0.0933 0.0852 0.0513 0.0297 0.0202 0.0150 0.0066 0.0058 0.0061 0.0000 0.0000 0.0000 0.0000 0.0000 - 1948 1 1 1 0 4 0.0630 0.0871 0.1647 0.1762 0.1370 0.0976 0.0798 0.0761 0.0457 0.0262 0.0181 0.0123 0.0055 0.0052 0.0054 0.0000 0.0000 0.0000 0.0000 0.0000 - 1949 1 1 1 0 4 0.0371 0.0577 0.1235 0.1477 0.1650 0.1137 0.1188 0.0934 0.0551 0.0264 0.0190 0.0173 0.0092 0.0058 0.0101 0.0000 0.0000 0.0000 0.0000 0.0000 - 1950 1 1 1 0 4 0.0190 0.0408 0.1129 0.1959 0.1516 0.1165 0.1108 0.0877 0.0771 0.0301 0.0239 0.0126 0.0063 0.0046 0.0101 0.0000 0.0000 0.0000 0.0000 0.0000 - 1951 1 1 1 0 4 0.0085 0.0519 0.1064 0.1568 0.1718 0.1291 0.1021 0.0955 0.0615 0.0518 0.0262 0.0169 0.0101 0.0041 0.0073 0.0000 0.0000 0.0000 0.0000 0.0000 - 1952 1 1 1 0 4 0.0226 0.0216 0.1210 0.1495 0.1397 0.1443 0.1017 0.0956 0.0746 0.0522 0.0331 0.0204 0.0094 0.0064 0.0079 0.0000 0.0000 0.0000 0.0000 0.0000 - 1953 1 1 1 0 4 0.0289 0.0584 0.0866 0.1703 0.1513 0.1355 0.1093 0.0797 0.0571 0.0451 0.0322 0.0181 0.0141 0.0039 0.0095 0.0000 0.0000 0.0000 0.0000 0.0000 - 1954 1 1 1 0 4 0.0387 0.0467 0.1034 0.1053 0.1854 0.1143 0.0980 0.0848 0.0646 0.0505 0.0429 0.0273 0.0173 0.0093 0.0116 0.0000 0.0000 0.0000 0.0000 0.0000 - 1955 1 1 1 0 4 0.0889 0.0744 0.0985 0.1275 0.1059 0.1523 0.1011 0.0768 0.0511 0.0404 0.0303 0.0231 0.0125 0.0079 0.0095 0.0000 0.0000 0.0000 0.0000 0.0000 - 1956 1 1 1 0 4 0.0940 0.1027 0.1119 0.0929 0.1271 0.0856 0.1181 0.0770 0.0622 0.0410 0.0257 0.0208 0.0151 0.0121 0.0139 0.0000 0.0000 0.0000 0.0000 0.0000 - 1957 1 1 1 0 4 0.0812 0.1069 0.1202 0.1188 0.0805 0.1076 0.0752 0.1030 0.0603 0.0487 0.0323 0.0228 0.0172 0.0097 0.0155 0.0000 0.0000 0.0000 0.0000 0.0000 - 1958 1 1 1 0 4 0.1450 0.1145 0.1120 0.1036 0.0985 0.0761 0.0772 0.0571 0.0762 0.0471 0.0288 0.0209 0.0163 0.0111 0.0154 0.0000 0.0000 0.0000 0.0000 0.0000 - 1959 1 1 1 0 4 0.1324 0.0669 0.1993 0.1381 0.1077 0.0862 0.0522 0.0593 0.0388 0.0387 0.0234 0.0180 0.0115 0.0105 0.0168 0.0000 0.0000 0.0000 0.0000 0.0000 - 1960 1 1 1 0 4 0.1126 0.0778 0.1170 0.2314 0.1287 0.0831 0.0570 0.0437 0.0374 0.0305 0.0256 0.0173 0.0120 0.0086 0.0171 0.0000 0.0000 0.0000 0.0000 0.0000 - 1961 1 1 1 0 4 0.0644 0.1012 0.1132 0.1301 0.2120 0.1110 0.0719 0.0492 0.0351 0.0305 0.0239 0.0200 0.0124 0.0087 0.0164 0.0000 0.0000 0.0000 0.0000 0.0000 - 1962 1 1 1 0 4 0.0655 0.0763 0.1229 0.1351 0.1461 0.1892 0.0738 0.0491 0.0333 0.0261 0.0252 0.0192 0.0131 0.0080 0.0172 0.0000 0.0000 0.0000 0.0000 0.0000 - 1963 1 1 1 0 4 0.0818 0.0735 0.1434 0.1511 0.1308 0.1204 0.1309 0.0533 0.0279 0.0179 0.0172 0.0150 0.0121 0.0086 0.0160 0.0000 0.0000 0.0000 0.0000 0.0000 - 1964 1 1 1 0 4 0.0504 0.0929 0.1002 0.1885 0.1384 0.1168 0.0987 0.0976 0.0381 0.0189 0.0146 0.0121 0.0086 0.0080 0.0161 0.0000 0.0000 0.0000 0.0000 0.0000 - 1965 1 1 1 0 4 0.0524 0.0817 0.1552 0.1160 0.1898 0.1161 0.0880 0.0725 0.0562 0.0209 0.0129 0.0093 0.0083 0.0058 0.0148 0.0000 0.0000 0.0000 0.0000 0.0000 - 1966 1 1 1 0 4 0.0471 0.0494 0.1096 0.1534 0.1143 0.1619 0.1010 0.0805 0.0661 0.0464 0.0217 0.0137 0.0106 0.0056 0.0187 0.0000 0.0000 0.0000 0.0000 0.0000 - 1967 1 1 1 0 4 0.0778 0.0711 0.0881 0.1643 0.1548 0.0963 0.1196 0.0687 0.0479 0.0374 0.0269 0.0136 0.0094 0.0067 0.0173 0.0000 0.0000 0.0000 0.0000 0.0000 - 1968 1 1 1 0 4 0.0777 0.1108 0.0990 0.1021 0.1611 0.1256 0.0794 0.0932 0.0489 0.0354 0.0268 0.0173 0.0080 0.0044 0.0102 0.0000 0.0000 0.0000 0.0000 0.0000 - 1969 1 1 1 0 4 0.1105 0.0591 0.1727 0.0987 0.0872 0.1288 0.1020 0.0659 0.0637 0.0329 0.0272 0.0203 0.0117 0.0066 0.0128 0.0000 0.0000 0.0000 0.0000 0.0000 - 1970 1 1 1 0 4 0.1088 0.0799 0.0987 0.1886 0.0915 0.0820 0.1064 0.0727 0.0506 0.0450 0.0242 0.0158 0.0122 0.0089 0.0147 0.0000 0.0000 0.0000 0.0000 0.0000 - 1971 1 1 1 0 4 0.1255 0.1017 0.1335 0.1164 0.1729 0.0706 0.0621 0.0688 0.0479 0.0387 0.0238 0.0147 0.0094 0.0061 0.0081 0.0000 0.0000 0.0000 0.0000 0.0000 - 1972 1 1 1 0 4 0.1139 0.1099 0.1348 0.1347 0.1125 0.1493 0.0582 0.0573 0.0440 0.0318 0.0209 0.0132 0.0065 0.0049 0.0082 0.0000 0.0000 0.0000 0.0000 0.0000 - 1973 1 1 1 0 4 0.0269 0.0661 0.1138 0.1376 0.1489 0.1187 0.1492 0.0621 0.0486 0.0480 0.0308 0.0160 0.0136 0.0054 0.0144 0.0000 0.0000 0.0000 0.0000 0.0000 - 1974 1 1 1 0 4 0.0202 0.0454 0.1028 0.1246 0.1325 0.1304 0.1035 0.1276 0.0472 0.0465 0.0485 0.0268 0.0151 0.0115 0.0173 0.0000 0.0000 0.0000 0.0000 0.0000 - 1975 1 1 1 0 4 0.0178 0.0423 0.1025 0.1322 0.1423 0.1332 0.1220 0.0778 0.0906 0.0343 0.0321 0.0265 0.0170 0.0080 0.0215 0.0000 0.0000 0.0000 0.0000 0.0000 - 1976 1 1 1 0 4 0.0491 0.0539 0.1244 0.1442 0.1340 0.1095 0.1065 0.0744 0.0602 0.0617 0.0210 0.0196 0.0148 0.0081 0.0185 0.0000 0.0000 0.0000 0.0000 0.0000 - 1977 1 1 1 0 4 0.0288 0.0583 0.1065 0.1362 0.1577 0.1079 0.1049 0.0848 0.0654 0.0491 0.0453 0.0172 0.0137 0.0075 0.0165 0.0000 0.0000 0.0000 0.0000 0.0000 - 1978 1 1 1 0 4 0.0390 0.0691 0.1275 0.1387 0.1465 0.1236 0.1018 0.0691 0.0590 0.0425 0.0320 0.0190 0.0103 0.0065 0.0153 0.0000 0.0000 0.0000 0.0000 0.0000 - 1979 1 1 1 0 4 0.0165 0.0644 0.1065 0.1551 0.1501 0.1307 0.1202 0.0724 0.0637 0.0412 0.0315 0.0191 0.0114 0.0052 0.0120 0.0000 0.0000 0.0000 0.0000 0.0000 - 1980 1 1 1 0 4 0.0171 0.0527 0.1148 0.1286 0.1569 0.1335 0.1136 0.0812 0.0615 0.0435 0.0335 0.0215 0.0169 0.0097 0.0149 0.0000 0.0000 0.0000 0.0000 0.0000 - 1981 1 1 1 0 4 0.0220 0.0456 0.1138 0.1632 0.1384 0.1474 0.1121 0.0817 0.0566 0.0361 0.0272 0.0190 0.0139 0.0063 0.0168 0.0000 0.0000 0.0000 0.0000 0.0000 - 1982 1 1 1 0 4 0.0131 0.0480 0.0903 0.1633 0.1685 0.1323 0.1253 0.0874 0.0595 0.0370 0.0229 0.0197 0.0109 0.0080 0.0138 0.0000 0.0000 0.0000 0.0000 0.0000 - 1983 1 1 1 0 4 0.0094 0.0373 0.0972 0.1388 0.2068 0.1435 0.1209 0.0843 0.0544 0.0376 0.0263 0.0150 0.0102 0.0054 0.0128 0.0000 0.0000 0.0000 0.0000 0.0000 - 1984 1 1 1 0 4 0.0120 0.0614 0.1180 0.1511 0.1542 0.1752 0.1124 0.0727 0.0566 0.0305 0.0188 0.0143 0.0077 0.0046 0.0105 0.0000 0.0000 0.0000 0.0000 0.0000 - 1985 1 1 1 0 4 0.0064 0.0295 0.1191 0.1533 0.1683 0.1511 0.1451 0.0750 0.0484 0.0363 0.0257 0.0128 0.0099 0.0058 0.0131 0.0000 0.0000 0.0000 0.0000 0.0000 - 1986 1 1 1 0 4 0.0035 0.0274 0.0908 0.1844 0.1643 0.1523 0.1312 0.0982 0.0544 0.0326 0.0260 0.0119 0.0081 0.0062 0.0085 0.0000 0.0000 0.0000 0.0000 0.0000 - 1987 1 1 1 0 4 0.0038 0.0346 0.0878 0.1291 0.1987 0.1637 0.1203 0.0885 0.0678 0.0398 0.0239 0.0144 0.0100 0.0058 0.0117 0.0000 0.0000 0.0000 0.0000 0.0000 - 1988 1 1 1 0 4 0.0048 0.0317 0.1117 0.1593 0.1499 0.1979 0.1123 0.0701 0.0595 0.0443 0.0198 0.0132 0.0088 0.0054 0.0112 0.0000 0.0000 0.0000 0.0000 0.0000 - 1989 1 1 1 0 4 0.0077 0.0178 0.0686 0.1621 0.1713 0.1401 0.1707 0.0867 0.0584 0.0439 0.0315 0.0149 0.0108 0.0051 0.0102 0.0000 0.0000 0.0000 0.0000 0.0000 - 1990 1 1 1 0 4 0.0088 0.0221 0.0455 0.0972 0.1859 0.1656 0.1482 0.1348 0.0692 0.0449 0.0338 0.0184 0.0087 0.0060 0.0109 0.0000 0.0000 0.0000 0.0000 0.0000 - 1991 1 1 1 0 4 0.0045 0.0260 0.0574 0.0701 0.1216 0.1888 0.1699 0.1250 0.1056 0.0553 0.0292 0.0190 0.0126 0.0050 0.0101 0.0000 0.0000 0.0000 0.0000 0.0000 - 1992 1 1 1 0 4 0.0028 0.0162 0.0566 0.1095 0.1007 0.1461 0.1723 0.1291 0.0923 0.0753 0.0395 0.0227 0.0164 0.0077 0.0128 0.0000 0.0000 0.0000 0.0000 0.0000 - 1993 1 1 1 0 4 0.0035 0.0074 0.0348 0.0823 0.1371 0.1219 0.1291 0.1459 0.1197 0.0798 0.0592 0.0330 0.0172 0.0110 0.0183 0.0000 0.0000 0.0000 0.0000 0.0000 - 1994 1 1 1 0 4 0.0066 0.0133 0.0265 0.0490 0.0954 0.1461 0.1318 0.1284 0.1330 0.1006 0.0695 0.0439 0.0246 0.0109 0.0203 0.0000 0.0000 0.0000 0.0000 0.0000 - 1995 1 1 1 0 4 0.0059 0.0177 0.0599 0.0571 0.0885 0.1391 0.1623 0.1183 0.1125 0.0843 0.0538 0.0346 0.0259 0.0132 0.0268 0.0000 0.0000 0.0000 0.0000 0.0000 - 1996 1 1 1 0 4 0.0030 0.0126 0.0449 0.1225 0.0942 0.1136 0.1509 0.1414 0.0917 0.0690 0.0579 0.0397 0.0223 0.0134 0.0231 0.0000 0.0000 0.0000 0.0000 0.0000 - 1997 1 1 1 0 4 0.0052 0.0160 0.0423 0.1020 0.1781 0.1113 0.1204 0.1149 0.0965 0.0565 0.0464 0.0383 0.0236 0.0179 0.0306 0.0000 0.0000 0.0000 0.0000 0.0000 - 1998 1 1 1 0 4 0.0022 0.0088 0.0282 0.0544 0.1334 0.2181 0.1091 0.0981 0.0976 0.0722 0.0467 0.0349 0.0321 0.0206 0.0436 0.0000 0.0000 0.0000 0.0000 0.0000 - 1999 1 1 1 0 4 0.0026 0.0060 0.0170 0.0414 0.0691 0.1477 0.2165 0.0981 0.0842 0.0791 0.0655 0.0411 0.0380 0.0291 0.0647 0.0000 0.0000 0.0000 0.0000 0.0000 - 2000 1 1 1 0 4 0.0051 0.0075 0.0211 0.0338 0.0632 0.0930 0.1460 0.2367 0.0879 0.0580 0.0510 0.0501 0.0333 0.0263 0.0869 0.0000 0.0000 0.0000 0.0000 0.0000 - 2001 1 1 1 0 4 0.0018 0.0083 0.0173 0.0353 0.0488 0.0788 0.1057 0.1701 0.1959 0.0840 0.0458 0.0422 0.0363 0.0291 0.1006 0.0000 0.0000 0.0000 0.0000 0.0000 + 1935 1 1 1 0 4 0.1085 0.1645 0.1479 0.1896 0.1486 0.0762 0.0610 0.0375 0.0225 0.0165 0.0112 0.0055 0.0044 0.0021 0.0041 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1936 1 1 1 0 4 0.0729 0.1376 0.1219 0.1225 0.1496 0.1208 0.0864 0.0673 0.0388 0.0261 0.0183 0.0132 0.0099 0.0042 0.0105 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1937 1 1 1 0 4 0.0715 0.0929 0.1694 0.1244 0.1129 0.1208 0.1000 0.0802 0.0379 0.0364 0.0168 0.0108 0.0073 0.0060 0.0127 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1938 1 1 1 0 4 0.1129 0.1154 0.1649 0.1634 0.0741 0.0772 0.0835 0.0751 0.0559 0.0315 0.0184 0.0100 0.0049 0.0050 0.0080 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1939 1 1 1 0 4 0.0883 0.0863 0.1537 0.1421 0.1535 0.0809 0.0819 0.0690 0.0608 0.0323 0.0269 0.0116 0.0074 0.0010 0.0041 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1940 1 1 1 0 4 0.1354 0.0819 0.0997 0.1274 0.1618 0.1236 0.0779 0.0485 0.0484 0.0475 0.0202 0.0132 0.0081 0.0016 0.0049 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1941 1 1 1 0 4 0.1321 0.0840 0.1386 0.1137 0.1337 0.1125 0.1064 0.0596 0.0347 0.0352 0.0245 0.0127 0.0054 0.0022 0.0046 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1942 1 1 1 0 4 0.0924 0.1572 0.1021 0.1197 0.1161 0.1057 0.1015 0.0787 0.0431 0.0260 0.0257 0.0132 0.0100 0.0038 0.0047 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1943 1 1 1 0 4 0.0954 0.1839 0.2094 0.0969 0.0855 0.0744 0.0720 0.0754 0.0382 0.0258 0.0190 0.0104 0.0057 0.0036 0.0044 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1944 1 1 1 0 4 0.0616 0.0793 0.1749 0.1459 0.1004 0.0857 0.0946 0.0978 0.0637 0.0371 0.0230 0.0160 0.0071 0.0078 0.0051 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1945 1 1 1 0 4 0.0892 0.1572 0.1585 0.1452 0.0999 0.0767 0.0744 0.0780 0.0465 0.0273 0.0177 0.0127 0.0056 0.0055 0.0057 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1946 1 1 1 0 4 0.0457 0.1226 0.1913 0.1477 0.1363 0.0852 0.0767 0.0761 0.0457 0.0264 0.0177 0.0122 0.0056 0.0051 0.0057 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1947 1 1 1 0 4 0.0630 0.0716 0.1631 0.1503 0.1277 0.1112 0.0933 0.0852 0.0513 0.0297 0.0202 0.0150 0.0066 0.0058 0.0061 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1948 1 1 1 0 4 0.0630 0.0871 0.1647 0.1762 0.1370 0.0976 0.0798 0.0761 0.0457 0.0262 0.0181 0.0123 0.0055 0.0052 0.0054 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1949 1 1 1 0 4 0.0371 0.0577 0.1235 0.1477 0.1650 0.1137 0.1188 0.0934 0.0551 0.0264 0.0190 0.0173 0.0092 0.0058 0.0101 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1950 1 1 1 0 4 0.0190 0.0408 0.1129 0.1959 0.1516 0.1165 0.1108 0.0877 0.0771 0.0301 0.0239 0.0126 0.0063 0.0046 0.0101 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1951 1 1 1 0 4 0.0085 0.0519 0.1064 0.1568 0.1718 0.1291 0.1021 0.0955 0.0615 0.0518 0.0262 0.0169 0.0101 0.0041 0.0073 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1952 1 1 1 0 4 0.0226 0.0216 0.1210 0.1495 0.1397 0.1443 0.1017 0.0956 0.0746 0.0522 0.0331 0.0204 0.0094 0.0064 0.0079 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1953 1 1 1 0 4 0.0289 0.0584 0.0866 0.1703 0.1513 0.1355 0.1093 0.0797 0.0571 0.0451 0.0322 0.0181 0.0141 0.0039 0.0095 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1954 1 1 1 0 4 0.0387 0.0467 0.1034 0.1053 0.1854 0.1143 0.0980 0.0848 0.0646 0.0505 0.0429 0.0273 0.0173 0.0093 0.0116 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1955 1 1 1 0 4 0.0889 0.0744 0.0985 0.1275 0.1059 0.1523 0.1011 0.0768 0.0511 0.0404 0.0303 0.0231 0.0125 0.0079 0.0095 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1956 1 1 1 0 4 0.0940 0.1027 0.1119 0.0929 0.1271 0.0856 0.1181 0.0770 0.0622 0.0410 0.0257 0.0208 0.0151 0.0121 0.0139 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1957 1 1 1 0 4 0.0812 0.1069 0.1202 0.1188 0.0805 0.1076 0.0752 0.1030 0.0603 0.0487 0.0323 0.0228 0.0172 0.0097 0.0155 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1958 1 1 1 0 4 0.1450 0.1145 0.1120 0.1036 0.0985 0.0761 0.0772 0.0571 0.0762 0.0471 0.0288 0.0209 0.0163 0.0111 0.0154 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1959 1 1 1 0 4 0.1324 0.0669 0.1993 0.1381 0.1077 0.0862 0.0522 0.0593 0.0388 0.0387 0.0234 0.0180 0.0115 0.0105 0.0168 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1960 1 1 1 0 4 0.1126 0.0778 0.1170 0.2314 0.1287 0.0831 0.0570 0.0437 0.0374 0.0305 0.0256 0.0173 0.0120 0.0086 0.0171 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1961 1 1 1 0 4 0.0644 0.1012 0.1132 0.1301 0.2120 0.1110 0.0719 0.0492 0.0351 0.0305 0.0239 0.0200 0.0124 0.0087 0.0164 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1962 1 1 1 0 4 0.0655 0.0763 0.1229 0.1351 0.1461 0.1892 0.0738 0.0491 0.0333 0.0261 0.0252 0.0192 0.0131 0.0080 0.0172 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1963 1 1 1 0 4 0.0818 0.0735 0.1434 0.1511 0.1308 0.1204 0.1309 0.0533 0.0279 0.0179 0.0172 0.0150 0.0121 0.0086 0.0160 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1964 1 1 1 0 4 0.0504 0.0929 0.1002 0.1885 0.1384 0.1168 0.0987 0.0976 0.0381 0.0189 0.0146 0.0121 0.0086 0.0080 0.0161 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1965 1 1 1 0 4 0.0524 0.0817 0.1552 0.1160 0.1898 0.1161 0.0880 0.0725 0.0562 0.0209 0.0129 0.0093 0.0083 0.0058 0.0148 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1966 1 1 1 0 4 0.0471 0.0494 0.1096 0.1534 0.1143 0.1619 0.1010 0.0805 0.0661 0.0464 0.0217 0.0137 0.0106 0.0056 0.0187 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1967 1 1 1 0 4 0.0778 0.0711 0.0881 0.1643 0.1548 0.0963 0.1196 0.0687 0.0479 0.0374 0.0269 0.0136 0.0094 0.0067 0.0173 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1968 1 1 1 0 4 0.0777 0.1108 0.0990 0.1021 0.1611 0.1256 0.0794 0.0932 0.0489 0.0354 0.0268 0.0173 0.0080 0.0044 0.0102 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1969 1 1 1 0 4 0.1105 0.0591 0.1727 0.0987 0.0872 0.1288 0.1020 0.0659 0.0637 0.0329 0.0272 0.0203 0.0117 0.0066 0.0128 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1970 1 1 1 0 4 0.1088 0.0799 0.0987 0.1886 0.0915 0.0820 0.1064 0.0727 0.0506 0.0450 0.0242 0.0158 0.0122 0.0089 0.0147 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1971 1 1 1 0 4 0.1255 0.1017 0.1335 0.1164 0.1729 0.0706 0.0621 0.0688 0.0479 0.0387 0.0238 0.0147 0.0094 0.0061 0.0081 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1972 1 1 1 0 4 0.1139 0.1099 0.1348 0.1347 0.1125 0.1493 0.0582 0.0573 0.0440 0.0318 0.0209 0.0132 0.0065 0.0049 0.0082 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1973 1 1 1 0 4 0.0269 0.0661 0.1138 0.1376 0.1489 0.1187 0.1492 0.0621 0.0486 0.0480 0.0308 0.0160 0.0136 0.0054 0.0144 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1974 1 1 1 0 4 0.0202 0.0454 0.1028 0.1246 0.1325 0.1304 0.1035 0.1276 0.0472 0.0465 0.0485 0.0268 0.0151 0.0115 0.0173 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1975 1 1 1 0 4 0.0178 0.0423 0.1025 0.1322 0.1423 0.1332 0.1220 0.0778 0.0906 0.0343 0.0321 0.0265 0.0170 0.0080 0.0215 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1976 1 1 1 0 4 0.0491 0.0539 0.1244 0.1442 0.1340 0.1095 0.1065 0.0744 0.0602 0.0617 0.0210 0.0196 0.0148 0.0081 0.0185 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1977 1 1 1 0 4 0.0288 0.0583 0.1065 0.1362 0.1577 0.1079 0.1049 0.0848 0.0654 0.0491 0.0453 0.0172 0.0137 0.0075 0.0165 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1978 1 1 1 0 4 0.0390 0.0691 0.1275 0.1387 0.1465 0.1236 0.1018 0.0691 0.0590 0.0425 0.0320 0.0190 0.0103 0.0065 0.0153 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1979 1 1 1 0 4 0.0165 0.0644 0.1065 0.1551 0.1501 0.1307 0.1202 0.0724 0.0637 0.0412 0.0315 0.0191 0.0114 0.0052 0.0120 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1980 1 1 1 0 4 0.0171 0.0527 0.1148 0.1286 0.1569 0.1335 0.1136 0.0812 0.0615 0.0435 0.0335 0.0215 0.0169 0.0097 0.0149 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1981 1 1 1 0 4 0.0220 0.0456 0.1138 0.1632 0.1384 0.1474 0.1121 0.0817 0.0566 0.0361 0.0272 0.0190 0.0139 0.0063 0.0168 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1982 1 1 1 0 4 0.0131 0.0480 0.0903 0.1633 0.1685 0.1323 0.1253 0.0874 0.0595 0.0370 0.0229 0.0197 0.0109 0.0080 0.0138 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1983 1 1 1 0 4 0.0094 0.0373 0.0972 0.1388 0.2068 0.1435 0.1209 0.0843 0.0544 0.0376 0.0263 0.0150 0.0102 0.0054 0.0128 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1984 1 1 1 0 4 0.0120 0.0614 0.1180 0.1511 0.1542 0.1752 0.1124 0.0727 0.0566 0.0305 0.0188 0.0143 0.0077 0.0046 0.0105 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1985 1 1 1 0 4 0.0064 0.0295 0.1191 0.1533 0.1683 0.1511 0.1451 0.0750 0.0484 0.0363 0.0257 0.0128 0.0099 0.0058 0.0131 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1986 1 1 1 0 4 0.0035 0.0274 0.0908 0.1844 0.1643 0.1523 0.1312 0.0982 0.0544 0.0326 0.0260 0.0119 0.0081 0.0062 0.0085 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1987 1 1 1 0 4 0.0038 0.0346 0.0878 0.1291 0.1987 0.1637 0.1203 0.0885 0.0678 0.0398 0.0239 0.0144 0.0100 0.0058 0.0117 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1988 1 1 1 0 4 0.0048 0.0317 0.1117 0.1593 0.1499 0.1979 0.1123 0.0701 0.0595 0.0443 0.0198 0.0132 0.0088 0.0054 0.0112 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1989 1 1 1 0 4 0.0077 0.0178 0.0686 0.1621 0.1713 0.1401 0.1707 0.0867 0.0584 0.0439 0.0315 0.0149 0.0108 0.0051 0.0102 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1990 1 1 1 0 4 0.0088 0.0221 0.0455 0.0972 0.1859 0.1656 0.1482 0.1348 0.0692 0.0449 0.0338 0.0184 0.0087 0.0060 0.0109 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1991 1 1 1 0 4 0.0045 0.0260 0.0574 0.0701 0.1216 0.1888 0.1699 0.1250 0.1056 0.0553 0.0292 0.0190 0.0126 0.0050 0.0101 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1992 1 1 1 0 4 0.0028 0.0162 0.0566 0.1095 0.1007 0.1461 0.1723 0.1291 0.0923 0.0753 0.0395 0.0227 0.0164 0.0077 0.0128 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1993 1 1 1 0 4 0.0035 0.0074 0.0348 0.0823 0.1371 0.1219 0.1291 0.1459 0.1197 0.0798 0.0592 0.0330 0.0172 0.0110 0.0183 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1994 1 1 1 0 4 0.0066 0.0133 0.0265 0.0490 0.0954 0.1461 0.1318 0.1284 0.1330 0.1006 0.0695 0.0439 0.0246 0.0109 0.0203 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1995 1 1 1 0 4 0.0059 0.0177 0.0599 0.0571 0.0885 0.1391 0.1623 0.1183 0.1125 0.0843 0.0538 0.0346 0.0259 0.0132 0.0268 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1996 1 1 1 0 4 0.0030 0.0126 0.0449 0.1225 0.0942 0.1136 0.1509 0.1414 0.0917 0.0690 0.0579 0.0397 0.0223 0.0134 0.0231 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1997 1 1 1 0 4 0.0052 0.0160 0.0423 0.1020 0.1781 0.1113 0.1204 0.1149 0.0965 0.0565 0.0464 0.0383 0.0236 0.0179 0.0306 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1998 1 1 1 0 4 0.0022 0.0088 0.0282 0.0544 0.1334 0.2181 0.1091 0.0981 0.0976 0.0722 0.0467 0.0349 0.0321 0.0206 0.0436 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1999 1 1 1 0 4 0.0026 0.0060 0.0170 0.0414 0.0691 0.1477 0.2165 0.0981 0.0842 0.0791 0.0655 0.0411 0.0380 0.0291 0.0647 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2000 1 1 1 0 4 0.0051 0.0075 0.0211 0.0338 0.0632 0.0930 0.1460 0.2367 0.0879 0.0580 0.0510 0.0501 0.0333 0.0263 0.0869 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2001 1 1 1 0 4 0.0018 0.0083 0.0173 0.0353 0.0488 0.0788 0.1057 0.1701 0.1959 0.0840 0.0458 0.0422 0.0363 0.0291 0.1006 ## 0.0000 0.0000 0.0000 0.0000 0.0000 2002 1 1 1 0 2 0.0038 0.0129 0.0380 0.0326 0.0506 0.0570 0.0721 0.0877 0.1285 0.1691 0.0905 0.0510 0.0453 0.0401 0.0278 0.0217 0.0190 0.0163 0.0111 0.0250 2003 1 1 1 0 2 0.0058 0.0160 0.0477 0.0811 0.0562 0.0595 0.0680 0.0688 0.0887 0.1136 0.1284 0.0758 0.0423 0.0350 0.0341 0.0208 0.0119 0.0141 0.0102 0.0220 2004 1 1 1 0 2 0.0158 0.0156 0.0371 0.0902 0.1056 0.0659 0.0641 0.0679 0.0615 0.0782 0.0985 0.1008 0.0536 0.0346 0.0276 0.0280 0.0161 0.0099 0.0091 0.0200 diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 50b39ea7..ad775464 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -30,7 +30,7 @@ require(reshape2) p <- p + geom_point(alpha=0.75,aes(colour=factor(BroodYear))) p <- p + scale_size_area(max_size=10) p <- p + labs(x="Year",y="Age",size="Count") - p <- p + facet_wrap(~Model+Sex+Gear,scales="free") + p <- p + facet_wrap(~Model+Sex+Gear+AgeErr,scales="free") p <- p + scale_colour_discrete(guide="none") print(p + .THEME) } @@ -57,7 +57,7 @@ require(reshape2) p <- p + geom_point(alpha=0.75) p <- p + scale_size_area(max_size=10) p <- p + labs(x="Year",y="Age",size="Residual",colour="Sign") - p <- p + facet_wrap(~Model+Sex+Gear,scales="free") + p <- p + facet_wrap(~Model+Sex+Gear+Err,scales="free") print(p + .THEME) } @@ -67,6 +67,7 @@ require(reshape2) n <- length(M) cat(".plotAgeSummary\n") mdf <- NULL + cat("length of M ",length(M),"\n") for( i in 1:n ) { age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) @@ -91,14 +92,14 @@ require(reshape2) colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","Err",paste(age)) mdf <- rbind(mdf,df) } - mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex","Err")) + mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex","Err"),measured.vars=age) print(head(mdf,3)) - p <- ggplot( mdf,aes(variable,value,col=Type) ) + p <- ggplot( mdf,aes(variable,value,col=Type,shape=factor(Sex)) ) p <- p + geom_point(alpha=0.75) # p <- p + scale_area(range = c(0,10)) - p <- p + labs(x="Age",y="Mean proportion",colour="Type") - p <- p + facet_wrap(~Model+Sex+Gear,scales="free") + p <- p + labs(x="Age",y="Mean proportion",colour="Type",shape="Sex") + p <- p + facet_wrap(~Model+Sex+Gear+Err,scales="free") print(p + .THEME) } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index c09c4a59..bbf0f35e 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2557,6 +2557,8 @@ FUNCTION calcComposition { dvar_vector pred_ca = ca * age_age(e); A_hat(kk)(ii) = pred_ca(n_A_sage(kk),n_A_nage(kk)); + + // predicted plus group age. if( n_A_nage(kk) < nage ) { A_hat(kk)(ii)(n_A_nage(kk)) += sum( pred_ca(n_A_nage(kk)+1,nage) ); @@ -3134,7 +3136,7 @@ FUNCTION calcObjectiveFunction // | - Two options based on d_iscamCntrl(14): // | - 1 -> multivariate logistic using conditional MLE of the variance for weight. // | - 2 -> multnomial, assumes input sample size as n in n log(p) - // | - 3 -> logistic normal w no autocorrelation. + // | - 3 -> logistic normal w no autocorrelation. // | - Both likelihoods pool pmin (d_iscamCntrl(16)) into adjacent yearclass. // | - PSEUDOCODE: // | - => first determine appropriate dimensions for each of nAgears arrays (naa) @@ -3145,7 +3147,7 @@ FUNCTION calcObjectiveFunction // | [ ] - change A_nu to data-type variable, does not need to be differentiable. // | [ ] - issue 29. Fix submatrix O, P for prospective analysis & sex/area/group. - // Testing new abstract compositionLikelihood class. + // Testing new abstract compositionLikelihood class. SUXS. //acl::negLogLikelihood *ptr_AgeCompLike[nAgears-1]; @@ -3178,8 +3180,6 @@ FUNCTION calcObjectiveFunction P(ii) = A_hat(k)(i).sub(n_A_sage(k),n_A_nage(k)); ii ++; } - //if( iyr <= nyr ) naa++; - //if( iyr < syr ) iaa++; } @@ -3198,10 +3198,10 @@ FUNCTION calcObjectiveFunction { case 1: // multivariate Logistic nlvec(4,k) = dmvlogistic(O,P,nu,age_tau2(k),dMinP(k)); - //cout<<"like: "<(O,P,dMinP(k)); - //nlvec(4,k) = ptr_AgeCompLike[k-1] -> nloglike(); - //nu = ptr_AgeCompLike[k-1] -> residual(); + // cout<<"like: "<(O,P,dMinP(k)); + // nlvec(4,k) = ptr_AgeCompLike[k-1] -> nloglike(); + // nu = ptr_AgeCompLike[k-1] -> residual(); break; @@ -4668,6 +4668,14 @@ REPORT_SECTION if(n_A_nobs(nAgears) > 0) { + for(k = 1; k<=nAgears; k++) + { + adstring lbl = "d3_A"+str(k); + report< Date: Fri, 3 Apr 2015 18:35:59 -0700 Subject: [PATCH 30/61] Nearly fixed all age comp plots, need to fix age labels on plotAgeSummary --- src/R/lib/plotAgeComps.R | 184 +++++++++++++++++++++++++++------------ src/admb-code/iscam.tpl | 17 +++- 2 files changed, 144 insertions(+), 57 deletions(-) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index ad775464..8e11dcde 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -1,36 +1,58 @@ # Rscript for plotting age-comp bubble plots. # Steven Martell # Aug 28, 2012 -require(ggplot2) -require(reshape2) +library(ggplot2) +library(reshape2) .plotAgeComps <- function( M ) { n <- length(M) cat(".plotAgeComps\n") + id <- grep("d3_A[1-9]",names(M[[1]])) mdf <- NULL for( i in 1:n ) { - A <- data.frame(M[[i]]$d3_A) - # Ensure proportions are being plotted. - A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) - age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) - # year gear area group sex - A <- data.frame(Model=names(M)[i],A) - colnames(A) <- c("Model","Year","Gear","Area","Group","Sex","AgeErr",paste(age)) - mdf <- rbind(mdf,A) + + getDF <- function(x) + { + ix <- id[x] + + df <- data.frame(M[[i]][ix]) + df <- data.frame(Model=names(M)[i],df) + age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) + colnames(df) <- c("Model","Year","Gear","Area","Group","Sex","AgeErr",paste(age)) + + return(df) + } + + B <- lapply(1:length(id),getDF) + + + + # A <- data.frame(M[[i]]$d3_A) + # # Ensure proportions are being plotted. + # A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) + # age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) + # # year gear area group sex + # A <- data.frame(Model=names(M)[i],A) + # colnames(A) <- c("Model","Year","Gear","Area","Group","Sex","AgeErr",paste(age)) + # mdf <- rbind(mdf,A) } - mdf <- melt(mdf,id.vars=c("Model","Year","Gear","Area","Group","Sex","AgeErr")) - BroodYear <- mdf$Year-as.double(mdf$variable) - mdf <- cbind(mdf,BroodYear) - print(head(mdf,3)) + mB <- melt(B,id.vars=c("Model","Year","Gear","Area","Group","Sex","AgeErr")) + BroodYear <- mB$Year-as.double(mB$variable) + mB <- cbind(mB,BroodYear) + + # mdf <- melt(mdf,id.vars=c("Model","Year","Gear","Area","Group","Sex","AgeErr")) + # BroodYear <- mdf$Year-as.double(mdf$variable) + # mdf <- cbind(mdf,BroodYear) + # print(head(mdf,3)) - p <- ggplot(mdf,aes(factor(Year),variable,size=value)) + p <- ggplot(mB,aes((Year),variable,size=value)) p <- p + geom_point(alpha=0.75,aes(colour=factor(BroodYear))) - p <- p + scale_size_area(max_size=10) + p <- p + scale_size_area(max_size=5) p <- p + labs(x="Year",y="Age",size="Count") - p <- p + facet_wrap(~Model+Sex+Gear+AgeErr,scales="free") + p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") p <- p + scale_colour_discrete(guide="none") print(p + .THEME) } @@ -39,25 +61,47 @@ require(reshape2) { n <- length(M) cat(".plotAgeCompResiduals\n") + id <- grep("d3_A[1-9]",names(M[[1]])) + iu <- grep("A_nu[1-9]",names(M[[1]])) mdf <- NULL for( i in 1:n ) { - A <- cbind(M[[i]]$d3_A[,1:6],M[[i]]$A_nu) - A <- data.frame(A) - age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) - # year gear area group sex - A <- data.frame(Model=names(M)[i],A) - colnames(A) <- c("Model","Year","Gear","Area","Group","Sex","Err",paste(age)) - mdf <- rbind(mdf,subset(A,A$Year>=M[[i]]$syr)) + getDF <- function(x) + { + ix <- id[x] + jx <- iu[x] + + df <- data.frame(M[[i]][[ix]][,1:6],M[[i]][jx]) + df <- data.frame(Model=names(M)[i],df) + age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) + colnames(df) <- c("Model","Year","Gear","Area","Group","Sex","AgeErr",paste(age)) + + return(df) + } + + B <- lapply(1:length(id),getDF) + + + + # A <- cbind(M[[i]]$d3_A[,1:6],M[[i]]$A_nu) + # A <- data.frame(A) + # age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) + # # year gear area group sex + # A <- data.frame(Model=names(M)[i],A) + # colnames(A) <- c("Model","Year","Gear","Area","Group","Sex","Err",paste(age)) + # mdf <- rbind(mdf,subset(A,A$Year>=M[[i]]$syr)) } - mdf <- melt(mdf,id.vars=c("Model","Year","Gear","Area","Group","Sex","Err")) - print(head(mdf,3)) - p <- ggplot(mdf,aes(factor(Year),variable,col=factor(sign(value)),size=abs(value))) + mB <- melt(B,id.vars=c("Model","Year","Gear","Area","Group","Sex","AgeErr")) + + # mdf <- melt(mdf,id.vars=c("Model","Year","Gear","Area","Group","Sex","Err")) + # print(head(mdf,3)) + + p <- ggplot(mB,aes((Year),variable,col=factor(sign(value)),size=abs(value))) p <- p + geom_point(alpha=0.75) - p <- p + scale_size_area(max_size=10) + p <- p + scale_size_area(max_size=5) p <- p + labs(x="Year",y="Age",size="Residual",colour="Sign") - p <- p + facet_wrap(~Model+Sex+Gear+Err,scales="free") + p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") print(p + .THEME) } @@ -66,40 +110,72 @@ require(reshape2) { n <- length(M) cat(".plotAgeSummary\n") + id <- grep("d3_A[1-9]",names(M[[1]])) + iu <- grep("A_hat[1-9]",names(M[[1]])) mdf <- NULL cat("length of M ",length(M),"\n") for( i in 1:n ) { - age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) - - # Predicted data - A <- cbind(M[[i]]$d3_A[,1:6],M[[i]]$A_hat) - A <- data.frame(A) - A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) - agA <- aggregate(A[,-1:-6],by=list(A[,2],A[,3],A[,4],A[,5],A[,6]),FUN=mean,na.rm=TRUE) - colnames(agA) = c("Gear","Area","Group","Sex","Err",paste(age)) - - # Observed data - O <- data.frame(M[[i]]$d3_A) - O[,-1:-6] <- O[,-1:-6]/rowSums(O[,-1:-6],na.rm=TRUE) - agO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],A[,4],O[,5],O[,6]),FUN=mean,na.rm=TRUE) - colnames(agO) = c("Gear","Area","Group","Sex","Err",paste(age)) - - # Create data frame - df <- rbind(cbind(type="Predicted",agA),cbind(type="Observed",agO)) - # year gear area group sex - df <- data.frame(Model=names(M)[i],df) - colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","Err",paste(age)) - mdf <- rbind(mdf,df) + + getDF <- function(x) + { + ix <- id[x] + jx <- iu[x] + + P <- data.frame(M[[i]][[ix]][,1:6],M[[i]][jx]) + age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) + aP <- aggregate(P[,-1:-6],by=list(P[,2],P[,3],P[,4],P[,5],P[,6]),FUN=mean,na.rm=TRUE) + colnames(aP) <- c("Gear","Area","Group","Sex","AgeErr",paste(age)) + + O <- data.frame(M[[i]][[ix]]) + age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) + aO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],O[,4],O[,5],O[,6]),FUN=mean,na.rm=TRUE) + colnames(aO) <- c("Gear","Area","Group","Sex","AgeErr",paste(age)) + + # create data frame + df <- cbind(data.frame(Type="Predicted",aP),data.frame(Type="Observed",aO)) + df <- data.frame(Model=names(M)[i],df) + return(df) + } + + B <- lapply(1:length(id),getDF) + + + + + # age <- seq(min(M[[i]]$n_A_sage),max(M[[i]]$n_A_nage)) + + # # Predicted data + # A <- cbind(M[[i]]$d3_A[,1:6],M[[i]]$A_hat) + # A <- data.frame(A) + # A[,-1:-6] <- A[,-1:-6]/rowSums(A[,-1:-6],na.rm=TRUE) + # agA <- aggregate(A[,-1:-6],by=list(A[,2],A[,3],A[,4],A[,5],A[,6]),FUN=mean,na.rm=TRUE) + # colnames(agA) = c("Gear","Area","Group","Sex","Err",paste(age)) + + # # Observed data + # O <- data.frame(M[[i]]$d3_A) + # O[,-1:-6] <- O[,-1:-6]/rowSums(O[,-1:-6],na.rm=TRUE) + # agO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],A[,4],O[,5],O[,6]),FUN=mean,na.rm=TRUE) + # colnames(agO) = c("Gear","Area","Group","Sex","Err",paste(age)) + + # # Create data frame + # df <- rbind(cbind(type="Predicted",agA),cbind(type="Observed",agO)) + # # year gear area group sex + # df <- data.frame(Model=names(M)[i],df) + # colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","Err",paste(age)) + # mdf <- rbind(mdf,df) } - mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex","Err"),measured.vars=age) - print(head(mdf,3)) - p <- ggplot( mdf,aes(variable,value,col=Type,shape=factor(Sex)) ) + mB <- melt(B,id.vars=c("Model","Type","Gear","Area","Group","Sex","AgeErr"),measured.vars=age) + + # mdf <- melt(mdf,id.vars=c("Model","Type","Gear","Area","Group","Sex","Err"),measured.vars=age) + # print(head(mdf,3)) + + p <- ggplot( mB,aes(variable,value,col=Type,shape=factor(Sex)) ) p <- p + geom_point(alpha=0.75) # p <- p + scale_area(range = c(0,10)) p <- p + labs(x="Age",y="Mean proportion",colour="Type",shape="Sex") - p <- p + facet_wrap(~Model+Sex+Gear+Err,scales="free") + p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") print(p + .THEME) } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index bbf0f35e..523e33ac 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -4668,16 +4668,27 @@ REPORT_SECTION if(n_A_nobs(nAgears) > 0) { + REPORT(n_A_sage); + REPORT(n_A_nage); + for(k = 1; k<=nAgears; k++) { adstring lbl = "d3_A"+str(k); report< Date: Fri, 3 Apr 2015 20:51:03 -0700 Subject: [PATCH 31/61] FIxed axis on plotAgeSummary.R --- src/R/lib/plotAgeComps.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 8e11dcde..04a33e3c 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -133,8 +133,10 @@ library(reshape2) colnames(aO) <- c("Gear","Area","Group","Sex","AgeErr",paste(age)) # create data frame - df <- cbind(data.frame(Type="Predicted",aP),data.frame(Type="Observed",aO)) + df <- rbind(data.frame(Type="Predicted",aP),data.frame(Type="Observed",aO)) df <- data.frame(Model=names(M)[i],df) + colnames(df) <- c("Model","Type","Gear","Area","Group","Sex","AgeErr",paste(age)) + return(df) } From 745d7bae62d5807384152422c890faf331581140 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 3 Apr 2015 21:07:36 -0700 Subject: [PATCH 32/61] FIxed more Rscrpts for autmated ploting. Parse Halibut age comps by age 20 and 25 --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 16 +++--- fba/HALIBUT/DATA/Halibut2014.dat | 60 +++++++++++------------ src/R/lib/plotCatchResiduals.R | 2 +- src/R/lib/plotRecruitmentResiduals.R | 2 +- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index d4d03dbf..20795d3f 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -37,14 +37,14 @@ ## -6 : multinomial with estimated effective sample size. ## ------------------------------------------------------------------------- ## ## Number of columns == na_gears. - 1 1 6 6 ## : Gear Index - 1 1 1 1 ## : Likelihood type - 0.000 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression - 0.0000 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize - -1 -1 -1 -1 ## : phase for log_age_tau2 estimation. - -2 -2 -2 -2 ## : phase for phi1 estimation : bounded (-1,1) AR1 - -2 -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 - 2 2 2 2 ## : phase for degrees of freedom for student T. + 1 1 6 6 6 6 ## : Gear Index + 1 1 1 1 1 1 ## : Likelihood type + 0.000 0.000 0.000 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression + 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize + -1 -1 -1 -1 -1 -1 ## : phase for log_age_tau2 estimation. + -2 -2 -2 -2 -2 -2 ## : phase for phi1 estimation : bounded (-1,1) AR1 + -2 -2 -2 -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 + 2 2 2 2 2 2 ## : phase for degrees of freedom for student T. -12345 ## : int check (-12345) ## ------------------------------------------------------------------------- ## diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index 1c1dff78..7b22f6b5 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -522,16 +522,16 @@ ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## ## ------------------------------------------------------------------------- ## -4 # Number of gears with age-comps int(na_gears) -67 13 26 26 # Number of rows in the matrix ivector(na_gears) +6 # Number of gears with age-comps int(na_gears) +67 13 12 14 12 14 # Number of rows in the matrix ivector(na_gears) ## ivector(na_gears) of youngest age-class -6 6 6 6 +6 6 6 6 6 6 ## ivector(na_gears) of oldest age-class + group -20 25 25 25 +20 25 20 25 20 25 ## Effective sample size from iterative re-weighting (nscaler) -50 111.4450 28.7800 43.9589 +50 50 50 50 50 50 ## Age Flag (0=length comps, 1 = age comps) -1 1 1 1 +1 1 1 1 1 1 ## commercial catches ## year gear area group sex age_err | data columns (numbers or proportions) 1935 1 1 1 0 4 0.1085 0.1645 0.1479 0.1896 0.1486 0.0762 0.0610 0.0375 0.0225 0.0165 0.0112 0.0055 0.0044 0.0021 0.0041 ## 0.0000 0.0000 0.0000 0.0000 0.0000 @@ -616,19 +616,19 @@ 2014 1 1 1 0 2 0.0022 0.0043 0.0144 0.0582 0.1035 0.1241 0.1569 0.1317 0.1078 0.0915 0.0529 0.0354 0.0285 0.0174 0.0149 0.0086 0.0081 0.0073 0.0071 0.0252 ## survey female ## year gear area group sex age_err | data columns (numbers or proportions) - 1980 6 1 1 1 4 0.0292 0.0363 0.0740 0.0861 0.0917 0.0755 0.0688 0.0551 0.0454 0.0225 0.0187 0.0188 0.0090 0.0065 0.0150 0.0000 0.0000 0.0000 0.0000 0.0000 - 1981 6 1 1 1 4 0.0535 0.0246 0.0522 0.0731 0.0711 0.0634 0.0664 0.0621 0.0432 0.0307 0.0246 0.0198 0.0144 0.0082 0.0151 0.0000 0.0000 0.0000 0.0000 0.0000 - 1982 6 1 1 1 4 0.0462 0.0467 0.0630 0.1072 0.0994 0.0792 0.0706 0.0509 0.0279 0.0177 0.0121 0.0078 0.0076 0.0080 0.0121 0.0000 0.0000 0.0000 0.0000 0.0000 - 1983 6 1 1 1 4 0.0584 0.0556 0.0608 0.0604 0.0723 0.0690 0.0580 0.0665 0.0407 0.0298 0.0157 0.0102 0.0078 0.0051 0.0119 0.0000 0.0000 0.0000 0.0000 0.0000 - 1984 6 1 1 1 4 0.0295 0.0444 0.0566 0.0505 0.0521 0.0720 0.0505 0.0319 0.0320 0.0229 0.0143 0.0123 0.0091 0.0088 0.0196 0.0000 0.0000 0.0000 0.0000 0.0000 - 1985 6 1 1 1 4 0.0308 0.0280 0.0734 0.0625 0.0594 0.0459 0.0549 0.0457 0.0316 0.0257 0.0108 0.0095 0.0049 0.0062 0.0218 0.0000 0.0000 0.0000 0.0000 0.0000 - 1986 6 1 1 1 4 0.0267 0.0306 0.0375 0.0589 0.0553 0.0510 0.0461 0.0539 0.0402 0.0333 0.0227 0.0140 0.0121 0.0086 0.0380 0.0000 0.0000 0.0000 0.0000 0.0000 - 1996 6 1 1 1 4 0.0126 0.0207 0.0567 0.0961 0.0524 0.0694 0.0836 0.0665 0.0508 0.0342 0.0261 0.0191 0.0090 0.0065 0.0077 0.0000 0.0000 0.0000 0.0000 0.0000 - 1997 6 1 1 1 4 0.0057 0.0173 0.0262 0.0646 0.1270 0.0654 0.0628 0.0581 0.0481 0.0232 0.0212 0.0169 0.0096 0.0082 0.0076 0.0000 0.0000 0.0000 0.0000 0.0000 + 1980 6 1 1 1 4 0.0292 0.0363 0.0740 0.0861 0.0917 0.0755 0.0688 0.0551 0.0454 0.0225 0.0187 0.0188 0.0090 0.0065 0.0150 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1981 6 1 1 1 4 0.0535 0.0246 0.0522 0.0731 0.0711 0.0634 0.0664 0.0621 0.0432 0.0307 0.0246 0.0198 0.0144 0.0082 0.0151 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1982 6 1 1 1 4 0.0462 0.0467 0.0630 0.1072 0.0994 0.0792 0.0706 0.0509 0.0279 0.0177 0.0121 0.0078 0.0076 0.0080 0.0121 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1983 6 1 1 1 4 0.0584 0.0556 0.0608 0.0604 0.0723 0.0690 0.0580 0.0665 0.0407 0.0298 0.0157 0.0102 0.0078 0.0051 0.0119 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1984 6 1 1 1 4 0.0295 0.0444 0.0566 0.0505 0.0521 0.0720 0.0505 0.0319 0.0320 0.0229 0.0143 0.0123 0.0091 0.0088 0.0196 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1985 6 1 1 1 4 0.0308 0.0280 0.0734 0.0625 0.0594 0.0459 0.0549 0.0457 0.0316 0.0257 0.0108 0.0095 0.0049 0.0062 0.0218 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1986 6 1 1 1 4 0.0267 0.0306 0.0375 0.0589 0.0553 0.0510 0.0461 0.0539 0.0402 0.0333 0.0227 0.0140 0.0121 0.0086 0.0380 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1996 6 1 1 1 4 0.0126 0.0207 0.0567 0.0961 0.0524 0.0694 0.0836 0.0665 0.0508 0.0342 0.0261 0.0191 0.0090 0.0065 0.0077 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1997 6 1 1 1 4 0.0057 0.0173 0.0262 0.0646 0.1270 0.0654 0.0628 0.0581 0.0481 0.0232 0.0212 0.0169 0.0096 0.0082 0.0076 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1999 6 1 1 1 4 0.0068 0.0144 0.0228 0.0390 0.0491 0.0886 0.1125 0.0564 0.0476 0.0332 0.0221 0.0130 0.0102 0.0067 0.0117 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2000 6 1 1 1 4 0.0118 0.0110 0.0226 0.0361 0.0465 0.0594 0.0897 0.1106 0.0455 0.0308 0.0248 0.0189 0.0115 0.0068 0.0175 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2001 6 1 1 1 4 0.0096 0.0166 0.0180 0.0248 0.0339 0.0519 0.0549 0.0833 0.0921 0.0572 0.0333 0.0187 0.0136 0.0087 0.0118 ## 0.0000 0.0000 0.0000 0.0000 0.0000 1998 6 1 1 1 2 0.0069 0.0121 0.0177 0.0272 0.0487 0.1145 0.0622 0.0447 0.0528 0.0368 0.0225 0.0153 0.0161 0.0137 0.0095 0.0053 0.0037 0.0015 0.0026 0.0043 - 1999 6 1 1 1 4 0.0068 0.0144 0.0228 0.0390 0.0491 0.0886 0.1125 0.0564 0.0476 0.0332 0.0221 0.0130 0.0102 0.0067 0.0117 0.0000 0.0000 0.0000 0.0000 0.0000 - 2000 6 1 1 1 4 0.0118 0.0110 0.0226 0.0361 0.0465 0.0594 0.0897 0.1106 0.0455 0.0308 0.0248 0.0189 0.0115 0.0068 0.0175 0.0000 0.0000 0.0000 0.0000 0.0000 - 2001 6 1 1 1 4 0.0096 0.0166 0.0180 0.0248 0.0339 0.0519 0.0549 0.0833 0.0921 0.0572 0.0333 0.0187 0.0136 0.0087 0.0118 0.0000 0.0000 0.0000 0.0000 0.0000 2002 6 1 1 1 2 0.0113 0.0303 0.0418 0.0265 0.0319 0.0358 0.0443 0.0440 0.0666 0.0760 0.0447 0.0259 0.0155 0.0139 0.0103 0.0062 0.0063 0.0042 0.0030 0.0058 2003 6 1 1 1 2 0.0170 0.0286 0.0523 0.0662 0.0394 0.0300 0.0392 0.0364 0.0440 0.0501 0.0534 0.0314 0.0170 0.0119 0.0088 0.0085 0.0036 0.0045 0.0031 0.0057 2004 6 1 1 1 2 0.0233 0.0264 0.0438 0.0678 0.0555 0.0324 0.0339 0.0275 0.0295 0.0339 0.0334 0.0299 0.0161 0.0097 0.0064 0.0055 0.0033 0.0023 0.0016 0.0039 @@ -644,19 +644,19 @@ 2014 6 1 1 1 2 0.0051 0.0119 0.0409 0.0986 0.0995 0.0750 0.0742 0.0565 0.0488 0.0339 0.0141 0.0098 0.0065 0.0047 0.0026 0.0014 0.0008 0.0010 0.0005 0.0030 ## survey male ## year gear area group sex age_err | data columns (numbers or proportions) - 1980 6 1 1 2 4 0.0174 0.0433 0.0462 0.0488 0.0444 0.0482 0.0315 0.0200 0.0155 0.0091 0.0077 0.0031 0.0036 0.0037 0.0048 0.0000 0.0000 0.0000 0.0000 0.0000 - 1981 6 1 1 2 4 0.0503 0.0396 0.0576 0.0501 0.0457 0.0435 0.0305 0.0225 0.0150 0.0072 0.0075 0.0013 0.0028 0.0018 0.0022 0.0000 0.0000 0.0000 0.0000 0.0000 - 1982 6 1 1 2 4 0.0270 0.0313 0.0439 0.0722 0.0461 0.0314 0.0308 0.0210 0.0149 0.0105 0.0064 0.0028 0.0020 0.0011 0.0022 0.0000 0.0000 0.0000 0.0000 0.0000 - 1983 6 1 1 2 4 0.0369 0.0408 0.0429 0.0502 0.0634 0.0496 0.0274 0.0241 0.0123 0.0096 0.0091 0.0041 0.0021 0.0023 0.0031 0.0000 0.0000 0.0000 0.0000 0.0000 - 1984 6 1 1 2 4 0.0399 0.0566 0.0553 0.0642 0.0662 0.0692 0.0458 0.0286 0.0240 0.0163 0.0106 0.0064 0.0020 0.0022 0.0064 0.0000 0.0000 0.0000 0.0000 0.0000 - 1985 6 1 1 2 4 0.0241 0.0415 0.0811 0.0669 0.0609 0.0574 0.0644 0.0387 0.0188 0.0113 0.0089 0.0067 0.0030 0.0033 0.0023 0.0000 0.0000 0.0000 0.0000 0.0000 - 1986 6 1 1 2 4 0.0283 0.0281 0.0394 0.0761 0.0503 0.0452 0.0542 0.0479 0.0334 0.0216 0.0153 0.0121 0.0070 0.0041 0.0082 0.0000 0.0000 0.0000 0.0000 0.0000 - 1996 6 1 1 2 4 0.0062 0.0096 0.0277 0.0510 0.0323 0.0390 0.0490 0.0426 0.0339 0.0303 0.0244 0.0178 0.0110 0.0075 0.0061 0.0000 0.0000 0.0000 0.0000 0.0000 - 1997 6 1 1 2 4 0.0035 0.0073 0.0178 0.0400 0.0871 0.0390 0.0436 0.0446 0.0437 0.0290 0.0267 0.0207 0.0133 0.0076 0.0141 0.0000 0.0000 0.0000 0.0000 0.0000 + 1980 6 1 1 2 4 0.0174 0.0433 0.0462 0.0488 0.0444 0.0482 0.0315 0.0200 0.0155 0.0091 0.0077 0.0031 0.0036 0.0037 0.0048 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1981 6 1 1 2 4 0.0503 0.0396 0.0576 0.0501 0.0457 0.0435 0.0305 0.0225 0.0150 0.0072 0.0075 0.0013 0.0028 0.0018 0.0022 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1982 6 1 1 2 4 0.0270 0.0313 0.0439 0.0722 0.0461 0.0314 0.0308 0.0210 0.0149 0.0105 0.0064 0.0028 0.0020 0.0011 0.0022 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1983 6 1 1 2 4 0.0369 0.0408 0.0429 0.0502 0.0634 0.0496 0.0274 0.0241 0.0123 0.0096 0.0091 0.0041 0.0021 0.0023 0.0031 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1984 6 1 1 2 4 0.0399 0.0566 0.0553 0.0642 0.0662 0.0692 0.0458 0.0286 0.0240 0.0163 0.0106 0.0064 0.0020 0.0022 0.0064 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1985 6 1 1 2 4 0.0241 0.0415 0.0811 0.0669 0.0609 0.0574 0.0644 0.0387 0.0188 0.0113 0.0089 0.0067 0.0030 0.0033 0.0023 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1986 6 1 1 2 4 0.0283 0.0281 0.0394 0.0761 0.0503 0.0452 0.0542 0.0479 0.0334 0.0216 0.0153 0.0121 0.0070 0.0041 0.0082 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1996 6 1 1 2 4 0.0062 0.0096 0.0277 0.0510 0.0323 0.0390 0.0490 0.0426 0.0339 0.0303 0.0244 0.0178 0.0110 0.0075 0.0061 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1997 6 1 1 2 4 0.0035 0.0073 0.0178 0.0400 0.0871 0.0390 0.0436 0.0446 0.0437 0.0290 0.0267 0.0207 0.0133 0.0076 0.0141 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 1999 6 1 1 2 4 0.0041 0.0070 0.0126 0.0247 0.0383 0.0742 0.1031 0.0452 0.0380 0.0332 0.0295 0.0180 0.0134 0.0115 0.0132 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2000 6 1 1 2 4 0.0055 0.0070 0.0155 0.0197 0.0345 0.0475 0.0747 0.0836 0.0375 0.0316 0.0323 0.0219 0.0169 0.0102 0.0184 ## 0.0000 0.0000 0.0000 0.0000 0.0000 + 2001 6 1 1 2 4 0.0067 0.0093 0.0104 0.0171 0.0243 0.0330 0.0548 0.0764 0.0774 0.0460 0.0386 0.0294 0.0209 0.0135 0.0137 ## 0.0000 0.0000 0.0000 0.0000 0.0000 1998 6 1 1 2 2 0.0030 0.0035 0.0076 0.0170 0.0353 0.0716 0.0437 0.0319 0.0388 0.0377 0.0302 0.0323 0.0320 0.0261 0.0242 0.0167 0.0077 0.0058 0.0057 0.0111 - 1999 6 1 1 2 4 0.0041 0.0070 0.0126 0.0247 0.0383 0.0742 0.1031 0.0452 0.0380 0.0332 0.0295 0.0180 0.0134 0.0115 0.0132 0.0000 0.0000 0.0000 0.0000 0.0000 - 2000 6 1 1 2 4 0.0055 0.0070 0.0155 0.0197 0.0345 0.0475 0.0747 0.0836 0.0375 0.0316 0.0323 0.0219 0.0169 0.0102 0.0184 0.0000 0.0000 0.0000 0.0000 0.0000 - 2001 6 1 1 2 4 0.0067 0.0093 0.0104 0.0171 0.0243 0.0330 0.0548 0.0764 0.0774 0.0460 0.0386 0.0294 0.0209 0.0135 0.0137 0.0000 0.0000 0.0000 0.0000 0.0000 2002 6 1 1 2 2 0.0067 0.0139 0.0249 0.0166 0.0220 0.0222 0.0285 0.0326 0.0463 0.0709 0.0368 0.0244 0.0222 0.0233 0.0143 0.0112 0.0107 0.0095 0.0058 0.0129 2003 6 1 1 2 2 0.0062 0.0147 0.0324 0.0308 0.0227 0.0205 0.0266 0.0252 0.0332 0.0456 0.0489 0.0342 0.0209 0.0160 0.0183 0.0130 0.0109 0.0066 0.0066 0.0159 2004 6 1 1 2 2 0.0122 0.0134 0.0279 0.0516 0.0442 0.0224 0.0251 0.0303 0.0339 0.0358 0.0483 0.0510 0.0313 0.0185 0.0172 0.0138 0.0115 0.0057 0.0059 0.0138 diff --git a/src/R/lib/plotCatchResiduals.R b/src/R/lib/plotCatchResiduals.R index fa260b30..80a48ed5 100644 --- a/src/R/lib/plotCatchResiduals.R +++ b/src/R/lib/plotCatchResiduals.R @@ -19,7 +19,7 @@ require(reshape2) } print(head(mdf,3)) - p <- ggplot(mdf,aes(x=factor(Year),Residual,fill=factor(Gear))) + p <- ggplot(mdf,aes(x=(Year),Residual,fill=factor(Gear))) p <- p + geom_bar(width=0.75,position="dodge",stat='identity') p <- p + labs(x="Year",y="log residual") p <- p + facet_wrap(~Model,scales="free") diff --git a/src/R/lib/plotRecruitmentResiduals.R b/src/R/lib/plotRecruitmentResiduals.R index ee5d53f7..5b139684 100644 --- a/src/R/lib/plotRecruitmentResiduals.R +++ b/src/R/lib/plotRecruitmentResiduals.R @@ -30,7 +30,7 @@ require(reshape2) print(head(mdf,3)) print(tail(mdf,3)) - p <- ggplot(mdf,aes(x=factor(Year),Residual)) + p <- ggplot(mdf,aes(x=(Year),Residual)) p <- p + geom_bar(width=0.75,position="dodge",stat='identity') p <- p + labs(x="Year",y="Recruitment (log residual)") p <- p + facet_wrap(~Model,scales="free") From ebc13d20985257e57b4bffa4be79cdd5b5107753 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 3 Apr 2015 21:27:28 -0700 Subject: [PATCH 33/61] Stash --- src/admb-code/include/selex.hpp | 11 ++++++----- src/admb-code/iscam.tpl | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 7b3561c2..18acc49a 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -21,6 +21,12 @@ */ namespace slx { + template + const T plogis(const T &x, const T2 &mean, const T2 & sd) + { + return T2(1.0)/(T2(1.0)+exp(-(x-mean)/sd)); + } + /** * @ingroup Selectivities * @brief An abstract class for Selectivity functions. @@ -50,11 +56,6 @@ namespace slx { }; - template - const T plogis(const T &x, const T2 &mean, const T2 & sd) - { - return T2(1.0)/(T2(1.0)+exp(-(x-mean)/sd)); - } /** * @brief Logistic curve diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 523e33ac..a6e73d9b 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -478,7 +478,7 @@ DATA_SECTION if(!mseFlag) { cout< Date: Sat, 4 Apr 2015 13:00:13 -0700 Subject: [PATCH 34/61] Fixed legend in plotageSummary --- src/R/lib/plotAgeComps.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 04a33e3c..02165791 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -178,7 +178,7 @@ library(reshape2) # p <- p + scale_area(range = c(0,10)) p <- p + labs(x="Age",y="Mean proportion",colour="Type",shape="Sex") p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") - print(p + .THEME) + print(p + .THEME+theme(legend.position="top")) } # .plotAgecomps <- function(repObj, meanAge = FALSE ) From f7a8cc97c4b027efb9eda657acfaa3f7481b3d2c Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Sat, 4 Apr 2015 13:38:11 -0700 Subject: [PATCH 35/61] trimed the number of qdev parameters when conducting prospective analysis --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 2 +- src/admb-code/iscam.tpl | 33 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 20795d3f..417210d8 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -44,7 +44,7 @@ -1 -1 -1 -1 -1 -1 ## : phase for log_age_tau2 estimation. -2 -2 -2 -2 -2 -2 ## : phase for phi1 estimation : bounded (-1,1) AR1 -2 -2 -2 -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 - 2 2 2 2 2 2 ## : phase for degrees of freedom for student T. + -2 -2 -2 -2 -2 -2 ## : phase for degrees of freedom for student T. -12345 ## : int check (-12345) ## ------------------------------------------------------------------------- ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index a6e73d9b..a6d34f37 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -585,6 +585,7 @@ DATA_SECTION init_int nItNobs; ivector nSurveyIndex(1,nItNobs); + ivector qdev_count(1,nItNobs); init_ivector n_it_nobs(1,nItNobs); init_ivector n_survey_type(1,nItNobs); init_3darray d3_survey_data(1,nItNobs,1,n_it_nobs,1,9); @@ -611,6 +612,7 @@ DATA_SECTION it_log_pe(k) = column(d3_survey_data(k),8); it_grp(k)= column(d3_survey_data(k),5); nSurveyIndex(k) = d3_survey_data(k)(1,3); + qdev_count(k) = size_count(it_log_se(k)); } double tmp_mu = mean(it_wt); for(k=1;k<=nItNobs;k++) @@ -1205,10 +1207,10 @@ DATA_SECTION // | m_stdev -> Standard deviation for constraint. // | m_nNodes -> number of nodes for cubic spline. // | m_nodeyear -> position of the nodes. - int nMdev; + int nMdev; init_int m_type; init_int Mdev_phz; - init_number m_stdev; + init_number m_stdev; init_int m_nNodes; init_ivector m_nodeyear(1,m_nNodes); @@ -1345,6 +1347,7 @@ DATA_SECTION // | - adjust sel_blocks to new syr // | - Reduce ft_count so as not to bias estimates of ft. // | - Establish prospective counter for Composition data n_saa; + // | - Reduce qdev_count ivector n_saa(1,nAgears); @@ -1376,6 +1379,14 @@ DATA_SECTION if( iyr < syr ) n_saa(k)++; } } + + for( k = 1; k <= nItNobs; k++ ) + { + for( i = 1; i <= n_it_nobs(k); i++ ) + { + if( d3_survey_data(k)(i)(1) < syr) qdev_count(k) --; + } + } END_CALCS @@ -1548,7 +1559,11 @@ PARAMETER_SECTION // | DEVIATIONS IN CATCHABILITY COEFFICIENTS ASSUMING A RANDOM WALK | // |---------------------------------------------------------------------------------| // | - init_bounded_vector_vector log_q_devs(1,nItNobs,1,n_it_nobs,-5.0,5.0,q_phz); + //init_bounded_vector_vector log_q_devs(1,nItNobs,1,n_it_nobs,-5.0,5.0,q_phz); + !! COUT(n_it_nobs); + !! COUT(qdev_count); + //!! exit(1); + init_bounded_vector_vector log_q_devs(1,nItNobs,1,qdev_count,-5.0,5.0,q_phz); // |---------------------------------------------------------------------------------| @@ -2849,14 +2864,18 @@ FUNCTION calcSurveyObservations break; case 2: // Penalized random walk in Q + int jj = 1; // index for qdevs. zt -= log(t1(iz,nz)); - qt(kk)(iz) = exp( zt(iz) + log_q_devs(kk)(iz) ); + qt(kk)(iz) = exp( zt(iz) + log_q_devs(kk)(jj) ); for(ii=iz+1; ii<=nz; ii++) { - qt(kk)(ii) = qt(kk)(ii-1) * exp(log_q_devs(kk)(ii)); + jj ++; + qt(kk)(ii) = qt(kk)(ii-1) * exp(log_q_devs(kk)(jj)); + } it_hat(kk).sub(iz,nz) = elem_prod(qt(kk)(iz,nz),t1(iz,nz)); zt -= log(qt(kk)(iz,nz)); + //epsilon(kk).sub(iz,nz)= elem_div(zt,it_log_se(kk)(iz,nz)); break; } @@ -2867,8 +2886,8 @@ FUNCTION calcSurveyObservations // Standardized process error residuals. if(active(log_q_devs(kk))) { - dvar_vector fd_qt = first_difference( log_q_devs(kk)(iz,nz) ); - xi(kk).sub(iz,nz-1) = elem_div(fd_qt,it_log_pe(kk)(iz,nz-1)); + dvar_vector fd_qt = first_difference( log_q_devs(kk) ); + xi(kk).sub(iz,nz-1) = elem_div(fd_qt.shift(iz),it_log_pe(kk)(iz,nz-1)); } // TO BE DEPRECATED From 34a73105fc30f0cb8250aacf4e8466c6e71bf0cb Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Sat, 4 Apr 2015 13:41:44 -0700 Subject: [PATCH 36/61] Added retropsecitve adjustment to qdev_count --- src/admb-code/iscam.tpl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index a6d34f37..46fe46fe 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1328,6 +1328,14 @@ DATA_SECTION if( dCatchData(i)(1) > nyr ) ft_count --; } + for( k = 1; k <= nItNobs; k++ ) + { + for( i = 1; i <= n_it_nobs(k); i++ ) + { + if( d3_survey_data(k)(i)(1) > nyr) qdev_count(k) --; + } + } + // Retrospective counter for n_A_nobs n_naa.initialize(); for( k = 1; k <= nAgears; k++ ) From 74c8635e2b975e358d09df30a123a3acddbf9125 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 10 Apr 2015 15:29:12 -0700 Subject: [PATCH 37/61] Fixed the data file, wrong years for jumps in Q. --- fba/HALIBUT/DATA/DMVL1888/Halibut2014.ctl | 2 +- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 6 +-- fba/HALIBUT/DATA/Halibut2014.dat | 60 +++++++++++------------ fba/HALIBUT/R/R4iSCAM.R | 1 + src/R/lib/plotAgeComps.R | 12 ++--- src/admb-code/iscam.tpl | 23 +++++++-- 6 files changed, 59 insertions(+), 45 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1888/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1888/Halibut2014.ctl index 271153cc..94e2037c 100644 --- a/fba/HALIBUT/DATA/DMVL1888/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1888/Halibut2014.ctl @@ -125,7 +125,7 @@ 2.0 # 3 -std in observed catches in first phase. 1.0 # 4 -std in observed catches in last phase. 1 # 5 -Assume unfished in first year (0=FALSE, 1=TRUE) -0.00 # 6 -Minimum proportion to consider in age-proportions for dmvlogistic +1.00 # 6 -Maternal effects power parameter (1.0 = no maternal effects) 0.30 # 7 -Mean fishing mortality for regularizing the estimates of Ft 0.10 # 8 -std in mean fishing mortality in first phase 2.00 # 9 -std in mean fishing mortality in last phase diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 417210d8..5a0922cd 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -38,7 +38,7 @@ ## ------------------------------------------------------------------------- ## ## Number of columns == na_gears. 1 1 6 6 6 6 ## : Gear Index - 1 1 1 1 1 1 ## : Likelihood type + 2 2 2 2 2 2 ## : Likelihood type 0.000 0.000 0.000 0.000 0.000 0.000 ## : Minimum proportion for aggregation & compression 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 ## : Small constant to add to comps & renormalize -1 -1 -1 -1 -1 -1 ## : phase for log_age_tau2 estimation. @@ -128,8 +128,8 @@ 1.0 # 3 -std in observed catches in first phase. 1.0 # 4 -std in observed catches in last phase. 0 # 5 -Assume unfished in first year (0=FALSE, 1=TRUE) -0.00 # 6 -Minimum proportion to consider in age-proportions for dmvlogistic -0.40 # 7 -Mean fishing mortality for regularizing the estimates of Ft +1.00 # 6 -Maternal effects power parameter (1.0 = no maternal effects) +0.30 # 7 -Mean fishing mortality for regularizing the estimates of Ft 0.10 # 8 -std in mean fishing mortality in first phase 2.00 # 9 -std in mean fishing mortality in last phase -3 # 10 -DEPRECATED phase for estimating m_deviations (use -1 to turn off mdevs) diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index 7b22f6b5..9ba002c2 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -457,8 +457,8 @@ 1979 75 1 1 1 0 0.100 0.050 0.5 1980 94 1 1 1 0 0.100 0.050 0.5 1981 111 1 1 1 0 0.100 0.050 0.5 - 1982 127 1 1 1 0 0.100 0.050 0.5 - 1984 291 1 1 1 0 0.100 1.000 0.5 + 1982 127 1 1 1 0 0.100 2.000 0.5 + 1984 291 1 1 1 0 0.100 0.050 0.5 1985 357 1 1 1 0 0.036 0.050 0.5 1986 320 1 1 1 0 0.041 0.050 0.5 1987 321 1 1 1 0 0.040 0.050 0.5 @@ -490,34 +490,34 @@ 2013 179 1 1 1 0 0.017 0.050 0.5 2014 191 1 1 1 0 0.052 0.050 0.5 ## survey_data: - 1977 1.4713 6 1 1 0 0.100 0.010 0.5 - 1978 1.1112 6 1 1 0 0.100 0.010 0.5 - 1980 2.0090 6 1 1 0 0.100 0.010 0.5 - 1981 2.6670 6 1 1 0 0.100 0.010 0.5 - 1982 2.8739 6 1 1 0 0.100 1.000 0.5 - 1983 2.8816 6 1 1 0 0.100 0.010 0.5 - 1984 9.3014 6 1 1 0 0.100 1.000 0.5 - 1985 8.9419 6 1 1 0 0.100 0.010 0.5 - 1986 6.2568 6 1 1 0 0.100 0.010 0.5 - 1996 12.8858 6 1 1 0 0.100 0.010 0.5 - 1997 7.7841 6 1 1 0 0.034 1.000 0.5 - 1998 6.9727 6 1 1 0 0.034 0.010 0.5 - 1999 6.2649 6 1 1 0 0.034 0.010 0.5 - 2000 6.6265 6 1 1 0 0.034 0.010 0.5 - 2001 6.3842 6 1 1 0 0.028 0.010 0.5 - 2002 6.3893 6 1 1 0 0.026 0.010 0.5 - 2003 5.7876 6 1 1 0 0.027 0.010 0.5 - 2004 6.4579 6 1 1 0 0.026 0.010 0.5 - 2005 5.9282 6 1 1 0 0.027 0.010 0.5 - 2006 5.4306 6 1 1 0 0.027 0.010 0.5 - 2007 5.7267 6 1 1 0 0.027 0.010 0.5 - 2008 5.6536 6 1 1 0 0.026 0.010 0.5 - 2009 5.4952 6 1 1 0 0.027 0.010 0.5 - 2010 5.1239 6 1 1 0 0.029 0.010 0.5 - 2011 5.0435 6 1 1 0 0.029 0.010 0.5 - 2012 5.5606 6 1 1 0 0.030 0.010 0.5 - 2013 4.7301 6 1 1 0 0.034 0.010 0.5 - 2014 5.1645 6 1 1 0 0.032 0.010 0.5 + 1977 1.4713 6 1 1 0 0.100 0.020 0.5 + 1978 1.1112 6 1 1 0 0.100 0.020 0.5 + 1980 2.0090 6 1 1 0 0.100 0.020 0.5 + 1981 2.6670 6 1 1 0 0.100 1.020 0.5 + 1982 2.8739 6 1 1 0 0.100 0.020 0.5 + 1983 2.8816 6 1 1 0 0.100 1.020 0.5 + 1984 9.3014 6 1 1 0 0.100 0.020 0.5 + 1985 8.9419 6 1 1 0 0.100 0.020 0.5 + 1986 6.2568 6 1 1 0 0.100 0.020 0.5 + 1996 12.8858 6 1 1 0 0.100 1.020 0.5 + 1997 7.7841 6 1 1 0 0.034 0.020 0.5 + 1998 6.9727 6 1 1 0 0.034 0.020 0.5 + 1999 6.2649 6 1 1 0 0.034 0.020 0.5 + 2000 6.6265 6 1 1 0 0.034 0.020 0.5 + 2001 6.3842 6 1 1 0 0.028 0.020 0.5 + 2002 6.3893 6 1 1 0 0.026 0.020 0.5 + 2003 5.7876 6 1 1 0 0.027 0.020 0.5 + 2004 6.4579 6 1 1 0 0.026 0.020 0.5 + 2005 5.9282 6 1 1 0 0.027 0.020 0.5 + 2006 5.4306 6 1 1 0 0.027 0.020 0.5 + 2007 5.7267 6 1 1 0 0.027 0.020 0.5 + 2008 5.6536 6 1 1 0 0.026 0.020 0.5 + 2009 5.4952 6 1 1 0 0.027 0.020 0.5 + 2010 5.1239 6 1 1 0 0.029 0.020 0.5 + 2011 5.0435 6 1 1 0 0.029 0.020 0.5 + 2012 5.5606 6 1 1 0 0.030 0.020 0.5 + 2013 4.7301 6 1 1 0 0.034 0.020 0.5 + 2014 5.1645 6 1 1 0 0.032 0.020 0.5 ## ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## diff --git a/fba/HALIBUT/R/R4iSCAM.R b/fba/HALIBUT/R/R4iSCAM.R index 6d8fd4ad..c6ce937b 100644 --- a/fba/HALIBUT/R/R4iSCAM.R +++ b/fba/HALIBUT/R/R4iSCAM.R @@ -69,6 +69,7 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotStockRecruit( M ) .plotRecruitsPerSpawner( M ) .plotSurveyFit( M ) +.plotQ( M ) .plotCatchResidual( M ) .plotIndexResidual( M ) .plotRecruitmentResidual( M ) diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 02165791..37dd7a72 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -52,9 +52,9 @@ library(reshape2) p <- p + geom_point(alpha=0.75,aes(colour=factor(BroodYear))) p <- p + scale_size_area(max_size=5) p <- p + labs(x="Year",y="Age",size="Count") - p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") + p <- p + facet_wrap(~L1+Model+Gear+AgeErr+Sex,scales="free") p <- p + scale_colour_discrete(guide="none") - print(p + .THEME) + print(p + .THEME + theme(legend.position="top")) } .plotAgeCompResiduals <- function( M ) @@ -101,8 +101,8 @@ library(reshape2) p <- p + geom_point(alpha=0.75) p <- p + scale_size_area(max_size=5) p <- p + labs(x="Year",y="Age",size="Residual",colour="Sign") - p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") - print(p + .THEME) + p <- p + facet_wrap(~L1+Model+Gear+AgeErr+Sex,scales="free") + print(p + .THEME + theme(legend.position="top")) } @@ -177,8 +177,8 @@ library(reshape2) p <- p + geom_point(alpha=0.75) # p <- p + scale_area(range = c(0,10)) p <- p + labs(x="Age",y="Mean proportion",colour="Type",shape="Sex") - p <- p + facet_wrap(~Model+Sex+Gear+AgeErr+L1,scales="free") - print(p + .THEME+theme(legend.position="top")) + p <- p + facet_wrap(~L1+Model+Gear+AgeErr+Sex,scales="free") + print(p + .THEME + theme(legend.position="top")) } # .plotAgecomps <- function(repObj, meanAge = FALSE ) diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 46fe46fe..95a31478 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1245,7 +1245,7 @@ DATA_SECTION // | 3 -> std in catch first phase // | 4 -> std in catch in last phase // | 5 -> assumed unfished in first year (0=FALSE, 1=TRUE) - // | 6 -> Maternal effects power parameter. + // | 6 -> Maternal effects power parameter (1=no maternal effects). // | 7 -> mean fishing mortality rate to regularize the solution // | 8 -> standard deviation of mean F penalty in first phases // | 9 -> standard deviation of mean F penalty in last phase. @@ -1557,8 +1557,8 @@ PARAMETER_SECTION // | then natural mortality rate deviates are not estimated and M is assumed const. // | - This model is implemented as a random walk, where M{t+1} = M{t} + dev. - !! int m_dev_phz = -1; - !! m_dev_phz = d_iscamCntrl(10); + //!! int m_dev_phz = -1; + //!! m_dev_phz = d_iscamCntrl(10); //!! int n_m_devs = d_iscamCntrl(12); //init_bounded_vector log_m_nodes(1,n_m_devs,-5.0,5.0,m_dev_phz); init_bounded_vector log_m_nodes(1,nMdev,-5.0,5.0,Mdev_phz); @@ -1729,6 +1729,7 @@ PARAMETER_SECTION sdreport_vector sd_depletion(1,ngroup); sdreport_matrix sd_log_sbt(1,ngroup,syr,nyr+1); + PRELIMINARY_CALCS_SECTION @@ -1850,6 +1851,9 @@ FUNCTION void calcSdreportVariables() sd_log_sbt(g) = log(sbt(g)); } + + + if( verbose ) { cout<<"**** Ok after calcSdreportVariables ****"< nyr) continue; + // total numbers-at-age + // ta.initialize(); + // for( h = 1; h <= nsex; h++ ) + // { + // ig = pntr_ags(f,g,h); + // ta += N(ig)(i); + // } + if( h ) // age comps are sexed (h > 0) { ig = pntr_ags(f,g,h); From 38904bfb007c4b2fcc40e847451cbdfe97e90b61 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 10 Apr 2015 15:29:49 -0700 Subject: [PATCH 38/61] Added qdeve plot --- src/R/lib/plotQ.R | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/R/lib/plotQ.R diff --git a/src/R/lib/plotQ.R b/src/R/lib/plotQ.R new file mode 100644 index 00000000..96d2d4a6 --- /dev/null +++ b/src/R/lib/plotQ.R @@ -0,0 +1,40 @@ +# plotQ.R +# Steve Martell +# April 10, 2015 + + +.plotQ <- function ( M ) +{ + n <- length(M) + cat(".plotQ\n") + mdf <- NULL + for( i in 1:n ) + { + fit = M[[i]]$fit + yr = M[[i]]$d3_survey_data[,1] + kk = M[[i]]$d3_survey_data[,3] + + qt = M[[i]]$qt + qt = na.omit(as.vector(t(qt))) + ln.qt.mu = fit$est[grep("log_q_devs",fit$names)] + ln.qt.sd = fit$std[grep("log_q_devs",fit$names)] + ub = ln.qt.mu + 1.96 * ln.qt.sd + lb = ln.qt.mu - 1.96 * ln.qt.sd + + + df <- data.frame(Model=names(M)[i],year=yr,gear=kk,qt=qt) + names(df) <- c("Model","Year","Gear","Q") + df <- subset(df,Q>0) + + df <- cbind(df,"delta"=ln.qt.mu,"ub"=ub,"lb"=lb) + + mdf <- rbind(mdf,subset(df,Q>0)); + + } + + print(head(mdf)) + p <- ggplot(mdf) + geom_point(aes(Year,Q)) + p <- p + geom_point(aes(Year,delta)) + geom_pointrange(aes(Year,delta,ymax=ub,ymin=lb)) + p <- p + facet_grid(Gear~Model,scales="free") + print(p + .THEME) +} \ No newline at end of file From 50fe871649e340e85bc28e2bc9a2d172feb8e548 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 10 Apr 2015 20:15:44 -0700 Subject: [PATCH 39/61] Better fits to the halibut model, fixed likelihood for first-differnece on log_q, not the deviates --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 6 +-- fba/HALIBUT/DATA/Halibut2014.dat | 56 +++++++++++------------ src/R/lib/plotQ.R | 1 + src/admb-code/iscam.tpl | 3 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 5a0922cd..6c002229 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -65,11 +65,11 @@ ## sig=0.05 0.10 0.15 0.20 0.30 0.40 0.50 ## ## wt =200. 50.0 22.2 12.5 5.56 3.12 2.00 ## ## ------------------------------------------------------------------------- ## - 3 1 1 1 3 11 # 1 -selectivity type ivector(isel_type) for gear + 3 1 1 1 3 5 # 1 -selectivity type ivector(isel_type) for gear 82 3.0 4.0 4.0 3.0 65.0 # 2 -Age/length at 50% selectivity (logistic) 5.5 1.5 2.5 2.0 2.5 5.5 # 3 -STD at 50% selectivity (logistic) 5 0 0 0 5 5 # 4 -No. of age nodes for each gear (0=ignore) - 0 0 0 0 0 10 # 5 -No. of year nodes for 2d spline(0=ignore) + 0 0 0 0 0 5 # 5 -No. of year nodes for 2d spline(0=ignore) 2 -2 -3 -4 -1 2 # 6 -Phase of estimation (-1 for fixed) 0.0 0.0 0.0 0.0 0.0 12.5 # 7 -Penalty wt for 2nd differences w=1/(2*sig^2) 200.0 200.0 200.0 200.0 200.0 200.0 # 8 -Penalty wt for dome-shaped w=1/(2*sig^2) @@ -82,7 +82,7 @@ 1888 1888 1888 -1888 +1970 ## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## TIME VARYING NATURAL MORTALIIY RATES ## diff --git a/fba/HALIBUT/DATA/Halibut2014.dat b/fba/HALIBUT/DATA/Halibut2014.dat index 9ba002c2..967dfc0c 100644 --- a/fba/HALIBUT/DATA/Halibut2014.dat +++ b/fba/HALIBUT/DATA/Halibut2014.dat @@ -490,34 +490,34 @@ 2013 179 1 1 1 0 0.017 0.050 0.5 2014 191 1 1 1 0 0.052 0.050 0.5 ## survey_data: - 1977 1.4713 6 1 1 0 0.100 0.020 0.5 - 1978 1.1112 6 1 1 0 0.100 0.020 0.5 - 1980 2.0090 6 1 1 0 0.100 0.020 0.5 - 1981 2.6670 6 1 1 0 0.100 1.020 0.5 - 1982 2.8739 6 1 1 0 0.100 0.020 0.5 - 1983 2.8816 6 1 1 0 0.100 1.020 0.5 - 1984 9.3014 6 1 1 0 0.100 0.020 0.5 - 1985 8.9419 6 1 1 0 0.100 0.020 0.5 - 1986 6.2568 6 1 1 0 0.100 0.020 0.5 - 1996 12.8858 6 1 1 0 0.100 1.020 0.5 - 1997 7.7841 6 1 1 0 0.034 0.020 0.5 - 1998 6.9727 6 1 1 0 0.034 0.020 0.5 - 1999 6.2649 6 1 1 0 0.034 0.020 0.5 - 2000 6.6265 6 1 1 0 0.034 0.020 0.5 - 2001 6.3842 6 1 1 0 0.028 0.020 0.5 - 2002 6.3893 6 1 1 0 0.026 0.020 0.5 - 2003 5.7876 6 1 1 0 0.027 0.020 0.5 - 2004 6.4579 6 1 1 0 0.026 0.020 0.5 - 2005 5.9282 6 1 1 0 0.027 0.020 0.5 - 2006 5.4306 6 1 1 0 0.027 0.020 0.5 - 2007 5.7267 6 1 1 0 0.027 0.020 0.5 - 2008 5.6536 6 1 1 0 0.026 0.020 0.5 - 2009 5.4952 6 1 1 0 0.027 0.020 0.5 - 2010 5.1239 6 1 1 0 0.029 0.020 0.5 - 2011 5.0435 6 1 1 0 0.029 0.020 0.5 - 2012 5.5606 6 1 1 0 0.030 0.020 0.5 - 2013 4.7301 6 1 1 0 0.034 0.020 0.5 - 2014 5.1645 6 1 1 0 0.032 0.020 0.5 + 1977 1.4713 6 1 1 0 0.100 0.001 0.5 + 1978 1.1112 6 1 1 0 0.100 0.001 0.5 + 1980 2.0090 6 1 1 0 0.100 0.001 0.5 + 1981 2.6670 6 1 1 0 0.100 1.001 0.5 + 1982 2.8739 6 1 1 0 0.100 0.001 0.5 + 1983 2.8816 6 1 1 0 0.100 1.001 0.5 + 1984 9.3014 6 1 1 0 0.100 0.001 0.5 + 1985 8.9419 6 1 1 0 0.100 0.001 0.5 + 1986 6.2568 6 1 1 0 0.100 0.001 0.5 + 1996 12.8858 6 1 1 0 0.100 1.001 0.5 + 1997 7.7841 6 1 1 0 0.034 0.001 0.5 + 1998 6.9727 6 1 1 0 0.034 0.001 0.5 + 1999 6.2649 6 1 1 0 0.034 0.001 0.5 + 2000 6.6265 6 1 1 0 0.034 0.001 0.5 + 2001 6.3842 6 1 1 0 0.028 0.001 0.5 + 2002 6.3893 6 1 1 0 0.026 0.001 0.5 + 2003 5.7876 6 1 1 0 0.027 0.001 0.5 + 2004 6.4579 6 1 1 0 0.026 0.001 0.5 + 2005 5.9282 6 1 1 0 0.027 0.001 0.5 + 2006 5.4306 6 1 1 0 0.027 0.001 0.5 + 2007 5.7267 6 1 1 0 0.027 0.001 0.5 + 2008 5.6536 6 1 1 0 0.026 0.001 0.5 + 2009 5.4952 6 1 1 0 0.027 0.001 0.5 + 2010 5.1239 6 1 1 0 0.029 0.001 0.5 + 2011 5.0435 6 1 1 0 0.029 0.001 0.5 + 2012 5.5606 6 1 1 0 0.030 0.001 0.5 + 2013 4.7301 6 1 1 0 0.034 0.001 0.5 + 2014 5.1645 6 1 1 0 0.032 0.001 0.5 ## ## ------------------------------------------------------------------------- ## ## AGE COMPOSITION DATA (ROW YEAR, COL=AGE) Ragged object ## diff --git a/src/R/lib/plotQ.R b/src/R/lib/plotQ.R index 96d2d4a6..560241a4 100644 --- a/src/R/lib/plotQ.R +++ b/src/R/lib/plotQ.R @@ -37,4 +37,5 @@ p <- p + geom_point(aes(Year,delta)) + geom_pointrange(aes(Year,delta,ymax=ub,ymin=lb)) p <- p + facet_grid(Gear~Model,scales="free") print(p + .THEME) + } \ No newline at end of file diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 95a31478..a99fb9be 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2907,7 +2907,8 @@ FUNCTION calcSurveyObservations // Standardized process error residuals. if(active(log_q_devs(kk))) { - dvar_vector fd_qt = first_difference( log_q_devs(kk) ); + //dvar_vector fd_qt = first_difference( log_q_devs(kk) ); + dvar_vector fd_qt = first_difference( log(qt(kk)(iz,nz)) ); xi(kk).sub(iz,nz-1) = elem_div(fd_qt.shift(iz),it_log_pe(kk)(iz,nz-1)); } From 2a9edc50daf4856e50b63565896fa3627a8a3364 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 10 Apr 2015 21:58:13 -0700 Subject: [PATCH 40/61] new Age Barplot --- src/R/lib/plotAgeBars.R | 40 ++++++++++++++++++++++++++++++++++++++++ src/R/lib/plotAgeComps.R | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 src/R/lib/plotAgeBars.R diff --git a/src/R/lib/plotAgeBars.R b/src/R/lib/plotAgeBars.R new file mode 100644 index 00000000..b4ed8446 --- /dev/null +++ b/src/R/lib/plotAgeBars.R @@ -0,0 +1,40 @@ +# plotAgeBars.R +library(reshape2) +library(ggplot2) + +.plotAgeBars <- function( M ) +{ + n <- length( M ) + cat(".plogAgeBars\n") + id <- grep("d3_A[1-9]",names(M[[1]])) + iu <- grep("A_hat[1-9]",names(M[[1]])) + hr <- c("Year","Gear","Area","Group","Sex","AgeErr") + mdf <- NULL + for(i in 1:n) + { + getDF <- function(x) + { + ix <- id[x] + jx <- iu[x] + + age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) + df <- data.frame(M[[i]][[ix]]) + colnames(df) = c(hr,paste(age)) + + + return(df) + } + + B <- lapply(1:length(id),getDF) + } + + mB <- melt(B,id.vars=hr) + mB$BroodYear <- mB$Year - as.integer(mB$variable) + + p <- ggplot(subset(mB,L1==5),aes(as.integer(variable),value,fill=factor(BroodYear))) + p <- p + geom_bar(stat="identity") + p <- p + labs(x="Age",y="Proportion",fill=NULL) + p <- p + guides(fill = guide_legend(nrow = 4,keyheight=0.5)) + p <- p + facet_wrap(~Year)+coord_flip() + print(p + .THEME + theme(legend.position="top")) +} \ No newline at end of file diff --git a/src/R/lib/plotAgeComps.R b/src/R/lib/plotAgeComps.R index 37dd7a72..6545e601 100644 --- a/src/R/lib/plotAgeComps.R +++ b/src/R/lib/plotAgeComps.R @@ -123,11 +123,13 @@ library(reshape2) jx <- iu[x] P <- data.frame(M[[i]][[ix]][,1:6],M[[i]][jx]) + P[,-1:-6] <- P[,-1:-6]/rowSums(P[,-1:-6],na.rm=TRUE) age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) aP <- aggregate(P[,-1:-6],by=list(P[,2],P[,3],P[,4],P[,5],P[,6]),FUN=mean,na.rm=TRUE) colnames(aP) <- c("Gear","Area","Group","Sex","AgeErr",paste(age)) O <- data.frame(M[[i]][[ix]]) + O[,-1:-6] <- O[,-1:-6]/rowSums(O[,-1:-6],na.rm=TRUE) age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) aO <- aggregate(O[,-1:-6],by=list(O[,2],O[,3],O[,4],O[,5],O[,6]),FUN=mean,na.rm=TRUE) colnames(aO) <- c("Gear","Area","Group","Sex","AgeErr",paste(age)) From 7a5f9c09aa73908489a689b6f64f103be92d1636 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Sun, 12 Apr 2015 22:11:11 -0700 Subject: [PATCH 41/61] Adding lines to age bars --- src/R/lib/plotAgeBars.R | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/R/lib/plotAgeBars.R b/src/R/lib/plotAgeBars.R index b4ed8446..ac2c0a78 100644 --- a/src/R/lib/plotAgeBars.R +++ b/src/R/lib/plotAgeBars.R @@ -18,23 +18,31 @@ library(ggplot2) jx <- iu[x] age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) - df <- data.frame(M[[i]][[ix]]) - colnames(df) = c(hr,paste(age)) - + df <- data.frame(V="Observed",M[[i]][[ix]]) + df[,-1:-6] <- df[,-1:-6]/rowSums(df[,-1:-6],na.rm=TRUE) + colnames(df) = c("V",hr,paste(age)) + + dp <- data.frame(V="Predicted",M[[i]][[ix]][,1:6],M[[i]][[jx]]) + dp[,-1:-6] <- dp[,-1:-6]/rowSums(dp[,-1:-6],na.rm=TRUE) + colnames(dp) = c("V",hr,paste(age)) - return(df) + return(rbind(df,dp)) } B <- lapply(1:length(id),getDF) } - mB <- melt(B,id.vars=hr) + mB <- melt(B,id.vars=c("V",hr)) mB$BroodYear <- mB$Year - as.integer(mB$variable) - p <- ggplot(subset(mB,L1==5),aes(as.integer(variable),value,fill=factor(BroodYear))) + O <- subset(mB,V=="Observed") + I <- subset(mB,V=="Predicted") + + p <- ggplot(O,aes(as.numeric(variable),as.double(value),fill=BroodYear)) p <- p + geom_bar(stat="identity") - p <- p + labs(x="Age",y="Proportion",fill=NULL) - p <- p + guides(fill = guide_legend(nrow = 4,keyheight=0.5)) - p <- p + facet_wrap(~Year)+coord_flip() - print(p + .THEME + theme(legend.position="top")) + p <- p + geom_line(data=I,aes(as.numeric(variable),value),color="red") + p <- p + labs(x="Age",y="Proportion") + p <- p + guides(title.position = "top") + p <- p + facet_wrap(~Year,nrow=4)+coord_flip() + print(p + .THEME + theme(legend.position="top") + theme_bw(8)) } \ No newline at end of file From bae2f68d4109e1755bb29880a8f6cf7edcbad3ba Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 13 Apr 2015 10:43:05 -0700 Subject: [PATCH 42/61] PlotAgebars now available --- fba/HALIBUT/R/R4iSCAM.R | 7 +++--- src/R/lib/plotAgeBars.R | 48 ++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/fba/HALIBUT/R/R4iSCAM.R b/fba/HALIBUT/R/R4iSCAM.R index c6ce937b..fd825190 100644 --- a/fba/HALIBUT/R/R4iSCAM.R +++ b/fba/HALIBUT/R/R4iSCAM.R @@ -59,9 +59,6 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotCatch( M ) .plotIndex( M ) .plotWeightAtAge( M ) -.plotAgeComps( M ) -.plotAgeCompResiduals( M ) -.plotAgeSummary( M ) .plotSpawnBiomass( M ) .plotDepletion( M ) .plotMortality( M ) @@ -73,6 +70,10 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotCatchResidual( M ) .plotIndexResidual( M ) .plotRecruitmentResidual( M ) +.plotAgeComps( M ) +.plotAgeCompResiduals( M ) +.plotAgeSummary( M ) +.plotAgeBars( M ) # |----------------------------------------------------------------------------------| # | guiView: Main function for starting the iSCAM Gui diff --git a/src/R/lib/plotAgeBars.R b/src/R/lib/plotAgeBars.R index ac2c0a78..afaa9d45 100644 --- a/src/R/lib/plotAgeBars.R +++ b/src/R/lib/plotAgeBars.R @@ -5,11 +5,12 @@ library(ggplot2) .plotAgeBars <- function( M ) { n <- length( M ) - cat(".plogAgeBars\n") + cat(".plotAgeBars\n") id <- grep("d3_A[1-9]",names(M[[1]])) iu <- grep("A_hat[1-9]",names(M[[1]])) hr <- c("Year","Gear","Area","Group","Sex","AgeErr") mdf <- NULL + mcol<- -1:-7 for(i in 1:n) { getDF <- function(x) @@ -19,30 +20,43 @@ library(ggplot2) age <- seq(M[[i]]$n_A_sage[x],M[[i]]$n_A_nage[x]) df <- data.frame(V="Observed",M[[i]][[ix]]) - df[,-1:-6] <- df[,-1:-6]/rowSums(df[,-1:-6],na.rm=TRUE) + df[,mcol] <- df[,mcol]/rowSums(df[,mcol],na.rm=TRUE) + # cat("\nSum of observed = ",rowSums(df[,-1:-6])) colnames(df) = c("V",hr,paste(age)) dp <- data.frame(V="Predicted",M[[i]][[ix]][,1:6],M[[i]][[jx]]) - dp[,-1:-6] <- dp[,-1:-6]/rowSums(dp[,-1:-6],na.rm=TRUE) + dp[,mcol] <- dp[,mcol]/rowSums(dp[,mcol],na.rm=TRUE) + # cat("\nSum of predicted = ",rowSums(dp[,-1:-6])) colnames(dp) = c("V",hr,paste(age)) - return(rbind(df,dp)) + dfp <- rbind(df,dp) + dfp <- subset(dfp,Year %in% seq(M[[i]]$syr,M[[i]]$nyr)) + return(dfp) } B <- lapply(1:length(id),getDF) } - mB <- melt(B,id.vars=c("V",hr)) - mB$BroodYear <- mB$Year - as.integer(mB$variable) - - O <- subset(mB,V=="Observed") - I <- subset(mB,V=="Predicted") - - p <- ggplot(O,aes(as.numeric(variable),as.double(value),fill=BroodYear)) - p <- p + geom_bar(stat="identity") - p <- p + geom_line(data=I,aes(as.numeric(variable),value),color="red") - p <- p + labs(x="Age",y="Proportion") - p <- p + guides(title.position = "top") - p <- p + facet_wrap(~Year,nrow=4)+coord_flip() - print(p + .THEME + theme(legend.position="top") + theme_bw(8)) + + + barplot <- function(B) + { + mB <- melt(B,id.vars=c("V",hr)) + mB$BroodYear <- mB$Year - as.integer(mB$variable) + + + O <- subset(mB,V=="Observed") + I <- subset(mB,V=="Predicted") + + p <- ggplot(O,aes(variable,as.double(value),fill=BroodYear)) + p <- p + geom_bar(stat="identity",alpha=0.7) + p <- p + geom_line(data=I,aes(as.numeric(variable),value),color="red") + p <- p + labs(x="Age",y="Proportion") + p <- p + guides(title.position = "top") + p <- p + facet_wrap(~Year,nrow=4)+coord_flip() + return (p + .THEME + theme(legend.position="top") + theme_bw(8)) + } + + P <- lapply(B,barplot) + print(P) } \ No newline at end of file From 11ac51ce2ad562140a0dffdded39a7db6db4f36e Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 13 Apr 2015 13:36:21 -0700 Subject: [PATCH 43/61] Added new controls to control file, and read in DATA_SECTION --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 72 +++++++++++++++++++++-- src/admb-code/iscam.tpl | 14 +++++ 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 6c002229..eb729c42 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -25,9 +25,9 @@ ## ------------------------------------------------------------------------- ## ## -## ------------------------------------------------------------------------- ## -## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## Likelihood type for each gear: ## -1 : multivariate logistic (dmvlogistic) ## -2 : multinomial, sample size based on input data @@ -35,7 +35,7 @@ ## -4 : logistic_normal, AR1 ## -5 : logistic_normal, AR2 ## -6 : multinomial with estimated effective sample size. -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## Number of columns == na_gears. 1 1 6 6 6 6 ## : Gear Index 2 2 2 2 2 2 ## : Likelihood type @@ -46,9 +46,69 @@ -2 -2 -2 -2 -2 -2 ## : phase for phi2 estimation : bounded (0,1) AR2 -2 -2 -2 -2 -2 -2 ## : phase for degrees of freedom for student T. -12345 ## : int check (-12345) -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## -## + + +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## SELECTIVITY CONTROLS ## +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## - Each gear must have a selectivity and retention curve. +# ## • Index = gear index for selectivity curve. +# ## • sel_type = type of selectivity function (see Legend). +# ## • sel_mu = mean age/length 50% selectivity. +# ## • sel_sd = std in 50% selectivity +# ## • sex_dep = 0 -> no; 1 -> offset for sex 2. +# ## • size_nodes = # of nodes for age/size cubic spline. +# ## • year_nodes = # of nodes for time varying bicubic spline. +# ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +# ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +# ## • lam2 = penalty weight for dome-shaped selectivity. +# ## • lam3 = penalty weight for time-varying selectivity. +# ## • start_block = year index for first year of selectivity curve. +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## sel_nBlocks ret_nBlocks ## Gear Description. +# 1 1 ## Commercial retained +# 1 1 ## Commercial discards +# 1 1 ## Bycatch in non-directed fisheries. +# 1 1 ## Sport +# 1 1 ## Personal use +# 1 1 ## Setline survey. +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## slx_dControls +# ## sel sel sel sex size year phz start end ## +# ## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## Selectivity P(capture of all size/age) +# 1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 +# 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 +# 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 +# 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 +# 5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 +# 6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## ret_dControls +# ## sel sel sel sex size year phz start end ## +# ## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +# ## ———————————————————————————————————————————————————————————————————————————————————— ## +# ## Retention P(retaining size/age) +# -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 +# -2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 +# -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 +# -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 +# -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 +# -6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 + + + + + + + + + + +## TO BE DEPRECATED ## ------------------------------------------------------------------------- ## ## SELECTIVITY PARAMETERS Columns for gear ## ## OPTIONS FOR SELECTIVITY (isel_type): ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index a99fb9be..955d8c05 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1081,6 +1081,20 @@ DATA_SECTION // | 10 -> Number of discrete selectivity blocks. // | + + /// April 13, issue 39. Changing the way selectivity/retention is controlled. + !! #define NEW_SELEX + !! #ifdef NEW_SELEX + init_imatrix slx_nBlocks(1,ngear,1,2); + int slx_nrow; + int ret_nrow + !! slx_nrow = sum(column(slx_nBlocks,1)); + !! ret_nrow = sum(column(slx_nBlocks,2)); + init_matrix slx_dControls(1,slx_nrow,1,12); + init_matrix ret_dControls(1,slx_nrow,1,12); + !! #endif + + init_matrix selex_controls(1,10,1,ngear); From 639904e1a4dad2897032ef5ca3697d50b7989e00 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 13 Apr 2015 15:06:40 -0700 Subject: [PATCH 44/61] Implemented slx_log_par --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 96 ++++++++++---------- src/admb-code/iscam.tpl | 106 +++++++++++++++++++++- 2 files changed, 149 insertions(+), 53 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index eb729c42..1e5590de 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -50,54 +50,54 @@ -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## SELECTIVITY CONTROLS ## -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## - Each gear must have a selectivity and retention curve. -# ## • Index = gear index for selectivity curve. -# ## • sel_type = type of selectivity function (see Legend). -# ## • sel_mu = mean age/length 50% selectivity. -# ## • sel_sd = std in 50% selectivity -# ## • sex_dep = 0 -> no; 1 -> offset for sex 2. -# ## • size_nodes = # of nodes for age/size cubic spline. -# ## • year_nodes = # of nodes for time varying bicubic spline. -# ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) -# ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). -# ## • lam2 = penalty weight for dome-shaped selectivity. -# ## • lam3 = penalty weight for time-varying selectivity. -# ## • start_block = year index for first year of selectivity curve. -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## sel_nBlocks ret_nBlocks ## Gear Description. -# 1 1 ## Commercial retained -# 1 1 ## Commercial discards -# 1 1 ## Bycatch in non-directed fisheries. -# 1 1 ## Sport -# 1 1 ## Personal use -# 1 1 ## Setline survey. -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## slx_dControls -# ## sel sel sel sex size year phz start end ## -# ## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## Selectivity P(capture of all size/age) -# 1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 -# 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 -# 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 -# 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 -# 5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 -# 6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## ret_dControls -# ## sel sel sel sex size year phz start end ## -# ## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## -# ## ———————————————————————————————————————————————————————————————————————————————————— ## -# ## Retention P(retaining size/age) -# -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 -# -2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 -# -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 -# -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 -# -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 -# -6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## SELECTIVITY CONTROLS ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## - Each gear must have a selectivity and retention curve. +## • Index = gear index for selectivity curve. +## • sel_type = type of selectivity function (see Legend). +## • sel_mu = mean age/length 50% selectivity. +## • sel_sd = std in 50% selectivity +## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## • size_nodes = # of nodes for age/size cubic spline. +## • year_nodes = # of nodes for time varying bicubic spline. +## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## • lam2 = penalty weight for dome-shaped selectivity. +## • lam3 = penalty weight for time-varying selectivity. +## • start_block = year index for first year of selectivity curve. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel_nBlocks ret_nBlocks ## Gear Description. + 1 1 ## Commercial retained + 1 1 ## Commercial discards + 1 1 ## Bycatch in non-directed fisheries. + 1 1 ## Sport + 1 1 ## Personal use + 1 1 ## Setline survey. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Selectivity P(capture of all size/age) +## slx_dControls +## sel sel sel sex age year phz start end ## +## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + 1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 + 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 + 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 + 5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 + 6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Retention P(retaining size/age) +## ret_dControls +## sel sel sel sex age year phz start end ## +## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + -2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 + -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 + -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 + -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 + -6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 955d8c05..0ee4e4ef 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1083,16 +1083,100 @@ DATA_SECTION /// April 13, issue 39. Changing the way selectivity/retention is controlled. - !! #define NEW_SELEX - !! #ifdef NEW_SELEX + +!! #ifdef NEW_SELEX init_imatrix slx_nBlocks(1,ngear,1,2); int slx_nrow; int ret_nrow !! slx_nrow = sum(column(slx_nBlocks,1)); !! ret_nrow = sum(column(slx_nBlocks,2)); - init_matrix slx_dControls(1,slx_nrow,1,12); - init_matrix ret_dControls(1,slx_nrow,1,12); - !! #endif + init_matrix slx_dControls(1,slx_nrow,1,13); + init_matrix ret_dControls(1,slx_nrow,1,13); + + ivector slx_nIpar(1,slx_nrow); /// number of rows for each slx + ivector slx_nJpar(1,slx_nrow); /// number of cols for each slx + ivector slx_nSelType(1,slx_nrow); /// type of selectivity function + ivector slx_nAgeNodes(1,slx_nrow); /// number of age/size nodes + ivector slx_nYrNodes(1,slx_nrow); /// number of Year nodes + ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. + ivector slx_nsb(1,slx_nrow); /// start of block year. + ivector slx_neb(1,slx_nrow); /// end of block year. + + LOC_CALCS + slx_nSelType = ivector(column(slx_dControls,2)); + slx_nAgeNodes = ivector(column(slx_dControls,6)); + slx_nYrNodes = ivector(column(slx_dControls,7)); + slx_phz = ivector(column(slx_dControls,8)); + slx_nsb = ivector(column(slx_dControls,12)); + slx_neb = ivector(column(slx_dControls,13)); + + // • Count number of selectivity parameters required for each slx_type + for(i = 1; i <= slx_nrow; i++) + { + int hsex = int(slx_dControls(i,5)) + 1; + slx_nIpar(i) = hsex; + + switch(slx_nSelType(i)) + { + // • logistic selectivity + case 1: + slx_nJpar(i) = 2; + break; + + // • age-specific coefficients + case 2: + slx_nJpar(i) = int(nage - sage); + break; + + // • cubic spline over age/size + case 3: + slx_nJpar(i) = slx_nAgeNodes(i); + break; + + // • cubic spline over age/size each year + case 4: + slx_nJpar(i) = slx_nAgeNodes(i); + slx_nIpar(i) = hsex * (slx_neb(i) - slx_nsb(i) + 1); + break; + + // • bicubic spline over age-size / years + case 5: + slx_nJpar(i) = slx_nAgeNodes(i); + slx_nIpar(i) = hsex * slx_nYrNodes(i); + break; + + // • logistic based on weight-at-age deviations. + case 6: + slx_nJpar(i) = 2; + break; + + // • logistic based on weight-at-age devs and scalar parameter. + case 7: + slx_nJpar(i) = 3; + break; + + // • age-specific coefficients between lb_age <= age <= ub_age + // case 8: + + // • logistic based on mean length-at-age. + case 11: + slx_nJpar(i) = 2; + break; + + // • size-specific coefficients. + //case 12: + + // • size-based cubic spline over mean size-at-age + case 13: + slx_nJpar(i) = slx_nAgeNodes(i); + break; + } + } + END_CALCS + + + +!! #endif init_matrix selex_controls(1,10,1,ngear); @@ -1486,6 +1570,11 @@ PARAMETER_SECTION // | - Special case: if SimFlag=TRUE, then add some random noise to ahat. // | - NB sel_par is in log space. // | +!! #ifdef NEW_SELEX + init_bounded_matrix_vector slx_log_par(1,slx_nrow,1,slx_nIpar,1,slx_nJpar,-25.0,25.0,slx_phz); + // TO DO set initial values for slx parameters. +!! #endif + init_bounded_matrix_vector sel_par(1,ngear,1,jsel_npar,1,isel_npar,-25.,25.,sel_phz); LOC_CALCS @@ -5482,6 +5571,13 @@ TOP_OF_MAIN_SECTION GLOBALS_SECTION + + /** + * \def NEW_SELEX + * Testing new selectivity controls. + */ + #define NEW_SELEX + /** \def REPORT(object) Prints name and value of \a object on ADMB report %ofstream file. From d574c4567501082e19dec4f0bd5b08c21618a246 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Mon, 13 Apr 2015 19:29:20 -0700 Subject: [PATCH 45/61] chk point --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 6 +- src/admb-code/include/selex.hpp | 102 ++++++++++++++++++++++ src/admb-code/iscam.tpl | 46 +++++++++- 3 files changed, 150 insertions(+), 4 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 1e5590de..5c2578f7 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -80,12 +80,12 @@ ## sel sel sel sex age year phz start end ## ## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + 1 1 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 - 5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - 6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + 5 1 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 + 6 1 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 18acc49a..af60871b 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -4,6 +4,8 @@ #define SELEX_HPP #include +#include +#include /** * @defgroup Selectivities @@ -21,6 +23,106 @@ */ namespace slx { + #define Register(x) slxInterface::template Init(); + + /** + * A Generic Selectivity Interface class. + */ + template + class slxInterface + { + private: + + typedef REAL_T(*EVAL_FUNCTION_PTR)(void* const); + + EVAL_FUNCTION_PTR eval_ptr; + + template static + REAL_T Evaluate_T(void* const pObj) + { + return static_cast (pObj)->Evaluate(); + } + + protected: + + // set a pointer to the evaluate function. + template void Init() + { + eval_ptr = (EVAL_FUNCTION_PTR) & Evaluate_T; + } + + public: + + slxInterface() + : eval_ptr(0){ + + } + + virtual ~ slxInterface(){ + + } + + inline REAL_T Evaluate(){ + assert(eval_ptr); // ensure Init() was called. + return (*eval_ptr)(this); + } + + }; + + /** + * Logistic Selectivity Class that inherits from the slxInterface + */ + template + class slx_Logistic: public slxInterface + { + private: + friend class slxInterface; + + // Evaluate should return a dvar_vector or a df1b2_vector + inline REAL_T Evaluate() { + cout<<"Evaluating slx_Logistic"<); + } + }; + + + + + + + + + + + + + + + + + + + + + + + template const T plogis(const T &x, const T2 &mean, const T2 & sd) { diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 0ee4e4ef..9cb8a371 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1098,12 +1098,14 @@ DATA_SECTION ivector slx_nSelType(1,slx_nrow); /// type of selectivity function ivector slx_nAgeNodes(1,slx_nrow); /// number of age/size nodes ivector slx_nYrNodes(1,slx_nrow); /// number of Year nodes + ivector slx_nSex(1,slx_nrow); /// number of sexes ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. ivector slx_nsb(1,slx_nrow); /// start of block year. ivector slx_neb(1,slx_nrow); /// end of block year. LOC_CALCS slx_nSelType = ivector(column(slx_dControls,2)); + slx_nSex = ivector(column(slx_dControls,5)) + 1; slx_nAgeNodes = ivector(column(slx_dControls,6)); slx_nYrNodes = ivector(column(slx_dControls,7)); slx_phz = ivector(column(slx_dControls,8)); @@ -1113,7 +1115,7 @@ DATA_SECTION // • Count number of selectivity parameters required for each slx_type for(i = 1; i <= slx_nrow; i++) { - int hsex = int(slx_dControls(i,5)) + 1; + int hsex = slx_nSex(i); slx_nIpar(i) = hsex; switch(slx_nSelType(i)) @@ -1172,6 +1174,8 @@ DATA_SECTION break; } } + + cout<<"Ok after new selex stuff in data section"< *ptrSlx[slx_nIpar(k)-1]; + for( j = 0; j < slx_nIpar(k); j++ ) + { + + switch(slx_nSelType(k)) + { + // logistic selectivity based on age. + case 1: + p1 = slx_log_par(k,j+1,1); + p2 = slx_log_par(k,j+1,2); + COUT(p1); + ptrSlx[j] = new slx::slx_Logistic(p1,p2); + break; + } + ptrSlx[j]->Evaluate(); + } + + } + + cout<<"End of CalcSelex"< Date: Wed, 15 Apr 2015 09:12:44 -0700 Subject: [PATCH 46/61] New Selex class interface now starting to work for Logistic only --- src/admb-code/include/selex.hpp | 18 ++++----- src/admb-code/iscam.tpl | 68 ++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index af60871b..1fbc7aec 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -81,20 +81,20 @@ namespace slx { // Evaluate should return a dvar_vector or a df1b2_vector inline REAL_T Evaluate() { cout<<"Evaluating slx_Logistic"<); diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 9cb8a371..dfe7d5b4 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1093,24 +1093,26 @@ DATA_SECTION init_matrix slx_dControls(1,slx_nrow,1,13); init_matrix ret_dControls(1,slx_nrow,1,13); - ivector slx_nIpar(1,slx_nrow); /// number of rows for each slx - ivector slx_nJpar(1,slx_nrow); /// number of cols for each slx - ivector slx_nSelType(1,slx_nrow); /// type of selectivity function - ivector slx_nAgeNodes(1,slx_nrow); /// number of age/size nodes - ivector slx_nYrNodes(1,slx_nrow); /// number of Year nodes - ivector slx_nSex(1,slx_nrow); /// number of sexes - ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. - ivector slx_nsb(1,slx_nrow); /// start of block year. - ivector slx_neb(1,slx_nrow); /// end of block year. + ivector slx_nGearIndex(1,slx_nrow); /// index for fishing gear. + ivector slx_nIpar(1,slx_nrow); /// number of rows for each slx + ivector slx_nJpar(1,slx_nrow); /// number of cols for each slx + ivector slx_nSelType(1,slx_nrow); /// type of selectivity function + ivector slx_nAgeNodes(1,slx_nrow); /// number of age/size nodes + ivector slx_nYrNodes(1,slx_nrow); /// number of Year nodes + ivector slx_nSex(1,slx_nrow); /// number of sexes + ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. + ivector slx_nsb(1,slx_nrow); /// start of block year. + ivector slx_neb(1,slx_nrow); /// end of block year. LOC_CALCS - slx_nSelType = ivector(column(slx_dControls,2)); - slx_nSex = ivector(column(slx_dControls,5)) + 1; - slx_nAgeNodes = ivector(column(slx_dControls,6)); - slx_nYrNodes = ivector(column(slx_dControls,7)); - slx_phz = ivector(column(slx_dControls,8)); - slx_nsb = ivector(column(slx_dControls,12)); - slx_neb = ivector(column(slx_dControls,13)); + slx_nGearIndex = ivector(column(slx_dControls,1)); + slx_nSelType = ivector(column(slx_dControls,2)); + slx_nSex = ivector(column(slx_dControls,5)) + 1; + slx_nAgeNodes = ivector(column(slx_dControls,6)); + slx_nYrNodes = ivector(column(slx_dControls,7)); + slx_phz = ivector(column(slx_dControls,8)); + slx_nsb = ivector(column(slx_dControls,12)); + slx_neb = ivector(column(slx_dControls,13)); // • Count number of selectivity parameters required for each slx_type for(i = 1; i <= slx_nrow; i++) @@ -2099,14 +2101,14 @@ FUNCTION calcSelex log_sel.initialize(); int h,i,j,k; - int ig; + int ig,kgear; dvariable p1,p2; - COUT(slx_nrow); + COUT(nyr ); for(k = 1; k <= slx_nrow; k++) { - slx::slxInterface *ptrSlx[slx_nIpar(k)-1]; + slx::slxInterface *ptrSlx[slx_nIpar(k)-1]; for( j = 0; j < slx_nIpar(k); j++ ) { @@ -2116,13 +2118,35 @@ FUNCTION calcSelex case 1: p1 = slx_log_par(k,j+1,1); p2 = slx_log_par(k,j+1,2); - COUT(p1); - ptrSlx[j] = new slx::slx_Logistic(p1,p2); + + ptrSlx[j] = new slx::slx_Logistic(age,p1,p2); break; } - ptrSlx[j]->Evaluate(); + COUT(ptrSlx[j]->Evaluate()); } + + // fill arrays with selectivity coefficients. + j = 0; + for( ig = 1; ig <= n_ags; ig++ ) + { + kgear = slx_nGearIndex(k); + if( slx_phz(k) < 0 ) /// check mirroring. + { + kgear = fabs(slx_phz(k)); + } + + for(i = syr>slx_nsb(k)?syr:slx_nsb(k); i <= nyr Evaluate(); + } + + } + + delete *ptrSlx; + + } cout<<"End of CalcSelex"< Date: Thu, 16 Apr 2015 21:03:16 -0700 Subject: [PATCH 47/61] annual cubic splines working --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 18 ++-- src/admb-code/include/selex.hpp | 117 +++++++++++++++++++++- src/admb-code/iscam.tpl | 81 +++++++++++---- 3 files changed, 183 insertions(+), 33 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 5c2578f7..73ebf971 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -53,7 +53,7 @@ ## ———————————————————————————————————————————————————————————————————————————————————— ## ## SELECTIVITY CONTROLS ## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## - Each gear must have a selectivity and retention curve. +## - Each gear must have at least one selectivity and retention curve. ## • Index = gear index for selectivity curve. ## • sel_type = type of selectivity function (see Legend). ## • sel_mu = mean age/length 50% selectivity. @@ -77,20 +77,22 @@ ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Selectivity P(capture of all size/age) ## slx_dControls -## sel sel sel sex age year phz start end ## -## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 1 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + 1 4 10 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 - 5 1 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - 6 1 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + 5 1 10 2.0 0 5 0 -1 0.0 0.0 0.0 1888 2014 + 6 2 3.0 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls -## sel sel sel sex age year phz start end ## -## Index type mu sd dep nodes nodes mirror lam1 lam2 lam3 | block block ## +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 -2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 1fbc7aec..9febd9ca 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -69,6 +69,12 @@ namespace slx { }; + + + + + + /** * Logistic Selectivity Class that inherits from the slxInterface */ @@ -80,7 +86,7 @@ namespace slx { // Evaluate should return a dvar_vector or a df1b2_vector inline REAL_T Evaluate() { - cout<<"Evaluating slx_Logistic"< + slx_Logistic(T1 &x, T2 &log_mu, T2 &log_sd) :m_log_mu(log_mu),m_log_sd(log_sd),m_x(x) { - cout<<"Constructor"<); } }; @@ -107,10 +113,115 @@ namespace slx { + /** + * Selectivity coefficients. + */ + + template + class slx_Coefficients: public slxInterface + { + private: + friend class slxInterface; + + inline REAL_T Evaluate() { + // cout<<"Evaluating slx_Coefficients"< + slx_Coefficients(T1 &x, T2 &log_sel_coeffs) + :m_x(x),m_log_sel_coeffs(log_sel_coeffs) + { + Register(slx_Coefficients); + } + }; + + + /** + * Cubic spline + */ + template + class slx_CubicSpline: public slxInterface + { + private: + friend class slxInterface; + + inline REAL_T Evaluate() { + cout<<"Evaluating CubicSpline"< + slx_CubicSpline(T1 &x, T2 &log_spline_coeffs) + :m_x(x),m_log_spline_coeffs(log_spline_coeffs) + { + Register(slx_CubicSpline); + } + }; + + + + /** + * BiCubic spline + */ + template + class slx_BiCubicSpline: public slxInterface + { + private: + friend class slxInterface; + + inline REAL_T Evaluate() { + cout<<"Evaluating BiCubicSpline"< + slx_BiCubicSpline(T1 &x, T2 &log_spline_coeffs) + :m_x(x),m_log_spline_coeffs(log_spline_coeffs) + { + Register(slx_BiCubicSpline); + } + }; diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index dfe7d5b4..27e0da2c 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1099,7 +1099,7 @@ DATA_SECTION ivector slx_nSelType(1,slx_nrow); /// type of selectivity function ivector slx_nAgeNodes(1,slx_nrow); /// number of age/size nodes ivector slx_nYrNodes(1,slx_nrow); /// number of Year nodes - ivector slx_nSex(1,slx_nrow); /// number of sexes + ivector slx_nSex(1,slx_nrow); /// index for sex (0=both, 1=female, 2=male) ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. ivector slx_nsb(1,slx_nrow); /// start of block year. ivector slx_neb(1,slx_nrow); /// end of block year. @@ -1107,7 +1107,7 @@ DATA_SECTION LOC_CALCS slx_nGearIndex = ivector(column(slx_dControls,1)); slx_nSelType = ivector(column(slx_dControls,2)); - slx_nSex = ivector(column(slx_dControls,5)) + 1; + slx_nSex = ivector(column(slx_dControls,5)); slx_nAgeNodes = ivector(column(slx_dControls,6)); slx_nYrNodes = ivector(column(slx_dControls,7)); slx_phz = ivector(column(slx_dControls,8)); @@ -1117,8 +1117,7 @@ DATA_SECTION // • Count number of selectivity parameters required for each slx_type for(i = 1; i <= slx_nrow; i++) { - int hsex = slx_nSex(i); - slx_nIpar(i) = hsex; + slx_nIpar(i) = 1; switch(slx_nSelType(i)) { @@ -1140,13 +1139,13 @@ DATA_SECTION // • cubic spline over age/size each year case 4: slx_nJpar(i) = slx_nAgeNodes(i); - slx_nIpar(i) = hsex * (slx_neb(i) - slx_nsb(i) + 1); + slx_nIpar(i) = slx_neb(i) - slx_nsb(i) + 1; break; // • bicubic spline over age-size / years case 5: slx_nJpar(i) = slx_nAgeNodes(i); - slx_nIpar(i) = hsex * slx_nYrNodes(i); + slx_nIpar(i) = slx_nYrNodes(i); break; // • logistic based on weight-at-age deviations. @@ -2100,14 +2099,13 @@ FUNCTION calcSelex cout<<"START of CalcSelex"< *ptrSlx[slx_nIpar(k)-1]; for( j = 0; j < slx_nIpar(k); j++ ) { @@ -2118,37 +2116,76 @@ FUNCTION calcSelex case 1: p1 = slx_log_par(k,j+1,1); p2 = slx_log_par(k,j+1,2); - ptrSlx[j] = new slx::slx_Logistic(age,p1,p2); break; + + // age-specific selectivity coefficients. + case 2: + ptrSlx[j] = new slx::slx_Coefficients(age,slx_log_par(k)(j+1)); + break; + + // cubic spline + case 3: + ptrSlx[j] = new slx::slx_CubicSpline(age,slx_log_par(k)(j+1)); + break; + + // • cubic spline over age/size each year + case 4: + ptrSlx[j] = new slx::slx_CubicSpline(age,slx_log_par(k)(j+1)); + break; } - COUT(ptrSlx[j]->Evaluate()); + } // fill arrays with selectivity coefficients. + // NOTES: + // • h = index for sex (0=both, 1=female, 2=male) + // • If slx_nSex(k) == 0, then apply same slx curve to both sexes. + // Do this by looping over area and group, and assign to specific sex. j = 0; - for( ig = 1; ig <= n_ags; ig++ ) + int f,g,h,ih; + int h_sex = slx_nSex(k); + int kgear = slx_nGearIndex(k); + //int ngrp = h_sex==0? n_ag: n_ags; + + + + for(int ig = 1; ig <= n_ags; ig++ ) { - kgear = slx_nGearIndex(k); - if( slx_phz(k) < 0 ) /// check mirroring. - { - kgear = fabs(slx_phz(k)); - } + f = n_area(ig); + g = n_group(ig); + h = n_sex(ig); + + + //if( slx_phz(k) < 0 ) /// check mirroring. + //{ + // kgear = fabs(slx_phz(k)); + //} + + // if h_sex == 0, then you need to reset j = 0 + if ( h_sex == 0 ) j = 0; - for(i = syr>slx_nsb(k)?syr:slx_nsb(k); i <= nyrslx_nsb(k)?syr:slx_nsb(k); i <= slx_neb(k); i++) { - COUT(i); - log_sel(kgear)(ig)(i) = ptrSlx[j] -> Evaluate(); - } + log_sel(kgear)(igrp)(i) = ptrSlx[j] -> Evaluate(); + if(slx_nSelType(k) == 4 && j < slx_nIpar(k)) j++; + } + //cout< Date: Fri, 17 Apr 2015 16:21:34 -0700 Subject: [PATCH 48/61] Bicubic spline working --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 18 +- src/admb-code/include/selex.hpp | 31 ++-- src/admb-code/iscam.tpl | 199 ++++++++++++++++------ 3 files changed, 174 insertions(+), 74 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 73ebf971..55ad2d05 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -78,20 +78,20 @@ ## Selectivity P(capture of all size/age) ## slx_dControls ## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz start end ## +## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 4 10 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 - 2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 - 3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 - 4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 - 5 1 10 2.0 0 5 0 -1 0.0 0.0 0.0 1888 2014 - 6 2 3.0 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 + 1 3 10 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 + 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 + 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 + 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 + 5 1 10 2.0 0 0 0 -1 0.0 0.0 0.0 1888 2014 + 6 5 3.0 2.0 0 5 5 2 0.0 0.0 0.0 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls ## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz start end ## +## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 @@ -99,7 +99,7 @@ -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - -6 5 3.0 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + -6 5 3.0 2.0 1 5 5 2 0.0 0.0 0.0 1888 2014 diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 9febd9ca..f01f8b9a 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -169,22 +169,22 @@ namespace slx { friend class slxInterface; inline REAL_T Evaluate() { - cout<<"Evaluating CubicSpline"< slx_CubicSpline(T1 &x, T2 &log_spline_coeffs) - :m_x(x),m_log_spline_coeffs(log_spline_coeffs) + :m_x(x),m_log_spline_knots(log_spline_coeffs) { Register(slx_CubicSpline); } @@ -202,22 +202,23 @@ namespace slx { friend class slxInterface; inline REAL_T Evaluate() { - cout<<"Evaluating BiCubicSpline"< - slx_BiCubicSpline(T1 &x, T2 &log_spline_coeffs) - :m_x(x),m_log_spline_coeffs(log_spline_coeffs) + slx_BiCubicSpline(const T1 &x, const T1 &y, T2 &log_spline_coeffs, T2 &A) + :m_x(x),m_y(y),m_log_sel(A),m_log_spline_knots(log_spline_coeffs) { Register(slx_BiCubicSpline); } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 27e0da2c..cb03035c 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1894,12 +1894,12 @@ PROCEDURE_SECTION initParameters(); + //calcSelectivities(isel_type); + #ifdef NEW_SELEX calcSelex(); #endif - - calcSelectivities(isel_type); - + calcTotalMortality(); calcNumbersAtAge(); @@ -2096,46 +2096,82 @@ FUNCTION dvector cubic_spline(const dvector& spline_coffs, const dvector& la) FUNCTION calcSelex { - cout<<"START of CalcSelex"< *ptrSlx[slx_nIpar(k)-1]; - for( j = 0; j < slx_nIpar(k); j++ ) + int yr1 = syr > slx_nsb(k)?syr:slx_nsb(k); + int yr2 = nyr < slx_neb(k)?nyr:slx_neb(k); + int nn = slx_nIpar(k)-1; + slx::slxInterface *ptrSlx[nn]; + for( i = 0; i <= nn; i++ ) { - - switch(slx_nSelType(k)) - { - // logistic selectivity based on age. - case 1: - p1 = slx_log_par(k,j+1,1); - p2 = slx_log_par(k,j+1,2); - ptrSlx[j] = new slx::slx_Logistic(age,p1,p2); - break; - - // age-specific selectivity coefficients. - case 2: - ptrSlx[j] = new slx::slx_Coefficients(age,slx_log_par(k)(j+1)); - break; - - // cubic spline - case 3: - ptrSlx[j] = new slx::slx_CubicSpline(age,slx_log_par(k)(j+1)); - break; - - // • cubic spline over age/size each year - case 4: - ptrSlx[j] = new slx::slx_CubicSpline(age,slx_log_par(k)(j+1)); - break; - } - + ptrSlx[i] = NULL; } + slx::slxInterface *ptrSlxM = NULL; + + + switch(slx_nSelType(k)) + { + // logistic selectivity based on age. + case 1: + for( j = 0; j < slx_nIpar(k); j++ ) + { + p1 = slx_log_par(k,j+1,1); + p2 = slx_log_par(k,j+1,2); + ptrSlx[j] = new slx::slx_Logistic(age,p1,p2); + } + break; + + // age-specific selectivity coefficients. + case 2: + for( j = 0; j < slx_nIpar(k); j++ ) + { + dvar_vector slx_theta = slx_log_par(k)(j+1); + ptrSlx[j] = new slx::slx_Coefficients(age,slx_theta); + } + break; + + // cubic spline + case 3: + for( j = 0; j < slx_nIpar(k); j++ ) + { + dvar_vector slx_theta = slx_log_par(k)(j+1); + ptrSlx[j] = new slx::slx_CubicSpline(age,slx_theta); + } + break; + + // • cubic spline over age/size each year + case 4: + for( j = 0; j < slx_nIpar(k); j++ ) + { + dvar_vector slx_theta = slx_log_par(k)(j+1); + ptrSlx[j] = new slx::slx_CubicSpline(age,slx_theta); + } + break; + + // • bicubic spline over age and year knots + case 5: + dvar_matrix tmp(yr1,yr2,sage,nage); + dvector iyr(1,slx_nYrNodes(k)); + dvector iag(1,slx_nAgeNodes(k)); + iyr.fill_seqadd(0,1.0/(slx_nYrNodes(k)-1)); + iag.fill_seqadd(0,1.0/(slx_nAgeNodes(k)-1)); + dvar_matrix slx_theta = slx_log_par(k); + tmp.initialize(); + + ptrSlxM = new slx::slx_BiCubicSpline(iag,iyr,slx_theta,tmp); + //COUT(ptrSlxM -> Evaluate()); + break; + } + + // fill arrays with selectivity coefficients. @@ -2144,13 +2180,9 @@ FUNCTION calcSelex // • If slx_nSex(k) == 0, then apply same slx curve to both sexes. // Do this by looping over area and group, and assign to specific sex. j = 0; - int f,g,h,ih; + int f,g,h; int h_sex = slx_nSex(k); int kgear = slx_nGearIndex(k); - //int ngrp = h_sex==0? n_ag: n_ags; - - - for(int ig = 1; ig <= n_ags; ig++ ) { f = n_area(ig); @@ -2168,26 +2200,34 @@ FUNCTION calcSelex // if !h_sex, skip the process if current group is not the right sex if ( h_sex != 0 && h != h_sex) continue; - int igrp = pntr_ags(f,g,h); - for(i = syr>slx_nsb(k)?syr:slx_nsb(k); i <= slx_neb(k); i++) + + // Fill vectors of selex + if (ptrSlx[j]) { - log_sel(kgear)(igrp)(i) = ptrSlx[j] -> Evaluate(); + for(i = syr>slx_nsb(k)?syr:slx_nsb(k); i <= slx_neb(k); i++) + { + log_sel(kgear)(igrp)(i) = ptrSlx[j] -> Evaluate(); - if(slx_nSelType(k) == 4 && j < slx_nIpar(k)) j++; + if(slx_nSelType(k) == 4 && j < slx_nIpar(k)) j++; + } + } + + // Fill matrix of selex + if (ptrSlxM) + { + log_sel(kgear)(igrp) = ptrSlxM -> Evaluate(); } - //cout< Date: Fri, 17 Apr 2015 16:24:05 -0700 Subject: [PATCH 49/61] Bicubic spline working --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 55ad2d05..4901d02c 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -95,11 +95,11 @@ ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 - -2 1 3.0 1.5 0 5 0 -2 0.0 0.0 0.0 1888 2014 + -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - -6 5 3.0 2.0 1 5 5 2 0.0 0.0 0.0 1888 2014 + -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 From dbea682179e788e703ba7d31c357d9e36f020f5e Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 17 Apr 2015 16:59:15 -0700 Subject: [PATCH 50/61] Testing sex-specific selex curves --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 11 ++++++++--- src/admb-code/iscam.tpl | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 4901d02c..f12a1af4 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -54,6 +54,10 @@ ## SELECTIVITY CONTROLS ## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## - Each gear must have at least one selectivity and retention curve. +## - Use a -ve phase with the gear index to mirror another gear. Note +## that if you mirror another gear, it must have the same sel type and +## age and year nodes so that the arrays are the same shape & block years. +## ## • Index = gear index for selectivity curve. ## • sel_type = type of selectivity function (see Legend). ## • sel_mu = mean age/length 50% selectivity. @@ -73,7 +77,7 @@ 1 1 ## Bycatch in non-directed fisheries. 1 1 ## Sport 1 1 ## Personal use - 1 1 ## Setline survey. + 2 1 ## Setline survey. ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Selectivity P(capture of all size/age) ## slx_dControls @@ -85,8 +89,9 @@ 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 - 5 1 10 2.0 0 0 0 -1 0.0 0.0 0.0 1888 2014 - 6 5 3.0 2.0 0 5 5 2 0.0 0.0 0.0 1888 2014 + 5 3 10 2.0 0 5 0 -1 0.0 0.0 0.0 1888 2014 + 6 5 3.0 2.0 1 5 5 2 0.0 0.0 0.0 1888 2014 + 6 5 3.0 2.0 2 5 5 2 0.0 0.0 0.0 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index cb03035c..abf5f9eb 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2104,8 +2104,17 @@ FUNCTION calcSelex dvariable p1,p2; - for(k = 1; k <= slx_nrow; k++) + for(int kr = 1; kr <= slx_nrow; kr++) { + // The following is used to mirror another gear-type + // based on the absolute value of sel_phz. + k = kr; + if(sel_phz(k) < 0) + { + k = abs(sel_phz(kr)); + slx_log_par(k) = slx_log_par(kr); + } + int yr1 = syr > slx_nsb(k)?syr:slx_nsb(k); int yr2 = nyr < slx_neb(k)?nyr:slx_neb(k); int nn = slx_nIpar(k)-1; @@ -2205,9 +2214,10 @@ FUNCTION calcSelex // Fill vectors of selex if (ptrSlx[j]) { - for(i = syr>slx_nsb(k)?syr:slx_nsb(k); i <= slx_neb(k); i++) + for(i = yr1; i <= yr2; i++) { log_sel(kgear)(igrp)(i) = ptrSlx[j] -> Evaluate(); + if(slx_nSelType(k) == 4 && j < slx_nIpar(k)) j++; } @@ -2218,6 +2228,12 @@ FUNCTION calcSelex { log_sel(kgear)(igrp) = ptrSlxM -> Evaluate(); } + + //subtract mean to ensure mean(exp(log_sel))==1 + for(i = yr1; i <= yr2; i++) + { + log_sel(kgear)(igrp)(i) -= log( mean(mfexp(log_sel(kgear)(ig)(i))) ); + } } if( !ptrSlxM ) delete ptrSlxM; From 31b24c02ac5a1f24e70e08b08c6cec44ff5b0344 Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 17 Apr 2015 18:33:33 -0700 Subject: [PATCH 51/61] Added penalties to objective function for NEW_SELEX --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 22 +++-- src/admb-code/iscam.tpl | 110 ++++++++++++++++++++-- 2 files changed, 119 insertions(+), 13 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index f12a1af4..5ee6f48e 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -85,13 +85,13 @@ ## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 3 10 2.0 0 5 0 2 0.0 0.0 0.0 1888 2014 + 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 - 5 3 10 2.0 0 5 0 -1 0.0 0.0 0.0 1888 2014 - 6 5 3.0 2.0 1 5 5 2 0.0 0.0 0.0 1888 2014 - 6 5 3.0 2.0 2 5 5 2 0.0 0.0 0.0 1888 2014 + 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 + 6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 + 6 5 3.0 2.0 2 5 5 2 12.5 200 50.5 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls @@ -106,8 +106,18 @@ -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 - - +## ———————————————————————————————————————————————————————————————————————————————————— ## +## LEGEND FOR SELECTIVITY TYPES (sel_type) ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel | No. | +## type | parameters | Description +## ———————————————————————————————————————————————————————————————————————————————————— ## +## 1 | 2 | • Logistic curve with mean and standard dev at age = p(50%) +## 2 | (nages-1) | • Age-specific selectivity coefficients for (sage):(nage-1) +## 3 | age_nodes | • Age-specific coefficients based on cubic-spline interpolation +## 4 | n*age_nodes| • Annual age-specific coeffs using cubic-spline interpolation +## 5 | nyr*nage | • Bicubic spline interpolation over time & age. +## ———————————————————————————————————————————————————————————————————————————————————— ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index abf5f9eb..91ae5a6c 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1091,7 +1091,7 @@ DATA_SECTION !! slx_nrow = sum(column(slx_nBlocks,1)); !! ret_nrow = sum(column(slx_nBlocks,2)); init_matrix slx_dControls(1,slx_nrow,1,13); - init_matrix ret_dControls(1,slx_nrow,1,13); + init_matrix ret_dControls(1,ret_nrow,1,13); ivector slx_nGearIndex(1,slx_nrow); /// index for fishing gear. ivector slx_nIpar(1,slx_nrow); /// number of rows for each slx @@ -1103,6 +1103,10 @@ DATA_SECTION ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. ivector slx_nsb(1,slx_nrow); /// start of block year. ivector slx_neb(1,slx_nrow); /// end of block year. + vector slx_lam1(1,slx_nrow); + vector slx_lam2(1,slx_nrow); + vector slx_lam3(1,slx_nrow); + LOC_CALCS slx_nGearIndex = ivector(column(slx_dControls,1)); @@ -1113,6 +1117,9 @@ DATA_SECTION slx_phz = ivector(column(slx_dControls,8)); slx_nsb = ivector(column(slx_dControls,12)); slx_neb = ivector(column(slx_dControls,13)); + slx_lam1 = column(slx_dControls,9); + slx_lam2 = column(slx_dControls,10); + slx_lam3 = column(slx_dControls,11); // • Count number of selectivity parameters required for each slx_type for(i = 1; i <= slx_nrow; i++) @@ -1175,7 +1182,7 @@ DATA_SECTION break; } } - + COUT(slx_nrow); cout<<"Ok after new selex stuff in data section"< slx_nsb(k)?syr:slx_nsb(k); @@ -3639,9 +3648,62 @@ FUNCTION calcObjectiveFunction dvar_vector lvec(1,7); lvec.initialize(); int ig; + #ifdef NEW_SELEX + for(int kr = 1; kr <= slx_nrow; kr++ ) + { + int yr1 = syr>slx_nsb(kr)?syr:slx_nsb(kr); + int yr2 = nyr 0) + { + nlvec(7,k) += slx_lam2(k) * square(diff); + } + } + } + } + } + + // penalty in time-varying changes (nlvec(8,k)). + if( slx_nSelType(kr) == 4 || slx_nSelType(kr) == 5) + { + for(ig=1;ig<=n_ags;ig++) + { + dvar_matrix trans_log_sel = trans( log_sel(k)(ig) ); + for(j=sage;j<=nage;j++) + { + dvar_vector df1 = first_difference(trans_log_sel(j)); + dvar_vector df2 = first_difference(df1); + nlvec(8,k) += slx_lam3(k)/(nage-sage+1)*norm2(df2); + } + } + } + } + + } + #endif + + #ifndef NEW_SELEX for(k=1;k<=ngear;k++) { - if(active(sel_par(k))) + + if( active(sel_par(k)) ) { //if not using logistic selectivity then //CHANGED from || to && May 18, 2011 Vivian @@ -3689,13 +3751,46 @@ FUNCTION calcObjectiveFunction } } - + #endif // |---------------------------------------------------------------------------------| // | CONSTRAINTS FOR SELECTIVITY DEVIATION VECTORS // |---------------------------------------------------------------------------------| // | [?] - TODO for isel_type==2 ensure mean 0 as well. // | + + #ifdef NEW_SELEX + for(k=1;k<=ngear;k++) + { + if( active(slx_log_par(k)) && slx_nSelType(k)!=1 ) + { + dvariable s = 0; + if(slx_nSelType(k)==5) //bicubic spline version ensure column mean = 0 + { + dvar_matrix tmp = trans(slx_log_par(k)); + for(j=1;j<=tmp.rowmax();j++) + { + s=mean(tmp(j)); + lvec(1)+=10000.0*s*s; + } + } + if( slx_nSelType(k)==2 || + slx_nSelType(k)==3 || + slx_nSelType(k)==4 || + slx_nSelType(k)==12 ) + { + dvar_matrix tmp = slx_log_par(k); + for(j=1;j<=tmp.rowmax();j++) + { + s=mean(tmp(j)); + lvec(1)+=10000.0*s*s; + } + } + } + } + #endif + + #ifndef NEW_SELEX for(k=1;k<=ngear;k++) { if( active(sel_par(k)) && @@ -3728,6 +3823,7 @@ FUNCTION calcObjectiveFunction } } } + #endif // |---------------------------------------------------------------------------------| From 497dfdfec183724e00da2374ce881fa75bc7014f Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Fri, 17 Apr 2015 18:44:52 -0700 Subject: [PATCH 52/61] Stash with NEW_SELEX undefined --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 114 +++++++++++----------- src/admb-code/iscam.tpl | 4 +- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 5ee6f48e..8b1a3067 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -15,8 +15,8 @@ ## npar 7 ## ival lb ub phz prior p1 p2 #parameter ## - 7.0 0.0 10 4 0 0.0 12.0 #log_ro ## - 0.75 0.2 1.0 4 3 3.00 2.00 #steepness ## + 7.0 0.0 10 4 0 0.0 10.0 #log_ro ## + 0.75 0.2 1.0 4 3 1.01 1.01 #steepness ## -1.89712 -3.0 2.0 -4 1 -1.203 0.15 #log_m g&b ## 6.5 0.0 10 1 0 0.0 10 #log_avgrec ## 7.5 0.0 10 1 0 0.0 10 #log_recinit ## @@ -50,61 +50,61 @@ -## ———————————————————————————————————————————————————————————————————————————————————— ## -## SELECTIVITY CONTROLS ## -## ———————————————————————————————————————————————————————————————————————————————————— ## -## - Each gear must have at least one selectivity and retention curve. -## - Use a -ve phase with the gear index to mirror another gear. Note -## that if you mirror another gear, it must have the same sel type and -## age and year nodes so that the arrays are the same shape & block years. -## -## • Index = gear index for selectivity curve. -## • sel_type = type of selectivity function (see Legend). -## • sel_mu = mean age/length 50% selectivity. -## • sel_sd = std in 50% selectivity -## • sex_dep = 0 -> no; 1 -> offset for sex 2. -## • size_nodes = # of nodes for age/size cubic spline. -## • year_nodes = # of nodes for time varying bicubic spline. -## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) -## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). -## • lam2 = penalty weight for dome-shaped selectivity. -## • lam3 = penalty weight for time-varying selectivity. -## • start_block = year index for first year of selectivity curve. -## ———————————————————————————————————————————————————————————————————————————————————— ## -## sel_nBlocks ret_nBlocks ## Gear Description. - 1 1 ## Commercial retained - 1 1 ## Commercial discards - 1 1 ## Bycatch in non-directed fisheries. - 1 1 ## Sport - 1 1 ## Personal use - 2 1 ## Setline survey. -## ———————————————————————————————————————————————————————————————————————————————————— ## -## Selectivity P(capture of all size/age) -## slx_dControls -## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz or start end ## -## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 - 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 - 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 - 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 - 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 - 6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 - 6 5 3.0 2.0 2 5 5 2 12.5 200 50.5 1888 2014 -## ———————————————————————————————————————————————————————————————————————————————————— ## -## Retention P(retaining size/age) -## ret_dControls -## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz or start end ## -## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ———————————————————————————————————————————————————————————————————————————————————— ## - -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 - -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 - -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 - -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 - -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## SELECTIVITY CONTROLS ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## - Each gear must have at least one selectivity and retention curve. +## ## - Use a -ve phase with the gear index to mirror another gear. Note +## ## that if you mirror another gear, it must have the same sel type and +## ## age and year nodes so that the arrays are the same shape & block years. +## ## +## ## • Index = gear index for selectivity curve. +## ## • sel_type = type of selectivity function (see Legend). +## ## • sel_mu = mean age/length 50% selectivity. +## ## • sel_sd = std in 50% selectivity +## ## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## ## • size_nodes = # of nodes for age/size cubic spline. +## ## • year_nodes = # of nodes for time varying bicubic spline. +## ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## ## • lam2 = penalty weight for dome-shaped selectivity. +## ## • lam3 = penalty weight for time-varying selectivity. +## ## • start_block = year index for first year of selectivity curve. +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## sel_nBlocks ret_nBlocks ## Gear Description. +## 1 1 ## Commercial retained +## 1 1 ## Commercial discards +## 1 1 ## Bycatch in non-directed fisheries. +## 1 1 ## Sport +## 1 1 ## Personal use +## 2 1 ## Setline survey. +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## Selectivity P(capture of all size/age) +## ## slx_dControls +## ## • index for sex (0=both, 1=female, 2=male) +## ## sel sel sel age year phz or start end ## +## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 +## 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 +## 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 +## 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 +## 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 +## 6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 +## 6 5 3.0 2.0 2 5 5 2 12.5 200 50.5 1888 2014 +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## Retention P(retaining size/age) +## ## ret_dControls +## ## • index for sex (0=both, 1=female, 2=male) +## ## sel sel sel age year phz or start end ## +## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 +## -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 +## -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 +## -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 +## -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 +## -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## LEGEND FOR SELECTIVITY TYPES (sel_type) ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 91ae5a6c..99b626da 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -3789,7 +3789,7 @@ FUNCTION calcObjectiveFunction } } #endif - + #ifndef NEW_SELEX for(k=1;k<=ngear;k++) { @@ -5833,7 +5833,7 @@ GLOBALS_SECTION * \def NEW_SELEX * Testing new selectivity controls. */ - #define NEW_SELEX + //#define NEW_SELEX /** \def REPORT(object) From e451a96afeb7fa11b4fad72bc81d3c734a314b1c Mon Sep 17 00:00:00 2001 From: Steve Martell Date: Sat, 18 Apr 2015 22:13:19 -0700 Subject: [PATCH 53/61] Still working on penalties and constraints for new slx params. --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 110 +++++++++++----------- fba/HALIBUT/R/R4iSCAM.R | 6 ++ src/R/lib/plotAgeBars.R | 10 +- src/admb-code/iscam.tpl | 37 ++++++-- 4 files changed, 100 insertions(+), 63 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index 8b1a3067..b51c6d64 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -50,61 +50,61 @@ -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## SELECTIVITY CONTROLS ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## - Each gear must have at least one selectivity and retention curve. -## ## - Use a -ve phase with the gear index to mirror another gear. Note -## ## that if you mirror another gear, it must have the same sel type and -## ## age and year nodes so that the arrays are the same shape & block years. -## ## -## ## • Index = gear index for selectivity curve. -## ## • sel_type = type of selectivity function (see Legend). -## ## • sel_mu = mean age/length 50% selectivity. -## ## • sel_sd = std in 50% selectivity -## ## • sex_dep = 0 -> no; 1 -> offset for sex 2. -## ## • size_nodes = # of nodes for age/size cubic spline. -## ## • year_nodes = # of nodes for time varying bicubic spline. -## ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) -## ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). -## ## • lam2 = penalty weight for dome-shaped selectivity. -## ## • lam3 = penalty weight for time-varying selectivity. -## ## • start_block = year index for first year of selectivity curve. -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## sel_nBlocks ret_nBlocks ## Gear Description. -## 1 1 ## Commercial retained -## 1 1 ## Commercial discards -## 1 1 ## Bycatch in non-directed fisheries. -## 1 1 ## Sport -## 1 1 ## Personal use -## 2 1 ## Setline survey. -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## Selectivity P(capture of all size/age) -## ## slx_dControls -## ## • index for sex (0=both, 1=female, 2=male) -## ## sel sel sel age year phz or start end ## -## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 -## 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 -## 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 -## 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 -## 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 -## 6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 -## 6 5 3.0 2.0 2 5 5 2 12.5 200 50.5 1888 2014 -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## Retention P(retaining size/age) -## ## ret_dControls -## ## • index for sex (0=both, 1=female, 2=male) -## ## sel sel sel age year phz or start end ## -## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 -## -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 -## -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 -## -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 -## -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 -## -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## SELECTIVITY CONTROLS ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## - Each gear must have at least one selectivity and retention curve. +## - Use a -ve phase with the gear index to mirror another gear. Note +## that if you mirror another gear, it must have the same sel type and +## age and year nodes so that the arrays are the same shape & block years. +## +## • Index = gear index for selectivity curve. +## • sel_type = type of selectivity function (see Legend). +## • sel_mu = mean age/length 50% selectivity. +## • sel_sd = std in 50% selectivity +## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## • size_nodes = # of nodes for age/size cubic spline. +## • year_nodes = # of nodes for time varying bicubic spline. +## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## • lam2 = penalty weight for dome-shaped selectivity. +## • lam3 = penalty weight for time-varying selectivity. +## • start_block = year index for first year of selectivity curve. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel_nBlocks ret_nBlocks ## Gear Description. + 1 1 ## Commercial retained + 1 1 ## Commercial discards + 1 1 ## Bycatch in non-directed fisheries. + 1 1 ## Sport + 1 1 ## Personal use + 2 1 ## Setline survey. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Selectivity P(capture of all size/age) +## slx_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 + 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 + 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 + 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 + 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 + 6 5 3.0 2.0 1 5 6 2 12.5 200 50.5 1888 2014 + 6 5 3.0 2.0 2 5 6 2 12.5 200 50.5 1888 2014 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Retention P(retaining size/age) +## ret_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 + -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 + -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 + -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 + -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## LEGEND FOR SELECTIVITY TYPES (sel_type) ## diff --git a/fba/HALIBUT/R/R4iSCAM.R b/fba/HALIBUT/R/R4iSCAM.R index fd825190..f2abbc8a 100644 --- a/fba/HALIBUT/R/R4iSCAM.R +++ b/fba/HALIBUT/R/R4iSCAM.R @@ -27,6 +27,12 @@ setwd(.PWD) .THEME <- theme_bw(12) .UNITS <- "(mlb)" +# | Labels for gear sex area and group index. +.GEAR = c("Directed","Wasteage","Bycatch","Sport","Personal","Setline Survey") +.SEX = c("F & M","Female","Male") +.AREA = c("Coast wide") +.GROUP = c("Pacific Halibut") + .srcRlib <- function() { diff --git a/src/R/lib/plotAgeBars.R b/src/R/lib/plotAgeBars.R index afaa9d45..2e676e19 100644 --- a/src/R/lib/plotAgeBars.R +++ b/src/R/lib/plotAgeBars.R @@ -2,6 +2,7 @@ library(reshape2) library(ggplot2) + .plotAgeBars <- function( M ) { n <- length( M ) @@ -48,12 +49,19 @@ library(ggplot2) O <- subset(mB,V=="Observed") I <- subset(mB,V=="Predicted") + klbl <- .GEAR[O$Gear] + albl <- .AREA[O$Area] + glbl <- .GROUP[O$Group] + slbl <- .SEX[O$Sex+1] + p <- ggplot(O,aes(variable,as.double(value),fill=BroodYear)) p <- p + geom_bar(stat="identity",alpha=0.7) + p <- p + scale_fill_distiller(type = "div") p <- p + geom_line(data=I,aes(as.numeric(variable),value),color="red") p <- p + labs(x="Age",y="Proportion") + p <- p + ggtitle(paste(klbl,":Area",albl,":Group",glbl,":Sex",slbl)) p <- p + guides(title.position = "top") - p <- p + facet_wrap(~Year,nrow=4)+coord_flip() + p <- p + facet_wrap(~Year)+coord_flip() return (p + .THEME + theme(legend.position="top") + theme_bw(8)) } diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 99b626da..b803768b 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1103,9 +1103,11 @@ DATA_SECTION ivector slx_phz(1,slx_nrow); /// phase of estimation or mirror index. ivector slx_nsb(1,slx_nrow); /// start of block year. ivector slx_neb(1,slx_nrow); /// end of block year. - vector slx_lam1(1,slx_nrow); - vector slx_lam2(1,slx_nrow); - vector slx_lam3(1,slx_nrow); + vector slx_sel_mu(1,slx_nrow); + vector slx_sel_sd(1,slx_nrow); + vector slx_lam1(1,slx_nrow); + vector slx_lam2(1,slx_nrow); + vector slx_lam3(1,slx_nrow); LOC_CALCS @@ -1117,6 +1119,8 @@ DATA_SECTION slx_phz = ivector(column(slx_dControls,8)); slx_nsb = ivector(column(slx_dControls,12)); slx_neb = ivector(column(slx_dControls,13)); + slx_sel_mu = column(slx_dControls,3); + slx_sel_sd = column(slx_dControls,4); slx_lam1 = column(slx_dControls,9); slx_lam2 = column(slx_dControls,10); slx_lam3 = column(slx_dControls,11); @@ -1585,6 +1589,25 @@ PARAMETER_SECTION !! #ifdef NEW_SELEX init_bounded_matrix_vector slx_log_par(1,slx_nrow,1,slx_nIpar,1,slx_nJpar,-25.0,25.0,slx_phz); // TO DO set initial values for slx parameters. + LOC_CALCS + if( !global_parfile ) + { + for(int k = 1; k <= slx_nrow; k++ ) + { + if(slx_nSelType(k)==1) + { + for(int j = 1; j <= slx_nIpar(k); j++ ) + { + cout<<"Made it here"< *ptrSlxM = NULL; - + cout<<"Made it here "< Date: Sun, 19 Apr 2015 20:23:28 -0700 Subject: [PATCH 54/61] commented out define NEW_SELEX. Issue with transposing the parameters for bicubic splines --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 114 +++++++++++----------- src/admb-code/iscam.tpl | 17 ++-- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index b51c6d64..db19fcd8 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -50,62 +50,62 @@ -## ———————————————————————————————————————————————————————————————————————————————————— ## -## SELECTIVITY CONTROLS ## -## ———————————————————————————————————————————————————————————————————————————————————— ## -## - Each gear must have at least one selectivity and retention curve. -## - Use a -ve phase with the gear index to mirror another gear. Note -## that if you mirror another gear, it must have the same sel type and -## age and year nodes so that the arrays are the same shape & block years. -## -## • Index = gear index for selectivity curve. -## • sel_type = type of selectivity function (see Legend). -## • sel_mu = mean age/length 50% selectivity. -## • sel_sd = std in 50% selectivity -## • sex_dep = 0 -> no; 1 -> offset for sex 2. -## • size_nodes = # of nodes for age/size cubic spline. -## • year_nodes = # of nodes for time varying bicubic spline. -## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) -## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). -## • lam2 = penalty weight for dome-shaped selectivity. -## • lam3 = penalty weight for time-varying selectivity. -## • start_block = year index for first year of selectivity curve. -## ———————————————————————————————————————————————————————————————————————————————————— ## -## sel_nBlocks ret_nBlocks ## Gear Description. - 1 1 ## Commercial retained - 1 1 ## Commercial discards - 1 1 ## Bycatch in non-directed fisheries. - 1 1 ## Sport - 1 1 ## Personal use - 2 1 ## Setline survey. -## ———————————————————————————————————————————————————————————————————————————————————— ## -## Selectivity P(capture of all size/age) -## slx_dControls -## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz or start end ## -## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 - 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 - 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 - 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 - 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 - 6 5 3.0 2.0 1 5 6 2 12.5 200 50.5 1888 2014 - 6 5 3.0 2.0 2 5 6 2 12.5 200 50.5 1888 2014 -## ———————————————————————————————————————————————————————————————————————————————————— ## -## Retention P(retaining size/age) -## ret_dControls -## • index for sex (0=both, 1=female, 2=male) -## sel sel sel age year phz or start end ## -## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ———————————————————————————————————————————————————————————————————————————————————— ## - -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 - -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 - -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 - -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 - -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 - -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 - +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## SELECTIVITY CONTROLS ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## - Each gear must have at least one selectivity and retention curve. +## ## - Use a -ve phase with the gear index to mirror another gear. Note +## ## that if you mirror another gear, it must have the same sel type and +## ## age and year nodes so that the arrays are the same shape & block years. +## ## +## ## • Index = gear index for selectivity curve. +## ## • sel_type = type of selectivity function (see Legend). +## ## • sel_mu = mean age/length 50% selectivity. +## ## • sel_sd = std in 50% selectivity +## ## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## ## • size_nodes = # of nodes for age/size cubic spline. +## ## • year_nodes = # of nodes for time varying bicubic spline. +## ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## ## • lam2 = penalty weight for dome-shaped selectivity. +## ## • lam3 = penalty weight for time-varying selectivity. +## ## • start_block = year index for first year of selectivity curve. +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## sel_nBlocks ret_nBlocks ## Gear Description. +## 1 1 ## Commercial retained +## 1 1 ## Commercial discards +## 1 1 ## Bycatch in non-directed fisheries. +## 1 1 ## Sport +## 1 1 ## Personal use +## 2 1 ## Setline survey. +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## Selectivity P(capture of all size/age) +## ## slx_dControls +## ## • index for sex (0=both, 1=female, 2=male) +## ## sel sel sel age year phz or start end ## +## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 +## 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 +## 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 +## 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 +## 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 +## 6 5 3.0 2.0 1 5 6 2 12.5 200 50.5 1888 2014 +## 6 5 3.0 2.0 2 5 6 2 12.5 200 50.5 1888 2014 +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## ## Retention P(retaining size/age) +## ## ret_dControls +## ## • index for sex (0=both, 1=female, 2=male) +## ## sel sel sel age year phz or start end ## +## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ## ———————————————————————————————————————————————————————————————————————————————————— ## +## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 +## -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 +## -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 +## -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 +## -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 +## -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 +## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## LEGEND FOR SELECTIVITY TYPES (sel_type) ## ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -146,7 +146,7 @@ 82 3.0 4.0 4.0 3.0 65.0 # 2 -Age/length at 50% selectivity (logistic) 5.5 1.5 2.5 2.0 2.5 5.5 # 3 -STD at 50% selectivity (logistic) 5 0 0 0 5 5 # 4 -No. of age nodes for each gear (0=ignore) - 0 0 0 0 0 5 # 5 -No. of year nodes for 2d spline(0=ignore) + 0 0 0 0 0 6 # 5 -No. of year nodes for 2d spline(0=ignore) 2 -2 -3 -4 -1 2 # 6 -Phase of estimation (-1 for fixed) 0.0 0.0 0.0 0.0 0.0 12.5 # 7 -Penalty wt for 2nd differences w=1/(2*sig^2) 200.0 200.0 200.0 200.0 200.0 200.0 # 8 -Penalty wt for dome-shaped w=1/(2*sig^2) diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index b803768b..d0fdb351 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2141,11 +2141,12 @@ FUNCTION calcSelex // The following is used to mirror another gear-type // based on the absolute value of sel_phz. k = kr; - if(sel_phz(k) < 0) + if(slx_phz(k) < 0) { - k = abs(sel_phz(kr)); + k = abs(slx_phz(kr)); slx_log_par(kr) = slx_log_par(k); } + //cout<<"Made it here "< slx_nsb(k)?syr:slx_nsb(k); int yr2 = nyr < slx_neb(k)?nyr:slx_neb(k); @@ -2157,7 +2158,6 @@ FUNCTION calcSelex } slx::slxInterface *ptrSlxM = NULL; - cout<<"Made it here "< Date: Mon, 20 Apr 2015 15:18:40 -0700 Subject: [PATCH 55/61] More tweaks to Selectivity and control file for halibut --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 145 +++++++++++----------- fba/HALIBUT/R/R4iSCAM.R | 1 + src/admb-code/include/selex.hpp | 2 +- src/admb-code/iscam.tpl | 30 +++-- 4 files changed, 92 insertions(+), 86 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index db19fcd8..c6f8ab35 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -1,9 +1,8 @@ -## ------------------------------------------------------------------------- ## -## CONTROL FILE TEMPLATE ## -## ------------------------------------------------------------------------- ## -## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## CONTROL FILE TEMPLATE ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## CONTROLS FOR LEADING PARAMETERS ## ## Prior descriptions: ## ## -0 uniform (0,0) ## @@ -11,19 +10,19 @@ ## -2 lognormal (p1=log(mu),p2=sig) ## ## -3 beta (p1=alpha,p2=beta) ## ## -4 gamma (p1=alpha,p2=beta) ## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## npar 7 -## ival lb ub phz prior p1 p2 #parameter ## - 7.0 0.0 10 4 0 0.0 10.0 #log_ro ## - 0.75 0.2 1.0 4 3 1.01 1.01 #steepness ## - -1.89712 -3.0 2.0 -4 1 -1.203 0.15 #log_m g&b ## - 6.5 0.0 10 1 0 0.0 10 #log_avgrec ## - 7.5 0.0 10 1 0 0.0 10 #log_recinit ## - 0.00 0.00 1.00 -3 3 3.00 5.00 #rho ## - 0.6 0.01 5.0 -3 4 1.01 1.01 #sigma_r ## - -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## ival lb ub phz prior p1 p2 #parameter ## + 7.0 0.0 10 4 0 0.0 10.0 #log_ro ## + 0.75 0.2 1.0 4 3 1.01 1.01 #steepness ## + -1.89712 -3.0 2.0 2 1 -1.89712 0.15 #log_m g&b ## + 6.5 0.0 10 1 0 0.0 10 #log_avgrec ## + 7.5 0.0 10 1 0 0.0 10 #log_recinit ## + 0.00 0.00 1.00 -3 3 3.00 5.00 #rho ## + 0.6 0.01 5.0 -3 4 1.01 1.01 #sigma_r ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## @@ -50,62 +49,62 @@ -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## SELECTIVITY CONTROLS ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## - Each gear must have at least one selectivity and retention curve. -## ## - Use a -ve phase with the gear index to mirror another gear. Note -## ## that if you mirror another gear, it must have the same sel type and -## ## age and year nodes so that the arrays are the same shape & block years. -## ## -## ## • Index = gear index for selectivity curve. -## ## • sel_type = type of selectivity function (see Legend). -## ## • sel_mu = mean age/length 50% selectivity. -## ## • sel_sd = std in 50% selectivity -## ## • sex_dep = 0 -> no; 1 -> offset for sex 2. -## ## • size_nodes = # of nodes for age/size cubic spline. -## ## • year_nodes = # of nodes for time varying bicubic spline. -## ## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) -## ## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). -## ## • lam2 = penalty weight for dome-shaped selectivity. -## ## • lam3 = penalty weight for time-varying selectivity. -## ## • start_block = year index for first year of selectivity curve. -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## sel_nBlocks ret_nBlocks ## Gear Description. -## 1 1 ## Commercial retained -## 1 1 ## Commercial discards -## 1 1 ## Bycatch in non-directed fisheries. -## 1 1 ## Sport -## 1 1 ## Personal use -## 2 1 ## Setline survey. -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## Selectivity P(capture of all size/age) -## ## slx_dControls -## ## • index for sex (0=both, 1=female, 2=male) -## ## sel sel sel age year phz or start end ## -## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## 1 3 10 2.0 0 5 0 2 0.0 200 50.5 1888 2014 -## 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 -## 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 -## 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 -## 5 3 10 2.0 0 5 0 -1 0.0 200 50.5 1888 2014 -## 6 5 3.0 2.0 1 5 6 2 12.5 200 50.5 1888 2014 -## 6 5 3.0 2.0 2 5 6 2 12.5 200 50.5 1888 2014 -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## ## Retention P(retaining size/age) -## ## ret_dControls -## ## • index for sex (0=both, 1=female, 2=male) -## ## sel sel sel age year phz or start end ## -## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## -## ## ———————————————————————————————————————————————————————————————————————————————————— ## -## -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 -## -2 1 3.0 1.5 0 5 0 -2 0.0 200 50.5 1888 2014 -## -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 -## -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 -## -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1888 2014 -## -6 5 3.0 2.0 1 5 5 2 12.5 200 50.5 1888 2014 -## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## SELECTIVITY CONTROLS ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## - Each gear must have at least one selectivity and retention curve. +## - Use a -ve phase with the gear index to mirror another gear. Note +## that if you mirror another gear, it must have the same sel type and +## age and year nodes so that the arrays are the same shape & block years. +## +## • Index = gear index for selectivity curve. +## • sel_type = type of selectivity function (see Legend). +## • sel_mu = mean age/length 50% selectivity. +## • sel_sd = std in 50% selectivity +## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## • size_nodes = # of nodes for age/size cubic spline. +## • year_nodes = # of nodes for time varying bicubic spline. +## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## • lam2 = penalty weight for dome-shaped selectivity. +## • lam3 = penalty weight for time-varying selectivity. +## • start_block = year index for first year of selectivity curve. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel_nBlocks ret_nBlocks ## Gear Description. + 1 1 ## Commercial retained + 1 1 ## Commercial discards + 1 1 ## Bycatch in non-directed fisheries. + 1 1 ## Sport + 1 1 ## Personal use + 2 1 ## Setline survey. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Selectivity P(capture of all size/age) +## slx_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + 1 3 10 2.0 0 5 0 2 0.0 2.0 50.5 1888 2014 + 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 + 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 + 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 + 5 3 10 2.0 0 5 0 -1 0.0 2.0 50.5 1888 2014 + 6 5 3.0 2.0 1 5 6 2 12.5 2.0 50.5 1980 2014 + 6 5 3.0 2.0 2 5 6 2 12.5 2.0 50.5 1980 2014 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Retention P(retaining size/age) +## ret_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + -2 1 3.0 1.5 0 5 0 -2 0.0 2.0 50.5 1888 2014 + -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 + -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 + -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1980 2014 + -6 5 3.0 2.0 1 5 5 2 12.5 2.0 50.5 1980 2014 + ## ———————————————————————————————————————————————————————————————————————————————————— ## ## LEGEND FOR SELECTIVITY TYPES (sel_type) ## ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -146,7 +145,7 @@ 82 3.0 4.0 4.0 3.0 65.0 # 2 -Age/length at 50% selectivity (logistic) 5.5 1.5 2.5 2.0 2.5 5.5 # 3 -STD at 50% selectivity (logistic) 5 0 0 0 5 5 # 4 -No. of age nodes for each gear (0=ignore) - 0 0 0 0 0 6 # 5 -No. of year nodes for 2d spline(0=ignore) + 0 0 0 0 0 5 # 5 -No. of year nodes for 2d spline(0=ignore) 2 -2 -3 -4 -1 2 # 6 -Phase of estimation (-1 for fixed) 0.0 0.0 0.0 0.0 0.0 12.5 # 7 -Penalty wt for 2nd differences w=1/(2*sig^2) 200.0 200.0 200.0 200.0 200.0 200.0 # 8 -Penalty wt for dome-shaped w=1/(2*sig^2) diff --git a/fba/HALIBUT/R/R4iSCAM.R b/fba/HALIBUT/R/R4iSCAM.R index f2abbc8a..7205fdc9 100644 --- a/fba/HALIBUT/R/R4iSCAM.R +++ b/fba/HALIBUT/R/R4iSCAM.R @@ -80,6 +80,7 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotAgeCompResiduals( M ) .plotAgeSummary( M ) .plotAgeBars( M ) +.plotSlx( M ) # |----------------------------------------------------------------------------------| # | guiView: Main function for starting the iSCAM Gui diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index f01f8b9a..8eb90ba8 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -205,7 +205,7 @@ namespace slx { //cout<<"Evaluating BiCubicSpline"<(iag,iyr,slx_theta,tmp); + ptrSlxM = new slx::slx_BiCubicSpline(iyr,iag,slx_theta,tmp); + //COUT(ptrSlxM -> Evaluate()); break; } @@ -2258,7 +2260,7 @@ FUNCTION calcSelex // Fill matrix of selex if (ptrSlxM) { - log_sel(kgear)(igrp) = ptrSlxM -> Evaluate(); + log_sel(kgear)(igrp).sub(yr1,yr2) = ptrSlxM -> Evaluate(); } //subtract mean to ensure mean(exp(log_sel))==1 @@ -2274,7 +2276,7 @@ FUNCTION calcSelex } - //cout<<"End of CalcSelex"< Date: Tue, 21 Apr 2015 15:59:55 -0700 Subject: [PATCH 56/61] Run using bicubic splines for all fisheries. --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 4 +- src/admb-code/iscam.tpl | 73 +++-------------------- 2 files changed, 11 insertions(+), 66 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index c6f8ab35..be459893 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -84,11 +84,11 @@ ## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 3 10 2.0 0 5 0 2 0.0 2.0 50.5 1888 2014 + 1 5 10 2.0 0 5 6 2 12.5 2.0 50.5 1888 2014 2 1 3.0 1.5 0 0 0 -2 0.0 0.0 0.0 1888 2014 3 1 4.0 2.5 0 0 0 -3 0.0 0.0 0.0 1888 2014 4 1 4.0 2.0 0 0 0 -4 0.0 0.0 0.0 1888 2014 - 5 3 10 2.0 0 5 0 -1 0.0 2.0 50.5 1888 2014 + 5 5 10 2.0 0 5 6 -1 0.0 0.0 0.0 1888 2014 6 5 3.0 2.0 1 5 6 2 12.5 2.0 50.5 1980 2014 6 5 3.0 2.0 2 5 6 2 12.5 2.0 50.5 1980 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 490f0cfb..efa85fc5 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -1155,8 +1155,8 @@ DATA_SECTION // • bicubic spline over age-size / years case 5: - slx_nJpar(i) = slx_nAgeNodes(i); - slx_nIpar(i) = slx_nYrNodes(i); + slx_nIpar(i) = slx_nAgeNodes(i); + slx_nJpar(i) = slx_nYrNodes(i); break; // • logistic based on weight-at-age deviations. @@ -2208,7 +2208,7 @@ FUNCTION calcSelex dvar_matrix slx_theta = slx_log_par(k); tmp.initialize(); - ptrSlxM = new slx::slx_BiCubicSpline(iyr,iag,slx_theta,tmp); + ptrSlxM = new slx::slx_BiCubicSpline(iag,iyr,slx_theta,tmp); //COUT(ptrSlxM -> Evaluate()); break; @@ -3760,7 +3760,11 @@ FUNCTION calcObjectiveFunction Mar 13, 2013, added 2nd difference penalty on isel_type==5 */ - if( isel_type(k)==4 || isel_type(k)==5 || n_sel_blocks(k) > 1 ) + if( lambda_3(k) && + (isel_type(k)==4 || + isel_type(k)==5 || + n_sel_blocks(k) > 1) + ) { for(ig=1;ig<=n_ags;ig++) { @@ -3804,7 +3808,6 @@ FUNCTION calcObjectiveFunction if( slx_nSelType(k)==2 || slx_nSelType(k)==3 || slx_nSelType(k)==4 || - //slx_nSelType(k)==5 || slx_nSelType(k)==12 ) { dvar_matrix tmp = slx_log_par(k); @@ -5991,65 +5994,7 @@ GLOBALS_SECTION double dicValue = 0; - // DEPRECATE Testing bicubic spline to get indexing right. - void bbicubic_spline(const dvector& x, const dvector& y, dvar_matrix& knots, dvar_matrix& S) - { - /* - Author: Steven Martell - Date: July 29, 2010 - Comments: Based on code from Numerical Recipies. - - This function returns matrix S which is the interpolated values of knots - over knots[1..m][1..n] grid. - - first call splie2 to get second-derivatives at knot points - void splie2(const dvector& _x1a,const dvector& _x2a,const dmatrix& _ya,dvar_matrix& _y2a) - - then run the splin2 to get the spline points - dvariable splin2(const dvector& _x1a,const dvector* _x2a, const dmatrix _ya, - dvar_matrix& _y2a, const double& x1,const double& x2) - */ - RETURN_ARRAYS_INCREMENT(); - int i,j; - int m=knots.rowmax(); - int n=knots.colmax(); - - int mm=S.rowmax()-S.rowmin()+1; - int nn=S.colmax()-S.colmin()+1; - - dvar_matrix shift_S(1,mm,1,nn); - - dvector im(1,mm); im.fill_seqadd(0,1./(mm-1.)); - dvector in(1,nn); in.fill_seqadd(0,1./(nn-1.)); - dvar_matrix y2(1,m,1,n); //matrix of second-derivatives - COUT(x); - COUT(y.indexmin()); - COUT(knots) - y2=splie2(x,y,knots); - COUT("HERE IAM TO SAVE THE DAY") - - for(i=1;i<=mm;i++){ - for(j=1;j<=nn;j++){ - shift_S(i,j)=splin2(x,y,knots,y2,in(j),im(i)); - } - } - - int ii,jj; - ii=0; - for(i=S.rowmin();i<=S.rowmax();i++) - { - ii++; jj=0; - for(j=S.colmin();j<=S.colmax();j++) - { - jj++; - S(i,j)=shift_S(ii,jj); - } - } - - //cout< Date: Tue, 21 Apr 2015 20:34:03 -0700 Subject: [PATCH 57/61] Fixed bug in case 2 of calc_slx --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 8 +-- scripts/Template.ctl | 84 +++++++++++++++++++---- src/admb-code/include/selex.hpp | 20 ++++-- src/admb-code/iscam.tpl | 12 ++-- 4 files changed, 94 insertions(+), 30 deletions(-) diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index be459893..d4af2051 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -46,9 +46,7 @@ -2 -2 -2 -2 -2 -2 ## : phase for degrees of freedom for student T. -12345 ## : int check (-12345) ## ———————————————————————————————————————————————————————————————————————————————————— ## - - - +## ## ———————————————————————————————————————————————————————————————————————————————————— ## ## SELECTIVITY CONTROLS ## ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -98,12 +96,12 @@ ## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - -1 3 10 2.0 1 5 0 2 0.0 0.0 0.0 1888 2014 + -1 3 10 2.0 1 5 0 -2 0.0 0.0 0.0 1888 2014 -2 1 3.0 1.5 0 5 0 -2 0.0 2.0 50.5 1888 2014 -3 1 4.0 2.5 0 5 0 -3 0.0 0.0 0.0 1888 2014 -4 1 4.0 2.0 0 5 0 -4 0.0 0.0 0.0 1888 2014 -5 3 10 2.0 1 5 0 -1 0.0 0.0 0.0 1980 2014 - -6 5 3.0 2.0 1 5 5 2 12.5 2.0 50.5 1980 2014 + -6 5 3.0 2.0 1 5 5 -2 12.5 2.0 50.5 1980 2014 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## LEGEND FOR SELECTIVITY TYPES (sel_type) ## diff --git a/scripts/Template.ctl b/scripts/Template.ctl index f3ff2643..3b8b8207 100644 --- a/scripts/Template.ctl +++ b/scripts/Template.ctl @@ -24,9 +24,9 @@ 0.8 0.01 5.0 3 4 1.01 1.01 #vartheta ## ## ------------------------------------------------------------------------- ## ## -## ------------------------------------------------------------------------- ## -## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## Likelihood type for each gear: ## -1 : multivariate logistic (dmvlogistic) ## -2 : multinomial, sample size based on input data @@ -34,20 +34,74 @@ ## -4 : logistic_normal, AR1 ## -5 : logistic_normal, AR2 ## -6 : multinomial with estimated effective samples size (log_age_tau2 phz >0) -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## Number of columns == na_gears. - 1 ## Gear Index - 3 ## Likelihood type - 0.000 ## Minimum proportion for aggregation & tail compression - 0.0000 ## Small constant to add to comps & renormalize - 1 ## phase for log_age_tau2 estimation. - 2 ## phase for phi1 estimation: bounded (-1,1) AR1 - -2 ## phase for phi2 estimation: bounded (0,1) AR2 - -2 ## phase for degrees of freedom for student T. - -12345 ## int check (-12345) -## ------------------------------------------------------------------------- ## - + 1 ## • Gear Index + 3 ## • Likelihood type + 0.000 ## • Minimum proportion for aggregation & tail compression + 0.0000 ## • Small constant to add to comps & renormalize + 1 ## • phase for log_age_tau2 estimation. + 2 ## • phase for phi1 estimation: bounded (-1,1) AR1 + -2 ## • phase for phi2 estimation: bounded (0,1) AR2 + -2 ## • phase for degrees of freedom for student T. + -12345 ## • int check (-12345) +## ———————————————————————————————————————————————————————————————————————————————————— ## +## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## SELECTIVITY CONTROLS ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## - Each gear must have at least one selectivity and retention curve. +## - Use a -ve phase with the gear index to mirror another gear. Note +## that if you mirror another gear, it must have the same sel type and +## age and year nodes so that the arrays are the same shape & block years. ## +## • Index = gear index for selectivity curve. +## • sel_type = type of selectivity function (see Legend). +## • sel_mu = mean age/length 50% selectivity. +## • sel_sd = std in 50% selectivity +## • sex_dep = 0 -> no; 1 -> offset for sex 2. +## • size_nodes = # of nodes for age/size cubic spline. +## • year_nodes = # of nodes for time varying bicubic spline. +## • phz_mirror = phase of estimation (-ve phase to mirror selextivity index) +## • lam1 = penalty weight for 2nd differences (w = 1/(2•sig^2)). +## • lam2 = penalty weight for dome-shaped selectivity. +## • lam3 = penalty weight for time-varying selectivity. +## • start_block = year index for first year of selectivity curve. +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel_nBlocks ret_nBlocks ## Gear Description. + 1 1 ## Commercial retained +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Selectivity P(capture of all size/age) +## slx_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + 1 2 3.5 2.0 0 0 0 2 12.5 2.0 50.5 1968 1979 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## Retention P(retaining size/age) +## ret_dControls +## • index for sex (0=both, 1=female, 2=male) +## sel sel sel age year phz or start end ## +## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + -1 2 10 2.0 1 0 0 -2 0.0 0.0 0.0 1968 1979 +## ———————————————————————————————————————————————————————————————————————————————————— ## +## LEGEND FOR SELECTIVITY TYPES (sel_type) ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## sel | No. | +## type | parameters | Description +## ———————————————————————————————————————————————————————————————————————————————————— ## +## 1 | 2 | • Logistic curve with mean and standard dev at age = p(50%) +## 2 | (nages-1) | • Age-specific selectivity coefficients for (sage):(nage-1) +## 3 | age_nodes | • Age-specific coefficients based on cubic-spline interpolation +## 4 | n*age_nodes| • Annual age-specific coeffs using cubic-spline interpolation +## 5 | nyr*nage | • Bicubic spline interpolation over time & age. +## ———————————————————————————————————————————————————————————————————————————————————— ## + + + +## TO BE DEPRECATED ## ------------------------------------------------------------------------- ## ## SELECTIVITY PARAMETERS Columns for gear ## ## OPTIONS FOR SELECTIVITY (isel_type): ## diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 8eb90ba8..33c4002d 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -130,13 +130,23 @@ namespace slx { int x1 = m_x.indexmin(); int x2 = m_x.indexmax(); REAL_T log_sel(x1,x2); - - for(int i = s1; i <= s2; i++ ) + cout< slx_nsb(k)?syr:slx_nsb(k); int yr2 = nyr < slx_neb(k)?nyr:slx_neb(k); int nn = slx_nIpar(k)-1; + slx::slxInterface *ptrSlx[nn]; for( i = 0; i <= nn; i++ ) { @@ -2214,7 +2214,7 @@ FUNCTION calcSelex break; } - + cout<<"Made it here "< Evaluate(); + cout<<"Made it here "< Date: Tue, 21 Apr 2015 20:34:21 -0700 Subject: [PATCH 58/61] Fixed bug in case 2 of calc_slx --- src/admb-code/include/selex.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/admb-code/include/selex.hpp b/src/admb-code/include/selex.hpp index 33c4002d..b50af4da 100644 --- a/src/admb-code/include/selex.hpp +++ b/src/admb-code/include/selex.hpp @@ -130,8 +130,7 @@ namespace slx { int x1 = m_x.indexmin(); int x2 = m_x.indexmax(); REAL_T log_sel(x1,x2); - cout< Date: Tue, 21 Apr 2015 20:38:13 -0700 Subject: [PATCH 59/61] Updated template control file --- scripts/Template.ctl | 22 +++++++++++----------- src/admb-code/iscam.tpl | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/Template.ctl b/scripts/Template.ctl index 3b8b8207..39590847 100644 --- a/scripts/Template.ctl +++ b/scripts/Template.ctl @@ -77,7 +77,7 @@ ## sel sel sel age year phz or start end ## ## Index type mu sd sex nodes nodes mirror lam1 lam2 lam3 | block block ## ## ———————————————————————————————————————————————————————————————————————————————————— ## - 1 2 3.5 2.0 0 0 0 2 12.5 2.0 50.5 1968 1979 + 1 2 3.5 2.0 0 0 0 2 2.0 2.0 12.5 1968 1979 ## ———————————————————————————————————————————————————————————————————————————————————— ## ## Retention P(retaining size/age) ## ret_dControls @@ -118,16 +118,16 @@ ## sig=0.05 0.10 0.15 0.20 0.30 0.40 0.50 ## ## wt =200. 50.0 22.2 12.5 5.56 3.12 2.00 ## ## ------------------------------------------------------------------------- ## - 2 # 1 -selectivity type ivector(isel_type) for gear - 3.5 # 2 -Age/length at 50% selectivity (logistic) - 0.5 # 3 -STD at 50% selectivity (logistic) - 7 # 4 -No. of age nodes for each gear (0=ignore) - 12 # 5 -No. of year nodes for 2d spline(0=ignore) - 3 # 6 -Phase of estimation (-1 for fixed) - 2.00 # 7 -Penalty wt for 2nd differences w=1/(2*sig^2) - 2.00 # 8 -Penalty wt for dome-shaped w=1/(2*sig^2) - 12.5 # 9 -Penalty wt for time-varying selectivity - 1 # 10 -n_sel_blocks (number of selex blocks) + 2 # 1 -selectivity type ivector(isel_type) for gear + 3.5 # 2 -Age/length at 50% selectivity (logistic) + 0.5 # 3 -STD at 50% selectivity (logistic) + 7 # 4 -No. of age nodes for each gear (0=ignore) + 12 # 5 -No. of year nodes for 2d spline(0=ignore) + 3 # 6 -Phase of estimation (-1 for fixed) + 2.00 # 7 -Penalty wt for 2nd differences w=1/(2*sig^2) + 2.00 # 8 -Penalty wt for dome-shaped w=1/(2*sig^2) + 12.5 # 9 -Penalty wt for time-varying selectivity + 1 # 10 -n_sel_blocks (number of selex blocks) ## ------------------------------------------------------------------------- ## ## Start year of each time block: 1 row for each gear 1968 diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 478d7e7e..8b234008 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2128,9 +2128,9 @@ FUNCTION dvector cubic_spline(const dvector& spline_coffs, const dvector& la) FUNCTION calcSelex { - cout<<"START of CalcSelex"< Evaluate(); - cout<<"Made it here "< Date: Wed, 22 Apr 2015 09:15:40 -0700 Subject: [PATCH 60/61] FIxed relative paths in R4iSCAM.R --- examples/makeproject | 6 +++--- src/R/R4iSCAM.R | 4 ++-- src/admb-code/iscam.tpl | 18 ------------------ 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/examples/makeproject b/examples/makeproject index 80d27455..c1e1005b 100755 --- a/examples/makeproject +++ b/examples/makeproject @@ -28,10 +28,10 @@ gsed -i "0,/^CTL=/s/^CTL=/CTL=$1/" $1/DATA/Makefile cp ../scripts/Template.dat $1/DATA/$1.dat cp ../scripts/Template.ctl $1/DATA/$1.ctl -cp ../scripts/Template.pfc $1/DATA/$1.pfc -cp ../scripts/Template.mpc $1/DATA/$1.mpc +cp ../scripts/Template.pfc $1/DATA/$1.pfc +cp ../scripts/Template.mpc $1/DATA/$1.mpc cp ../scripts/Template.scn $1/DATA/$1.scn -cp ../scripts/buildRdata.R $1/R/buildRdata.R +cp ../scripts/buildRdata.R $1/R/buildRdata.R cp ../scripts/collectAll.R $1/R/collectAll.R cp ../scripts/saveMSEdataframe.R $1/R/saveMSEdataframe.R diff --git a/src/R/R4iSCAM.R b/src/R/R4iSCAM.R index 6908b9be..1edfccab 100644 --- a/src/R/R4iSCAM.R +++ b/src/R/R4iSCAM.R @@ -15,8 +15,8 @@ # | .RFILES <- List of R functions to source from the lib directory. # .PWD <- "/Users/stevenmartell1/Documents/iSCAM/examples/PacificHake14/R" .PWD <- "/Users/stevenmartell1/Documents/iSCAM-project/src/R" -.LIB <- "../../../dist/R/lib/" -.WIN <- "../../../dist/R/iScamWin2.txt" +.LIB <- "../../../src/R/lib/" +.WIN <- "../../../src/R/iScamWin2.txt" setwd(.PWD) .FIGUREDIR <- "../FIGS/" .RFILES <- list.files(.LIB,pattern="\\.[Rr]$") diff --git a/src/admb-code/iscam.tpl b/src/admb-code/iscam.tpl index 8b234008..9efb0765 100644 --- a/src/admb-code/iscam.tpl +++ b/src/admb-code/iscam.tpl @@ -2140,7 +2140,6 @@ FUNCTION calcSelex { // The following is used to mirror another gear-type // based on the absolute value of sel_phz. - if(slx_phz(k) < 0) { kr = abs(slx_phz(k)); @@ -2199,7 +2198,6 @@ FUNCTION calcSelex // • bicubic spline over age and year knots case 5: - //cout<<"Start of bicubic spline"<(iag,iyr,slx_theta,tmp); - - //COUT(ptrSlxM -> Evaluate()); break; } - - //cout<<"Made it here "< Evaluate(); - //cout<<"Made it here "< Date: Wed, 22 Apr 2015 09:55:16 -0700 Subject: [PATCH 61/61] Added new plotSelex.R script --- fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl | 2 +- scripts/Template.ctl | 88 ++++++++++++++--------- src/R/R4iSCAM.R | 9 ++- src/R/lib/plotSelex.R | 44 ++++++++++++ 4 files changed, 105 insertions(+), 38 deletions(-) create mode 100644 src/R/lib/plotSelex.R diff --git a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl index d4af2051..296fd100 100644 --- a/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl +++ b/fba/HALIBUT/DATA/DMVL1988/Halibut2014.ctl @@ -13,8 +13,8 @@ ## ———————————————————————————————————————————————————————————————————————————————————— ## ## npar 7 -## ———————————————————————————————————————————————————————————————————————————————————— ## ## ival lb ub phz prior p1 p2 #parameter ## +## ———————————————————————————————————————————————————————————————————————————————————— ## 7.0 0.0 10 4 0 0.0 10.0 #log_ro ## 0.75 0.2 1.0 4 3 1.01 1.01 #steepness ## -1.89712 -3.0 2.0 2 1 -1.89712 0.15 #log_m g&b ## diff --git a/scripts/Template.ctl b/scripts/Template.ctl index 39590847..04b1801d 100644 --- a/scripts/Template.ctl +++ b/scripts/Template.ctl @@ -1,29 +1,37 @@ -## ------------------------------------------------------------------------- ## -## CONTROL FILE TEMPLATE ## -## ------------------------------------------------------------------------- ## -## -## -## ------------------------------------------------------------------------- ## -## CONTROLS FOR LEADING PARAMETERS ## -## Prior descriptions: ## -## -0 uniform (0,0) ## -## -1 normal (p1=mu,p2=sig) ## -## -2 lognormal (p1=log(mu),p2=sig) ## -## -3 beta (p1=alpha,p2=beta) ## -## -4 gamma (p1=alpha,p2=beta) ## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## +## CONTROL FILE TEMPLATE ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + + + + + +## ———————————————————————————————————————————————————————————————————————————————————— ## +## CONTROLS FOR LEADING PARAMETERS ## +## Prior descriptions: ## +## -0 uniform (0,0) ## +## -1 normal (p1=mu,p2=sig) ## +## -2 lognormal (p1=log(mu),p2=sig) ## +## -3 beta (p1=alpha,p2=beta) ## +## -4 gamma (p1=alpha,p2=beta) ## +## ———————————————————————————————————————————————————————————————————————————————————— ## ## npar -7 -## ival lb ub phz prior p1 p2 #parameter ## - 1.0 0.0 10 2 0 0.0 10.0 #log_ro ## - 0.75 0.2 1.0 2 3 3.00 2.00 #steepness ## - -1.203973 -3.0 2.0 4 1 -1.203 0.15 #log_m g&b ## - 1.0 0.0 10 1 0 0.0 10 #log_avgrec ## - 1.0 0.0 10 1 0 0.0 10 #log_recinit ## - 0.5 0.01 0.99 3 3 3.00 5.00 #rho ## - 0.8 0.01 5.0 3 4 1.01 1.01 #vartheta ## -## ------------------------------------------------------------------------- ## -## + 7 +## ival lb ub phz prior p1 p2 #parameter ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + 1.0 0.0 10 2 0 0.0 10.0 #log_ro ## + 0.75 0.2 1.0 2 3 3.00 2.00 #steepness ## + -1.203973 -3.0 2.0 4 1 -1.203 0.15 #log_m g&b ## + 1.0 0.0 10 1 0 0.0 10 #log_avgrec ## + 1.0 0.0 10 1 0 0.0 10 #log_recinit ## + 0.00 0.00 1.00 -3 3 3.00 5.00 #rho ## + 0.6 0.01 5.0 -3 4 1.01 1.01 #sigma_r ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + + + + + ## ———————————————————————————————————————————————————————————————————————————————————— ## ## CONTROL PARAMETERS FOR AGE/SIZE COMPOSITION DATA FOR na_gears ## ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -101,6 +109,8 @@ + + ## TO BE DEPRECATED ## ------------------------------------------------------------------------- ## ## SELECTIVITY PARAMETERS Columns for gear ## @@ -152,8 +162,11 @@ ## Year position of the knots (vector must be equal to the number of nodes) ## ———————————————————————————————————————————————————————————————————————————————————— ## -## -## + + + + + ## ———————————————————————————————————————————————————————————————————————————————————— ## ## ABUNDANCE OBSERVATION MODELS ## ———————————————————————————————————————————————————————————————————————————————————— ## @@ -168,12 +181,14 @@ 0 # -prior sd (set to 0 for uniformative prior) 1 # -Estimation phase ## ———————————————————————————————————————————————————————————————————————————————————— ## -## -## ------------------------------------------------------------------------- ## -## OTHER MISCELANEOUS CONTROLS ## -## ------------------------------------------------------------------------- ## + + + +## ———————————————————————————————————————————————————————————————————————————————————— ## +## OTHER MISCELANEOUS CONTROLS ## +## ———————————————————————————————————————————————————————————————————————————————————— ## 0 # 1 -verbose ADMB output (0=off, 1=on) 1 # 2 -recruitment model (1=beverton-holt, 2=ricker) 0.100 # 3 -std in observed catches in first phase. @@ -189,8 +204,13 @@ 0.50 # 13 -fraction of total mortality that takes place prior to spawning 0 # 14 -number of prospective years to add to syr. 0 # 15 -switch for IFD distribution in selectivity simulations -## -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## + + + + + +## ———————————————————————————————————————————————————————————————————————————————————— ## ## MARKER FOR END OF CONTROL FILE (eofc) -## ------------------------------------------------------------------------- ## +## ———————————————————————————————————————————————————————————————————————————————————— ## 999 \ No newline at end of file diff --git a/src/R/R4iSCAM.R b/src/R/R4iSCAM.R index 1edfccab..ee134c17 100644 --- a/src/R/R4iSCAM.R +++ b/src/R/R4iSCAM.R @@ -37,9 +37,6 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotCatch( M ) .plotIndex( M ) .plotWeightAtAge( M ) -.plotAgeComps( M ) -.plotAgeCompResiduals( M ) -.plotAgeSummary( M ) .plotSpawnBiomass( M ) .plotDepletion( M ) .plotMortality( M ) @@ -47,9 +44,15 @@ for(nm in .RFILES) source(file.path(.LIB, nm), echo=FALSE) .plotStockRecruit( M ) .plotRecruitsPerSpawner( M ) .plotSurveyFit( M ) +.plotQ( M ) .plotCatchResidual( M ) .plotIndexResidual( M ) .plotRecruitmentResidual( M ) +.plotAgeComps( M ) +.plotAgeCompResiduals( M ) +.plotAgeSummary( M ) +.plotAgeBars( M ) +.plotSlx( M ) # |----------------------------------------------------------------------------------| diff --git a/src/R/lib/plotSelex.R b/src/R/lib/plotSelex.R new file mode 100644 index 00000000..fa21f536 --- /dev/null +++ b/src/R/lib/plotSelex.R @@ -0,0 +1,44 @@ +# plotSelex.R +library(reshape2) +library(ggplot2) +library(dplyr) +library(gridExtra) + +.plotSlx <- function( M ) +{ + n <- length(M) + cat("plotSlx\n") + mdf <- NULL + decade <- seq(1900,2050,by=10) + for(i in 1:n) + { + df <- data.frame(Model=names(M)[i],logSel=M[[i]]$log_sel) + colnames(df) = c("Model","Gear","Area","Group","Sex","Year",M[[i]]$age) + df$Decade <- decade[findInterval(df$Year,decade)] + mdf <- rbind(mdf,melt(df,id=c("Model","Gear","Area","Group","Sex","Year","Decade"))) + } + + f <- unique(mdf$Area) + g <- unique(mdf$Group) + h <- unique(mdf$Sex) + k <- unique(mdf$Gear) + d <- unique(mdf$Decade) + ags <- as.matrix(expand.grid(k,f,g)) + + fnp <- function(ff) + { + dfx <- mdf %>% filter(Gear==ff[1]&Area==ff[2]&Group==ff[3]) + + p <- ggplot(dfx,aes(as.numeric(variable),exp(value),col=factor(Year))) + p <- p + geom_line() + p <- p + labs(x="Age",y="Relative Selectivity") + p <- p + ggtitle(paste("Gear",.GEAR[ff[1]])) + p <- p + facet_wrap(~Decade+Sex,scales="free_y") + return(p + .THEME + theme_bw(8) + guides(col=FALSE)) + } + + P <- apply(ags,1,fnp) + print(P) + + +}