seacode / gmacs

A generic size-structured stock assessment model
https://seacode.github.io/gmacs
18 stars 14 forks source link

calc_pred_catch_out #161

Closed quantifish closed 8 years ago

quantifish commented 8 years ago

I thought that we were having some issues fitting to catch, but it seems like it is a plotting issue. calc_pred_catch is the function the works out the predicted catch for use in the objective function. calc_pred_catch_out calculates a predicted catch for every year (not just the years for which we have data as above) and is used for plotting purposes only. calc_pred_catch looks correct, calc_pred_catch_out looks wrong. I am looking into this now.

quantifish commented 8 years ago

I found the offending code! The calc_pred_catch_out function is run at the end of the model, in the REPORT_SECTION. However, at the end of the PROCEDURE_SECTION the function calc_sdreport is run. This function looks like this:

FUNCTION calc_sdreport
sd_log_recruits = log(recruits);
sd_log_ssb = log(calc_ssb());
// F(1,nsex,syr,nyr,1,nclass);             ///> Fishing mortality
for ( int i = syr; i <= nyr; i++ )
{
    sd_fbar(i) = mean(F(1,i));
}

reset_Z_to_M();
calc_initial_numbers_at_length();
update_population_numbers_at_length();
sd_log_dyn_Bzero = log(calc_ssb())(syr+1,nyr);
sd_log_dyn_Bzero = elem_div(exp(sd_log_ssb(syr+1,nyr)),exp(sd_log_dyn_Bzero));
calc_total_mortality();

So the code at the bottom of calc_sdreport changes the numbers at length in each category before the calc_pred_catch_out function has a chance to be run, resulting in the wrong output and hence the wrong stuff being plotted.

I have simply commented out the last 6 lines of calc_sdreport but will need to discuss with Jim how to fix this up propoerly.

jimianelli commented 8 years ago

one solution would be to lose the sd_report_vector part of dynamic Bzero and just compute as simple output w/o Delta method variance estimates, then compute it after the report section is done. Another solution would be to set local objects to the nal beforehand and reset at the end. will think on it some more though

quantifish commented 8 years ago

I like the idea of setting local objects and resetting at the end. I'll think more on it too.

jimianelli commented 8 years ago

Think this is working now.