admb_synthetic:admb_synthtetic
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| admb_synthetic:admb_synthtetic [2010/04/28 12:51] – lennartfr | admb_synthetic:admb_synthtetic [2010/05/04 07:55] (current) – lennartfr | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== The Model ===== | ===== The Model ===== | ||
| - | The ADMB framework is first tested on synthetic data. In the first step, we start with a simple model [1] . We generate synthetic data using parameters in Table 1. Next, we attempt to recover the parameters using the objective function defined in [2]\\ | + | The ADMB framework is first tested on synthetic data. In the first step, we start with a simple model, |
| - | ^N< | + | |
| - | ^f(s, | + | ^N< |
| + | ^f(N< | ||
| + | |||
| + | We generate synthetic data using parameters in Table 1. Next, we attempt to recover the parameters using the objective function defined in [2] | ||
| == Table 1: Data model parameters == | == Table 1: Data model parameters == | ||
| - | ^Parameter | + | ^Parameter |
| - | ^ N | Recruitment | + | ^ N< |
| - | ^ M | Natural mortality | + | ^ M | Natural mortality |
| - | ^ C | Catch data | + | ^ C< |
| - | ^ I | Survey | + | ^ I< |
| - | ^ s | Standard deviation for I | Scalar | + | ^ s | Standard deviation for I |
| - | ^ q | Catchability | + | ^ q< |
| - | ^ t | | + | |
| ===== Assumptions ===== | ===== Assumptions ===== | ||
| - | ===== Implementation | + | The number of cohorts m, N< |
| - | Data can be generated using the following code: | + | ln(I< |
| - | <file txt generate_data.m> | + | ===== Implementation |
| - | function N = generate_data(N0, | + | |
| - | % filegenerator(N0, | + | |
| - | % | + | |
| - | % Generates .dat file for cod problem. | + | |
| - | % | + | |
| - | % VERSION WITH SIMPLE MODEL - no random effects, | + | |
| - | % | + | |
| - | % Written by Lennart Frimannslund | + | |
| - | if (exist(' | + | Data can be generated using the file generate_data.m, which can be found in the [[mfiles: |
| - | year_offset = 1980; | + | |
| - | end; | + | |
| - | % Generate filename if not specified | + | ===== Example Results ===== |
| - | if (exist(' | + | |
| - | c = clock; | + | |
| - | filename | + | |
| - | | + | |
| - | clear c; | + | |
| - | end; | + | |
| - | + | :!: ** SUMMARY: | |
| - | % Get number of surveys | + | data file generator. The conclusion that can be drawn from them is that unless |
| - | if (exist(' | + | |
| - | surveys = length(q); | + | |
| - | end; | + | |
| - | + | ||
| - | % s - Generate random number between 0 and 1 | + | |
| - | if (exist(' | + | |
| - | s = rand; | + | |
| - | end; | + | |
| - | + | ||
| - | % M - Generate random number between 0 and 0.2 | + | |
| - | if (exist(' | + | |
| - | M = rand(1, | + | |
| - | end; | + | |
| - | + | ||
| - | + | ||
| - | % If no of cohorts not specified - generate random number between 1 and 6 | + | |
| - | if (exist(' | + | |
| - | cohorts = ceil((rand*5)) + 1; | + | |
| - | end; | + | |
| - | + | ||
| - | % years - if not specified, generate random number between 5 and 25 | + | |
| - | if (exist(' | + | |
| - | years = ceil((rand*20)) + 5; | + | |
| - | end; | + | |
| - | + | ||
| - | % surveys - if not specified, generate random number between 1 and 6 | + | |
| - | if (exist(' | + | |
| - | surveys = ceil((rand*5)) + 1; | + | |
| - | end; | + | |
| - | + | ||
| - | % if not specified - generate which fraction of maximum possible | + | |
| - | % observations available | + | |
| - | %if (exist(' | + | |
| - | % observations = ceil(rand * surveys * years * cohorts); | + | |
| - | %end; | + | |
| - | + | ||
| - | + | ||
| - | % Define N0 if not supplied | + | |
| - | % exp(N0) between 0 and 3 | + | |
| - | %if (exist(' | + | |
| - | % N0 = 3 * rand(1, | + | |
| - | %end; | + | |
| - | + | ||
| - | % Generate q - between 0.1 and 0.8 | + | |
| - | if (exist(' | + | |
| - | q = 0.7 * rand(1, | + | |
| - | end; | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | % Input variables now in place - generate data set itself | + | |
| - | % | + | |
| - | % For the most part translated line-by-line from r/s-code. | + | |
| - | + | ||
| - | n = years; | + | |
| - | m = cohorts; | + | |
| - | %sM = t; | + | |
| - | + | ||
| - | logs = log(s); | + | |
| - | + | ||
| - | if (exist(' | + | |
| - | cfactor = in_cfactor; | + | |
| - | else, | + | |
| - | cfactor = 0.65; | + | |
| - | end; | + | |
| - | + | ||
| - | fprintf(1,' | + | |
| - | fprintf(1,' | + | |
| - | fprintf(1,' | + | |
| - | + | ||
| - | + | ||
| - | %alpha = 0; | + | |
| - | %Z = (rand(1, | + | |
| - | + | ||
| - | % TRANSPOSE OF ITS USUAL FORM! | + | |
| - | N = zeros(n, | + | |
| - | + | ||
| - | %N(1,:) = N0; | + | |
| - | % Added "* 100" 01032010 | + | |
| - | N(1,:) = N0(: | + | |
| - | + | ||
| - | % SAME HERE, TRANSPOSE! | + | |
| - | CC = zeros(size(N)); | + | |
| - | + | ||
| - | %u = randn(n+m-1, | + | |
| - | + | ||
| - | %for (i=2:n), | + | |
| - | % | + | |
| - | % if (i> | + | |
| - | % CC(i-1,:) = rand(1,m) * cfactor/ | + | |
| - | % end; | + | |
| - | % | + | |
| - | % N(i,: | + | |
| - | % | + | |
| - | %end; | + | |
| - | + | ||
| - | % NEW loop, replaces | + | |
| - | for (j=1:m), | + | |
| - | for (i=2:n), | + | |
| - | + | ||
| - | if (i>2), | + | |
| - | CC(i-1,j) = rand(1,1) * cfactor/n * N(i-1,j); | + | |
| - | end; | + | |
| - | + | ||
| - | N(i,j) = (N(i-1,j) - CC(i-1,j)) * exp(-M); | + | |
| - | end; | + | |
| - | end; | + | |
| - | + | ||
| - | %fprintf(1,' | + | |
| - | %N' | + | |
| - | + | ||
| - | II = cell(surveys, | + | |
| - | for (i=1: | + | |
| - | + | ||
| - | % Updated on 26Apr2010 to not include 0 year group | + | |
| - | II{i} = q(i) * N(2: | + | |
| - | end; | + | |
| - | + | ||
| - | surveyraw = []; | + | |
| - | % now create surveyraw matrix, to be put in file | + | |
| - | % Updated on 26Apr2010 to not include 0 year group | + | |
| - | for (l=1: | + | |
| - | + | ||
| - | surveyraw_l = zeros((years-1)*cohorts, | + | |
| - | III = II{l}; | + | |
| - | + | ||
| - | for (i = 1: | + | |
| - | for (j=1: | + | |
| - | + | ||
| - | surveyraw_l((i-1)*(years-1)+j,: | + | |
| - | + | ||
| - | + | ||
| - | end; | + | |
| - | end; | + | |
| - | + | ||
| - | surveyraw = [surveyraw; surveyraw_l]; | + | |
| - | end; | + | |
| - | + | ||
| - | % Surveyraw matrix now in place, extract requested | + | |
| - | % it randomly | + | |
| - | max_possible_observations = (years-1)*cohorts*surveys; | + | |
| - | + | ||
| - | if (requested_observations >= max_possible_observations), | + | |
| - | observations = max_possible_observations; | + | |
| - | if (requested_observations > max_possible_observations), | + | |
| - | fprintf(1,' | + | |
| - | fprintf(1,' | + | |
| - | num2str(max_possible_observations)); | + | |
| - | fprintf(1,' | + | |
| - | end; | + | |
| - | permutation = 1: | + | |
| - | else, | + | |
| - | observations = requested_observations; | + | |
| - | fprintf(1,' | + | |
| - | num2str(max_possible_observations)); | + | |
| - | initial_permutation = randperm(max_possible_observations); | + | |
| - | permutation = sort(initial_permutation(1: | + | |
| - | end; | + | |
| - | + | ||
| - | % Write to file | + | |
| - | fid = fopen([filename ' | + | |
| - | % disp(fopen(' | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,'# | + | |
| - | for (i=1:size(N,1)), | + | |
| - | fprintf(fid,'# | + | |
| - | for (j=1: | + | |
| - | | + | |
| - | end; | + | |
| - | fprintf(fid,' | + | |
| - | end; | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,' | + | |
| - | + | ||
| - | % Endret 01032010 -- gammel kode hadde et sluttår for mye | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | + | ||
| - | for (j=1: | + | |
| - | fprintf(fid,' | + | |
| - | fprintf(fid,' | + | |
| - | end; | + | |
| - | + | ||
| - | fprintf(fid,' | + | |
| - | fprintf(fid,'# | + | |
| - | fprintf(fid,'# | + | |
| - | + | ||
| - | + | ||
| - | for (i=1: | + | |
| - | fprintf(fid,' | + | |
| - | end; | + | |
| - | + | ||
| - | fclose(fid); | + | |
| - | + | ||
| - | return; | + | |
| - | + | ||
| - | </ | + | |
| - | + | ||
| - | ===== Example Results ===== | + | |
| ==== Varying s in the data: single experiments ==== | ==== Varying s in the data: single experiments ==== | ||
| Line 268: | Line 44: | ||
| </ | </ | ||
| - | In other words, the three cohorts should start with initial levels of 200, 400 and 800, respectively, | + | In other words, the three cohorts should start with initial levels of 200, 400 and 800, respectively, |
| - | + | ||
| - | < | + | |
| - | # Randomly generated herring | + | |
| - | # True values: | + | |
| - | # N0: 200 | + | |
| - | # q: 0.5 0.5 | + | |
| - | # s: 0.00010 | + | |
| - | # M: 0.15000 | + | |
| - | # | + | |
| - | # True population trajectory, transpose(N): | + | |
| - | # | + | |
| - | # 200 400 800 | + | |
| - | # 172.14 344.28 688.57 | + | |
| - | # 142.73 295.01 591.66 | + | |
| - | # 118.02 252.57 498.6 | + | |
| - | # 96.874 203.58 424.03 | + | |
| - | # 78.606 165.17 359.4 | + | |
| - | # 63.656 138.09 289.4 | + | |
| - | # 54.084 116.14 249.08 | + | |
| - | # 44.391 96.088 209.76 | + | |
| - | # 38.007 82.218 175.77 | + | |
| - | # 30.675 70.264 143 | + | |
| - | # 26.244 57.632 121.86 | + | |
| - | # 22.184 47.104 103.69 | + | |
| - | # 18.767 38.653 86.048 | + | |
| - | # 15.731 33.261 73.114 | + | |
| - | # | + | |
| - | + | ||
| - | # m (Antall kohorter) | + | |
| - | 3 | + | |
| - | + | ||
| - | # Startaar for kohorter | + | |
| - | 1980 1981 1982 | + | |
| - | # Sluttaar for kohorter | + | |
| - | 1994 1995 1996 | + | |
| - | # Catches (one cohort per line) | + | |
| - | 0.000 6.315 5.606 5.471 5.547 4.648 0.820 2.509 0.233 2.367 0.184 0.470 0.380 0.490 0.000 | + | |
| - | 0.000 1.531 1.568 16.040 11.677 4.738 3.157 4.497 0.565 0.582 3.305 2.905 2.196 0.009 0.000 | + | |
| - | 0.000 1.152 12.373 5.942 6.473 23.160 0.009 5.380 5.547 9.627 1.420 1.392 3.713 1.101 0.000 | + | |
| - | + | ||
| - | #Number of surveys | + | |
| - | 2 | + | |
| - | #Number of survey indices | + | |
| - | 90 | + | |
| - | # Survey table | + | |
| - | 2 12 2 23.557 | + | |
| - | 2 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | 3 13 1 43.025 | + | |
| - | 3 12 2 51.844 | + | |
| - | 1 10 1 15.337 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 1 10 2 15.337 | + | |
| - | 3 | + | |
| - | 2 10 2 35.126 | + | |
| - | 3 14 2 36.549 | + | |
| - | 3 | + | |
| - | 2 11 1 28.815 | + | |
| - | 1 | + | |
| - | 1 12 2 11.093 | + | |
| - | 3 | + | |
| - | 1 14 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | 2 | + | |
| - | 1 14 | + | |
| - | 2 11 2 28.816 | + | |
| - | 2 | + | |
| - | 2 10 1 35.132 | + | |
| - | 1 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 2 12 1 23.549 | + | |
| - | 3 12 1 51.840 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 3 11 1 60.935 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 3 14 1 36.555 | + | |
| - | 1 | + | |
| - | 3 10 2 71.497 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 2 13 2 19.326 | + | |
| - | 2 | + | |
| - | 3 11 2 60.931 | + | |
| - | 2 13 1 19.322 | + | |
| - | 1 13 | + | |
| - | 3 | + | |
| - | 2 | + | |
| - | 2 14 2 16.631 | + | |
| - | 3 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 3 | + | |
| - | 3 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | 1 | + | |
| - | 1 | + | |
| - | 1 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 1 11 2 13.122 | + | |
| - | 3 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 3 | + | |
| - | 2 14 1 16.633 | + | |
| - | 3 10 1 71.508 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 1 12 1 11.091 | + | |
| - | 3 13 2 43.027 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 3 | + | |
| - | 1 11 1 13.121 | + | |
| - | 2 | + | |
| - | 1 | + | |
| - | 1 13 | + | |
| - | 2 | + | |
| - | 3 | + | |
| - | 1 | + | |
| - | </ | + | |
| ...and the following .pin file | ...and the following .pin file | ||
| Line 502: | Line 142: | ||
| CC(i-1,j) = rand(1,1) * cfactor/n * N(i-1,j); | CC(i-1,j) = rand(1,1) * cfactor/n * N(i-1,j); | ||
| </ | </ | ||
| - | What this line does is to set the catch for the year in question as fraction of the remaining stock multiplied | + | Here CC is the generated catch, n the number of years we follow the cohort, and N is the population level. |
| with a uniformly distributed random variable. Increasing cfactor will therefore increase the catch. | with a uniformly distributed random variable. Increasing cfactor will therefore increase the catch. | ||
| + | |||
| + | FIXME ** NOTE: The above formula should probably be changed to be independent of n and have less variance. ** | ||
| We test for five different values of cfactor (0.3, 0.6, 0.9, 1.2, 1.5). The results are shown in the following plots: | We test for five different values of cfactor (0.3, 0.6, 0.9, 1.2, 1.5). The results are shown in the following plots: | ||
admb_synthetic/admb_synthtetic.1272459061.txt.gz · Last modified: 2010/04/28 12:51 by lennartfr