Revision 752 branches/threaded2/src/nh99/mod_hess.cpp
mod_hess.cpp (revision 752)  

4  4 
* Author: David Fournier 
5  5 
* Copyright (c) 20082012 Regents of the University of California 
6  6 
*/ 
7 
#include <sstream> 

8 
#include <thread> 

9 
#include <cassert> 

7  10 
#if defined(USE_LAPLACE) 
8  11 
# include <df1b2fun.h> 
9  12 
#else 
...  ...  
21  24  
22  25 
class admb_javapointers; 
23  26 
extern admb_javapointers * adjm_ptr; 
24 
void useless(const double& sdelta2); 

25  27 
// estimate the matrix of second derivatives 
26  28 
void ad_update_hess_stats_report(int i,int nvar); 
27  29  
...  ...  
67  69  
68  70 
void function_minimizer::hess_routine_noparallel(void) 
69  71 
{ 
70  
71  72 
int nvar=initial_params::nvarcalc(); // get the number of active parameters 
72  73 
//if (adjm_ptr) set_labels_for_hess(nvar); 
73  74 
independent_variables x(1,nvar); 
74  75 
initial_params::xinit(x); // get the initial values into the x vector 
75 
double f; 

76  76 
double delta=1.e5; 
77  77 
dvector g1(1,nvar); 
78  78 
dvector g2(1,nvar); 
...  ...  
83  83 
double eps=.1; 
84  84 
gradient_structure::set_YES_DERIVATIVES(); 
85  85 
gbest.fill_seqadd(1.e+50,0.); 
86 


87 
std::ostringstream oss; 

88 
std::thread::id this_thread_id = std::this_thread::get_id(); 

89 
oss << *ad_comm::adprogram_name << this_thread_id << ".hes"; 

90 
uostream ofs((char*)oss.str().c_str()); 

86  91  
87 
adstring tmpstring="admodel.hes"; 

88 
if (ad_comm::wd_flag) 

89 
tmpstring = ad_comm::adprogram_name + ".hes"; 

90 
uostream ofs((char*)tmpstring); 

91  
92  92 
ofs << nvar; 
93  93 
{ 
94  94 
{ 
95 
dvariable vf=0.0; 

96 
vf=initial_params::reset(dvar_vector(x)); 

95 
dvariable vf = initial_params::reset(dvar_vector(x)); 

97  96 
*objective_function_value::pobjfun=0.0; 
98  97 
pre_userfunction(); 
99  98 
vf+=*objective_function_value::pobjfun; 
100 
f=value(vf);


99 
double f = value(vf);


101  100 
gradcalc(nvar,g1); 
101 
//cerr << this_thread_id << " f: " << f << " g1: " << g1 << endl; 

102  102 
} 
103 
double sdelta1; 

104 
double sdelta2; 

105  103 
for (int i=1;i<=nvar;i++) 
106  104 
{ 
107  105 
#if defined (__SPDLL__) 
...  ...  
110  108 
cout << "Estimating row " << i << " out of " << nvar 
111  109 
<< " for hessian" << endl; 
112  110 
#endif 
113  
114  111 
double f=0.0; 
115  112 
double xsave=x(i); 
116 
sdelta1=x(i)+delta; 

117 
useless(sdelta1); 

113 
double sdelta1=x(i)+delta; 

118  114 
sdelta1=x(i); 
119  115 
x(i)=xsave+sdelta1; 
120 
dvariable vf=0.0; 

121 
vf=initial_params::reset(dvar_vector(x)); 

116 
dvariable vf=initial_params::reset(dvar_vector(x)); 

122  117 
*objective_function_value::pobjfun=0.0; 
123  118 
pre_userfunction(); 
124  119 
vf+=*objective_function_value::pobjfun; 
125  120 
f=value(vf); 
126  121 
gradcalc(nvar,g1); 
122 
//cerr << this_thread_id << " f: " << f << " g1: " << g1 << endl; 

127  123  
128 
sdelta2=x(i)delta; 

129 
useless(sdelta2); 

124 
double sdelta2=x(i)delta; 

130  125 
sdelta2=x(i); 
131  126 
x(i)=xsave+sdelta2; 
132 
vf=0.0; 

133  127 
vf=initial_params::reset(dvar_vector(x)); 
134  128 
*objective_function_value::pobjfun=0.0; 
135  129 
pre_userfunction(); 
Also available in: Unified diff