ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
newmodm4.cpp
Go to the documentation of this file.
1 
8 #include <admodel.h>
9 
11 {
12  adstring tmpstring="admodel.hes";
13  if (ad_comm::wd_flag)
14  tmpstring = ad_comm::adprogram_name + ".hes";
15  uistream ifs((char*)tmpstring);
16  if (!ifs)
17  {
18  cerr << "Error opening file " << (char*) tmpstring
19  << " in unrestricted_hess_determinant" << endl;
20  }
21 
22  int nvar = 0;
23  ifs >> nvar;
24  cout << "nvar =" << nvar << endl;
25  if (nvar > 0)
26  {
27  if (nvar != initial_params::nvarcalc())
28  {
29  cout << "the number of independent variables is wrong in admodel.hes"
30  << endl;
31  }
32  }
33  dmatrix h(1,nvar,1,nvar);
34  ifs >> h;
35  if (!ifs)
36  {
37  cerr << "Error reading the hessian from file admodel.hes" << endl;
38  }
39 
40  for (int i=1;i<=nvar;i++)
41  {
42  for (int j=1;j<i;j++)
43  {
44  double tmp=(h(i,j)+h(j,i))/2.;
45  h(i,j)=tmp;
46  h(j,i)=tmp;
47  }
48  }
49 
50  int sgn=0;
51  double lndet=ln_det(h,sgn);
52  if (sgn <= 0)
53  {
54  cerr << "sgn = " << sgn << endl;
55  cerr << "Error Hessian is not positive definite" << endl;
56  }
57  return lndet;
58 }
static adstring adprogram_name
Definition: fvar.hpp:8860
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 unrestricted_hess_determinant(void)
Definition: newmodm4.cpp:10
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
static unsigned int wd_flag
Definition: fvar.hpp:8864