ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
modhdet.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 #include <admodel.h>
8 #include <cassert>
9 
10 double function_minimizer::hess_determinant(int underflow_flag)
11 {
12  double lndet=0.0;
13  if (!underflow_flag)
14  {
15  uistream ifs("admodel.hes");
16  if (!ifs)
17  {
18  cerr << "Error opening file admodel.hes" << endl;
19  }
20  int sgn = 0;
21  int nvar = 0;
22  ifs >> nvar;
23  if (nvar > 0)
24  {
25  if (nvar != initial_params::nvarcalc())
26  {
27  cout << "the number of independent variables"
28  << " is wrong in admodel.hes" << endl;
29  }
30  dmatrix h(1,nvar,1,nvar);
31  ifs >> h;
32  if (!ifs)
33  {
34  cerr << "Error reading the hessian from file admodel.hes" << endl;
35  }
36 
37  for (int i=1;i<=nvar;i++)
38  {
39  for (int j=1;j<i;j++)
40  {
41  double tmp=(h(i,j)+h(j,i))/2.;
42  h(i,j)=tmp;
43  h(j,i)=tmp;
44  }
45  }
46  lndet=ln_det(h,sgn);
47  }
48  if (sgn <= 0)
49  {
50  cerr << "Error restricted Hessian is not positive definite" << endl;
51  }
52  }
53  else
54  {
55  lndet=50.0;
56  }
57  return lndet;
58 }
double hess_determinant(int underflow_flag)
Definition: modhdet.cpp:10
static int nvarcalc()
Definition: model.cpp:152
ivector sgn(const dvector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dvect24.cpp:11
prnstream & endl(prnstream &)
Description not yet available.
Description not yet available.
Definition: fvar.hpp:2819
double ln_det(const dmatrix &m1, int &sgn)
Compute log determinant of a constant matrix.
Definition: dmat3.cpp:536
Description not yet available.
Definition: fvar.hpp:3516