admb-project / admb

AD Model Builder
http://admb-project.org
Other
64 stars 19 forks source link

Access hessian and ln_det values #132

Closed johnoel closed 4 years ago

johnoel commented 4 years ago

Requested by Rick Methot

iantaylor-NOAA commented 4 years ago

Hi @johnoel , Thanks for adding access to these quantities. I cloned the dev-get-hessian branch and built ADMB to try it out. I further modified the rsimple.tpl file to copy your use of the new output from FINAL_SECTION into REPORT_SECTION as well as below (both to avoid the issue in #133 and try out saving the new quantities).

REPORT_SECTION
  report << "\nln_det:\n" << get_ln_det_value() << endl;
  report << "\nhessian:\n" << get_hessian() << endl;
  report << "\nhessian inverse:\n" << get_hessian_inverse() << endl;
FINAL_SECTION
  cout << "\nln_det:\n" << get_ln_det_value() << endl;
  cout << "\nhessian:\n" << get_hessian() << endl;
  cout << "\nhessian inverse:\n" << get_hessian_inverse() << endl;

However, I see two issues with the results. First, rsimple.rep doesn't have the new quantities in it:

ln_det:
0

hessian:

hessian inverse:

Second, the top of rsimple.cor says The logarithm of the determinant of the hessian = 7.98853 but the console output from the FINAL_SECTION doesn't match:

ln_det:
15.0258

hessian:
 101.473 17.5507 1.04706 11.7531 11.7805
 17.5507 5.0145 0.29916 5.28029e-007 5.38117e-007
 1.04706 0.29916 1.22997 3.14976e-008 2.21234e-006
 11.7531 5.28007e-007 3.14987e-008 120.584 1.75382
 11.7805 5.38081e-007 2.21233e-006 1.75382 121.146

hessian inverse:
 0.0264637 -0.0926231 4.63375e-009 -0.00254249 -0.00253659
 -0.0926231 0.526539 -0.0492188 0.00889871 0.00887806
 4.63375e-009 -0.0492188 0.825 -2.29173e-010 -1.52946e-008
 -0.00254249 0.00889871 -2.29173e-010 0.008539 0.000123619
 -0.00253659 0.00887806 -1.52946e-008 0.000123619 0.0084994
johnoel commented 4 years ago

Thanks @iantaylor-NOAA , I corrected the output value for ln_det in the last commit.

As for the blank values in the .rep file, it was expected. Since the hessian computations occur after the report section, the values will be empty. So, the only way to output them is in the FINAL_SECTION.

iantaylor-NOAA commented 4 years ago

Thanks @johnoel for the fix. I was able to compile fine and the values match as expected. The explanation for the timing of the Hessian computation relative to the REPORT_SECTION and FINAL_SECTION makes sense too.

johnoel commented 4 years ago

Merged #143