ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
f1b2trst.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  */
11 # include <admodel.h>
12 # include <df1b2fun.h>
13 # include <adrndeff.h>
14 //#include <vmon.h>
15 
21  independent_variables& x,const dvector& _g,const double& _f)
22 {
23  double & f= (double&)_f;
24  dvector & g= (dvector&)_g;
25  fmm fmc(nvar);
27  {
29  //int unvar=initial_params::nvarcalc(); // get the number of active
32  int nvar1=initial_params::nvarcalc(); // get the number of active
33  if (nvar1 != nvar)
34  {
35  cerr << "failed sanity check in "
36  "void function_minimizer::quasi_newton_block" << endl;
37  ad_exit(1);
38  }
39  }
40 
41  uistream uis("admodel.hes");
42  if (!uis)
43  {
44  cerr << "Error trying to open file admodel.hes" << endl;
45  ad_exit(1);
46  }
47  int hnvar = 0;
48  uis >> hnvar;
49  dmatrix Hess(1,hnvar,1,hnvar);
50  uis >> Hess;
51  if (!uis)
52  {
53  cerr << "Error trying to read Hessian from admodel.hes" << endl;
54  ad_exit(1);
55  }
56 
57  dmatrix tester(1,hnvar,1,hnvar);
58 
59  tester=Hess;
60 
61  dvector e=sort(eigenvalues(Hess));
62 
63  double lambda=-e(1)+100.;
64 
65  for (int i=1;i<=hnvar;i++)
66  {
67  tester(i,i)+=lambda;
68  }
69  dvector step = x-solve(tester,g);
70 
71  {
72  // calculate the number of random effects unvar
73  // this turns on random effects variables and turns off
74  // everything else
75  //cout << nvar << endl;
77  //cout << nvar << endl;
78  int unvar=initial_params::nvarcalc(); // get the number of active
79  //df1b2_gradlist::set_no_derivatives();
80 
81  if (lapprox)
82  {
83  delete lapprox;
84  lapprox=0;
86 
87  for (int i=0;i<df1b2variable::adpool_counter;i++)
88  {
92  df1b2variable::adpool_counter=0;
93  }
94  }
95  lapprox=new laplace_approximation_calculator(nvar,unvar,1,nvar+unvar,
96  this);
98 
100  allocate();
102 
104  int ynvar=initial_params::nvarcalc_all();
105  dvector y(1,ynvar);
108 
109  g=(*lapprox)(step,f,this);
110  }
111 } // end block for quasi newton minimization
static adpool * pool
Definition: df1b2fun.h:273
laplace_approximation_calculator * lapprox
Definition: admodel.h:1862
static void reset_all(const dvector &)
Description not yet available.
Definition: df1b2f18.cpp:17
void trust_region_update(int nvar, int _crit, independent_variables &x, const dvector &_g, const double &_f)
Description not yet available.
Definition: f1b2trst.cpp:20
static adpool * adpool_vector[]
Definition: df1b2fun.h:282
static void set_no_derivatives(void)
Definition: df1b2fun.h:760
Description not yet available.
Definition: adrndeff.h:182
Description not yet available.
dvector eigenvalues(const banded_symmetric_dmatrix &_SS)
Description not yet available.
Definition: dmat28.cpp:411
#define x
Vector of double precision numbers.
Definition: dvector.h:50
static void xinit_all(const dvector &x)
Description not yet available.
Definition: nvarcall.cpp:31
static unsigned int nvar_vector[]
Definition: df1b2fun.h:288
exitptr ad_exit
Definition: gradstrc.cpp:53
static void restore_start_phase(void)
Definition: model.cpp:275
static void save_varsptr(void)
Description not yet available.
Definition: df1b2fun.cpp:70
static int nvarcalc()
Definition: model.cpp:152
void deallocate(void)
Description not yet available.
Definition: adpool.cpp:319
static int current_phase
Definition: df1b2fun.h:1350
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
Definition: dmat34.cpp:46
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
Definition: dmsort.cpp:17
prnstream & endl(prnstream &)
Description not yet available.
Definition: fvar.hpp:1937
static int current_phase
Definition: admodel.h:842
static void set_active_only_random_effects(void)
Definition: model.cpp:251
Description not yet available.
Functions and variables for function minimizer.
Definition: fvar.hpp:3290
static int nvarcalc_all(void)
Description not yet available.
Definition: nvarcall.cpp:17
static void set_inactive_random_effects(void)
Definition: model.cpp:288
Description not yet available.
Definition: fvar.hpp:2819
Description not yet available.
Description not yet available.
Definition: fvar.hpp:3516
static int adpool_counter
Definition: df1b2fun.h:279
virtual void allocate()
Definition: admodel.h:1903
static void restore_varsptr(void)
Description not yet available.
Definition: df1b2fun.cpp:90
static int random_effects_flag
Definition: admodel.h:1857