<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Luis,<div><br></div><div>The error is occurring because you are trying to subtract a vector from another vector where the bounds are different. (log_fy_coff(2,nyrs)-log_fy_coff(1,nyrs-1)) This is not allowed. You can use the .shift function to change the array bounds (see the ADMB manual at the bottom of page 168, or 15-10 for more information). Also it looks like your trying to minimize the first difference in the log_fy_coff, there is an admb function called "first_difference" that will accomplish what you are trying to do. e.g. norm2(first_difference(log_fy_coff)).</div><div><br></div><div>Steve</div><div><div><div>On 2010-10-07, at 7:44 AM, Luis Ridao wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">ADMB-help,<div><br></div><div>This is my first e-mail to this mailing-list. I'm new to ADMB and </div><div>trying to learn little by little.</div><div><br></div><div>I'm working on a catch-at-age model provided in the admb manual.</div>
<div>The first step was to import my personal stock data set. As a second step </div><div>I wish to impose a penalty on the objective function based on the differences in the fishing mortality</div><div>coefficient ("log_fy_coff")</div>
<div><br></div><div>ADMB fails to run the model with the following message:</div><div><br></div><div>"Incompatible bounds in prevariable operator * (_CONST dvar_vector& v1,_CONST dvar_vector& v2)"</div><div>
The line causing the error is the FUNCTION "evaluate_the_objective_function" section at the of the file</div><div><br></div><div># originally (from the manual admb.pdf)</div><div><div>FUNCTION evaluate_the_objective_function</div>
<div> // penalty functions to ``regularize '' the solution</div><div> f+=.01*norm2(log_relpop);</div><div> avg_F=sum(F)/double(size_count(F));</div><div> if (last_phase())</div><div> {</div><div> // a very small penalty on the average fishing mortality</div>
<div> f+= .001*square(log(avg_F/.2));</div><div> }</div><div> else</div><div> {</div><div> f+= 1000.*square(log(avg_F/.2));</div><div> }</div><div> f+=0.5*double(size_count(C)+size_count(log_fy_coff)) </div><div>
* log( sum(elem_div(square(C-obs_catch_at_age),.01+C))</div><div> + 100*norm2(log_fy_coff))); // ORIGINAL LINE </div></div><div><br></div><div># the modification of the original code (last line)</div><div><div>
FUNCTION evaluate_the_objective_function</div><div> // penalty functions to ``regularize '' the solution</div><div> f+=.01*norm2(log_relpop);</div><div> avg_F=sum(F)/double(size_count(F));</div><div> if (last_phase())</div>
<div> {</div><div> // a very small penalty on the average fishing mortality</div><div> f+= .001*square(log(avg_F/.2));</div><div> }</div><div> else</div><div> {</div><div> f+= 1000.*square(log(avg_F/.2));</div>
<div> }</div><div> f+=0.5*double(size_count(C)+size_count(log_fy_coff)) </div><div> * log( sum(elem_div(square(C-obs_catch_at_age),.01+C))</div><div> + 100*norm2(log_fy_coff(2,nyrs)-log_fy_coff(1,nyrs-1))); // MODIFIED LINE</div>
</div><div><br></div><div>The .tpl file is provided below.</div><div>I'm running on a Windows machine.</div><div><br></div><div>########################################################################################</div>
<div><div>DATA_SECTION</div><div> init_int nyrs // the number of years odf data</div><div> init_int nages // the number of age classess in the population</div>
<div> init_matrix obs_catch_at_age(1,nyrs,1,nages) // observed catch-at-age data</div><div> init_number M // estimate of natural mortality rate</div><div> init_vector relwt(2,nages); // need to have relative weight-at-age to calculate B2+</div>
<div> vector ages(1,nages); // ages of data</div><div> vector ages4plus(1,nages-1); // non-recruiting ages in the population</div><div> vector years(1,nyrs); // years of data</div>
<div> int pred_year; // prediction year</div><div>INITIALIZATION_SECTION</div><div> //log_q -1 // original -1</div><div> log_popscale 5 // original 5</div>
<div>PARAMETER_SECTION</div><div> //init_number log_q(1) // log-catchability</div><div> init_number log_popscale(1) // overall population scaling parameter</div><div> init_bounded_dev_vector log_sel_coff(1,nages-1,-15.,15.,2) // original log_sel_coff(1,nages-1,-15.,15.,2) </div>
<div> init_bounded_dev_vector log_relpop(1,nyrs+nages-1,-15.,15.,2) // original log_relpop(1,nyrs+nages-1,-15.,15.,2) </div><div> init_bounded_dev_vector log_fy_coff(1,nyrs,-.3,.3,3) // original log_fy_coff(1,nyrs,-2.,2.,3) </div>
<div> vector log_sel(1,nages)</div><div> vector log_fy(1,nyrs)</div><div> vector log_initpop(1,nyrs+nages-1);</div><div> matrix F(1,nyrs,1,nages) // instantaneous fishing mortality</div><div> matrix Z(1,nyrs,1,nages) // instantaneous total mortality</div>
<div> matrix S(1,nyrs,1,nages) // survival rate</div><div> matrix N(1,nyrs,1,nages) // predicted numbers-at-age</div><div> matrix C(1,nyrs,1,nages) // predicted catch-at-age</div>
<div> objective_function_value f</div><div> number recsum</div><div> number initsum</div><div> sdreport_number avg_F</div><div> sdreport_vector predicted_N(2,nages)</div><div> sdreport_vector ratio_N(2,nages)</div><div>
// changed from the manual because adjusted likelihood routine doesn't</div><div> // work</div><div> likeprof_number pred_B</div><div><br></div><div>PRELIMINARY_CALCS_SECTION</div><div> ages.fill_seqadd(3,1); // vector of ages</div>
<div> ages4plus.fill_seqadd(4,1); // vector of non recruiting ages</div><div> years.fill_seqadd(1975,1); // fill vector of years with years</div><div> pred_year=years[nyrs]+1; // year of prediction = last_year +1</div>
<div>PROCEDURE_SECTION</div><div> // example of using FUNCTION to structure the procedure section</div><div> get_mortality_and_survivial_rates();</div><div><br></div><div> get_numbers_at_age();</div><div><br></div><div>
get_catch_at_age();</div><div><br></div><div> evaluate_the_objective_function();</div><div><br></div><div>FUNCTION get_mortality_and_survivial_rates</div><div> int i, j;</div><div> //calculate the selectivity from the sel_coffs ---------------------</div>
<div> for (j=1;j<nages;j++)</div><div> {</div><div> log_sel(j)=log_sel_coff(j);</div><div> }</div><div> //the selectivity is the same for the last two age classes</div><div> log_sel(nages)=log_sel_coff(nages-1);</div>
<div><br></div><div> for (i=1;i<=nyrs;i++)</div><div> {</div><div> log_fy(i)=log_fy_coff(i);</div><div> }</div><div> F=outer_prod(mfexp(log_fy),mfexp(log_sel)); // F=outer_prod(mfexp(log_fy),mfexp(log_sel)) ; F=outer_prod(mfexp(log_q)*effort,mfexp(log_sel));</div>
<div> Z=F+M;</div><div> // get the survival rate</div><div> S=mfexp(-1.0*Z);</div><div><br></div><div>FUNCTION get_numbers_at_age</div><div> int i, j;</div><div> </div><div> log_initpop=log_relpop+log_popscale;</div>
<div> </div><div> for (i=1;i<=nyrs;i++)</div><div> {</div><div> N(i,1)=mfexp(log_initpop(i));</div><div> }</div><div> for (j=2;j<=nages;j++)</div><div> {</div><div> N(1,j)=mfexp(log_initpop(nyrs+j-1));</div>
<div> }</div><div> for (i=1;i<nyrs;i++)</div><div> {</div><div> for (j=1;j<nages;j++)</div><div> {</div><div> N(i+1,j+1)=N(i,j)*S(i,j);</div><div> }</div><div> }</div><div> // calculated predicted numbers at age for next year</div>
<div> for (j=1;j<nages;j++)</div><div> {</div><div> predicted_N(j+1)=N(nyrs,j)*S(nyrs,j);</div><div> ratio_N(j+1)=predicted_N(j+1)/N(1,j+1);</div><div> }</div><div> // calculated predicted Biomass for next year for</div>
<div> // adjusted profile likelihood</div><div> pred_B=(predicted_N * relwt);</div><div><br></div><div>FUNCTION get_catch_at_age</div><div> C=elem_prod(elem_div(F,Z),elem_prod(1.-S,N));</div><div><br></div><div>FUNCTION evaluate_the_objective_function</div>
<div> // penalty functions to ``regularize '' the solution</div><div> f+=.01*norm2(log_relpop);</div><div> avg_F=sum(F)/double(size_count(F));</div><div> if (last_phase())</div><div> {</div><div> // a very small penalty on the average fishing mortality</div>
<div> f+= .001*square(log(avg_F/.2));</div><div> }</div><div> else</div><div> {</div><div> f+= 1000.*square(log(avg_F/.2));</div><div> }</div><div> f+=0.5*double(size_count(C)+size_count(log_fy_coff)) </div><div>
* log( sum(elem_div(square(C-obs_catch_at_age),.01+C))</div><div> + 100*norm2(log_fy_coff(2,nyrs)-log_fy_coff(1,nyrs-1))); </div><div>########################################################################################</div>
</div>
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@admb-project.org">Users@admb-project.org</a><br>http://lists.admb-project.org/mailman/listinfo/users<br></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div>Steve Martell</div><div><a href="mailto:s.martell@fisheries.ubc.ca">s.martell@fisheries.ubc.ca</a></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></div></body></html>