ADMB Documentation  11.1.2387
 All Classes Files Functions Variables Typedefs Friends Defines
modhdet.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: modhdet.cpp 1919 2014-04-22 22:02:01Z johnoel $
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::hess_determinant(int underflow_flag)
00010 {
00011  int sgn=0;
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 nvar = 0;
00021   ifs >> nvar;
00022   {
00023     if (nvar != initial_params::nvarcalc())
00024     {
00025       cout << "the number of independent variables is wrong in admodel.hes"
00026          << endl;
00027     }
00028     dmatrix h(1,nvar,1,nvar);
00029     ifs >> h;
00030     if (!ifs)
00031     {
00032       cerr << "Error reading the hessian from file admodel.hes" << endl;
00033     }
00034 
00035     for (int i=1;i<=nvar;i++)
00036     {
00037       for (int j=1;j<i;j++)
00038       {
00039         double tmp=(h(i,j)+h(j,i))/2.;
00040         h(i,j)=tmp;
00041         h(j,i)=tmp;
00042       }
00043     }
00044     lndet=ln_det(h,sgn);
00045   }
00046   if (sgn <= 0)
00047   {
00048     cerr << "Error restricted Hessian is not positive definite" << endl;
00049   }
00050  }
00051  else
00052  {
00053    lndet=50.0;
00054  }
00055  return lndet;
00056 }