ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
modhdet.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 #include <cassert>
00009 
00010 double function_minimizer::hess_determinant(int underflow_flag)
00011 {
00012   double lndet=0.0;
00013   if (!underflow_flag)
00014   {
00015     uistream ifs("admodel.hes");
00016     if (!ifs)
00017     {
00018       cerr << "Error opening file admodel.hes" << endl;
00019     }
00020     int sgn = 0;
00021     int nvar = 0;
00022     ifs >> nvar;
00023     if (nvar > 0)
00024     {
00025       if (nvar != initial_params::nvarcalc())
00026       {
00027         cout << "the number of independent variables"
00028              << " is wrong in admodel.hes" << endl;
00029       }
00030       dmatrix h(1,nvar,1,nvar);
00031       ifs >> h;
00032       if (!ifs)
00033       {
00034         cerr << "Error reading the hessian from file admodel.hes" << endl;
00035       }
00036 
00037       for (int i=1;i<=nvar;i++)
00038       {
00039         for (int j=1;j<i;j++)
00040         {
00041           double tmp=(h(i,j)+h(j,i))/2.;
00042           h(i,j)=tmp;
00043           h(j,i)=tmp;
00044         }
00045       }
00046       lndet=ln_det(h,sgn);
00047     }
00048     if (sgn <= 0)
00049     {
00050       cerr << "Error restricted Hessian is not positive definite" << endl;
00051     }
00052   }
00053   else
00054   {
00055     lndet=50.0;
00056   }
00057   return lndet;
00058 }