ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
newmodm4.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 double function_minimizer::unrestricted_hess_determinant(void)
00010 {
00011   adstring tmpstring="admodel.hes";
00012   if (ad_comm::wd_flag)
00013      tmpstring = ad_comm::adprogram_name + ".hes";
00014   uistream ifs((char*)tmpstring);
00015   if (!ifs)
00016   {
00017     cerr << "Error opening file " << (char*) tmpstring
00018       << " in unrestricted_hess_determinant" << endl;
00019   }
00020 
00021   int nvar = 0;
00022   ifs >> nvar;
00023   cout << "nvar =" << nvar << endl;
00024   if (nvar > 0)
00025   {
00026     if (nvar != initial_params::nvarcalc())
00027     {
00028       cout << "the number of independent variables is wrong in admodel.hes"
00029          << endl;
00030     }
00031   }
00032   dmatrix h(1,nvar,1,nvar);
00033   ifs >> h;
00034   if (!ifs)
00035   {
00036     cerr << "Error reading the hessian from file admodel.hes" << endl;
00037   }
00038 
00039   for (int i=1;i<=nvar;i++)
00040   {
00041     for (int j=1;j<i;j++)
00042     {
00043       double tmp=(h(i,j)+h(j,i))/2.;
00044       h(i,j)=tmp;
00045       h(j,i)=tmp;
00046     }
00047   }
00048 
00049   int sgn=0;
00050   double lndet=ln_det(h,sgn);
00051   if (sgn <= 0)
00052   {
00053     cerr << "sgn = " << sgn << endl;
00054     cerr << "Error Hessian is not positive definite" << endl;
00055   }
00056   return lndet;
00057 }