17 const std::chrono::time_point<std::chrono::system_clock>& from,
18 const std::chrono::time_point<std::chrono::system_clock>& to);
36 #if defined(USE_ADPVM)
48 cerr <<
"Error: Illegal value for pvm_manager->mode." <<
endl;
51 cout <<
"finished hess routine" <<
endl;
85 std::chrono::time_point<std::chrono::system_clock> from_start;
88 from_start = std::chrono::system_clock::now();
90 cout <<
"Calculating Hessian";
91 if (nvar >= 10) cout <<
" (" << nvar <<
" variables)";
110 const int num = nvar / 5;
111 int index = num + (nvar % 5);
112 for (
int i=1;i<=nvar;i++)
123 cout << percentage <<
"%";
130 if (i > 1) cout <<
", ";
159 hess1=(g1-g2)/(sdelta1-sdelta2);
161 sdelta1=
x(i)+eps*delta;
172 x(i)=xsave-eps*delta;
173 sdelta2=
x(i)-eps*delta;
185 hess2=(g1-g2)/(sdelta1-sdelta2);
187 hess=(eps2*hess1-hess2) /(eps2-1.);
234 double lambda=fg*g/
norm2(g);
235 cout << fg-lambda*g <<
endl;
236 cout <<
norm(fg-lambda*g) <<
" " << fg*g/(
norm(g)*
norm(fg)) << endl;
252 for (
int i=1;i<=nvar;i++)
281 hess1=(g1-g2)/(sdelta1-sdelta2);
481 const std::chrono::time_point<std::chrono::system_clock>& from,
482 const std::chrono::time_point<std::chrono::system_clock>& to);
502 std::chrono::time_point<std::chrono::system_clock> from_start;
505 from_start = std::chrono::system_clock::now();
507 cout <<
"Differentiating " << ndvarcals <<
" derived quantities: ";
517 ofstream ofs((
char*)tmpstring);
529 ofs << nvar <<
" " << ndvar <<
endl;
532 const int num = ndvarcals / 5;
533 int index = num + (ndvarcals % 5);
534 for (i=0;i<ndvarcals;i++)
540 if ((i + 1) == index)
543 cout << percentage <<
"%";
548 if (i > 0) cout <<
", ";
556 for (i=0;i<ndvarcals;i++)
580 std::chrono::time_point<std::chrono::system_clock> from_start;
583 from_start = std::chrono::system_clock::now();
585 cout <<
"Inverting Hessian";
586 if (nvar >= 10) cout <<
" (" << nvar <<
" variables)";
597 if (nvar != file_nvar)
599 cerr <<
"Number of active variables in file mod_hess.rpt is wrong"
603 for (
int i = 1;i <= nvar; i++)
608 cerr <<
"Error reading line " << i <<
" of the hessian"
609 <<
" in routine hess_inv()" <<
endl;
623 cerr <<
"Error reading sscale"
624 <<
" in routine hess_inv()" <<
endl;
629 const int num = nvar / 5;
630 int index = num + (nvar % 5);
631 for (
int i = 1;i <= nvar; i++)
633 for (
int j=1;j<i;j++)
635 double tmp=(hess(i,j)+hess(j,i))/2.;
636 double tmp1=
fabs(hess(i,j)-hess(j,i));
637 tmp1/=(1.e-4+
fabs(hess(i,j))+
fabs(hess(j,i)));
638 if (tmp1>maxerr) maxerr=tmp1;
649 cout << percentage <<
"%";
657 if (i > 1) cout <<
", ";
670 for (
int i = 1;i <= nvar; i++)
673 for (
int j=1;j<=nvar;j++)
687 cout <<
"\n Warning: Parameter " << i <<
" appears to have identically 0 derivative.. check model\n";
691 output_stream <<
" Hessian is 0 in row " << i
692 <<
"\n This means that the derivative if probably identically 0 for this parameter."
705 <<
"unsorted:\t" << se <<
endl;
708 <<
"sorted:\t" << se <<
endl;
713 output_stream <<
"Warning -- Hessian does not appear to be positive definite"
722 if (on > -1 || on1 >-1 )
731 double lam=ev(i)*hess*ev(i);
733 << lam <<
" " << ev(i)*ev(i) <<
endl;
737 negflags(num_negflags)=i;
740 if ( (on1>-1) && (num_negflags>0))
749 for (
int i=1;i<=num_negflags;i++)
751 (*negdirections)(i)=ev(negflags(i));
758 for (
int i = 1;i <= ev.
indexmax(); i++)
762 cross(i,j)=ev(i)*ev(j);
765 ofs3 << endl <<
" e(i)*e(j) ";
766 ofs3 << endl << cross <<
endl;
783 ofs3 <<
"choleski decomp of correlation" <<
endl;
787 ofs3 <<
"parameterization of choleski decomnp of correlation" <<
endl;
791 ofs3 << tmp(1,i)/tmp(i) <<
endl;
801 for (
int i = 1;i <= nvar; i++)
804 if (hess(i,i) <= 0.0)
808 cerr <<
"\n\n Error: Estimated variance of parameter " << i <<
" is "<< hess(i,i) <<
", failed to invert Hessian.\n"
809 <<
" No uncertainty estimates available. Fix model structure and reoptimize.\n";
834 output_stream <<
"Estimating row " << i <<
" out of " << nvar <<
" for hessian"
840 output_stream <<
"Hessian does not appear to be positive definite." <<
endl;
static likeprof_params * likeprofptr[500]
bool hess_inv()
Symmetrize and invert the hessian.
laplace_approximation_calculator * lapprox
static adpvm_manager * pvm_manager
void ad_update_hess_stats_report(int i, int nvar)
void jacobcalc(int nvar, const dmatrix &jac)
Description not yet available.
static void set_NO_DERIVATIVES(void)
Disable accumulation of derivative information.
void hess_calcreport(int i, int nvar)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dmatrix trans(const dmatrix &m1)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dvector eigenvalues(const banded_symmetric_dmatrix &_SS)
Description not yet available.
Vector of double precision numbers.
int indexmin() const
Get minimum valid index.
void hess_routine_and_constraint(int iprof, const dvector &g, dvector &fg)
void fill_seqadd(double, double)
Fills dvector elements with values starting from base and incremented by offset.
void print_elapsed_time(const std::chrono::time_point< std::chrono::system_clock > &from, const std::chrono::time_point< std::chrono::system_clock > &to)
df1_two_variable fabs(const df1_two_variable &x)
static dvariable reset(const dvar_vector &x)
static void restore_start_phase(void)
static adstring adprogram_name
static int num_stddev_calc(void)
double norm(const d3_array &a)
Return computed norm value of a.
virtual dvariable variable(void)=0
void gradcalc(int nvar, const dvector &g)
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
virtual unsigned int size_count() const =0
void set_labels_for_hess(int)
virtual const char * label()=0
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
prnstream & endl(prnstream &)
dmatrix eigenvectors(const banded_symmetric_dmatrix &_SS, const dvector &_e)
Description not yet available.
Description not yet available.
Array of integers(int) with indexes from index_min to indexmax.
Description not yet available.
preshowpoint setshowpoint(void)
Description not yet available.
virtual void set_dependent_variables(void)=0
static objective_function_value * pobjfun
Description not yet available.
static void xinit(const dvector &x)
static _THREAD gradient_structure * _instance
static void set_inactive_random_effects(void)
Description not yet available.
double norm2(const d3_array &a)
Return sum of squared elements in a.
static void copy_all_values(const dvector &x, const int &ii)
double ln_det(const dmatrix &m1, int &sgn)
Compute log determinant of a constant matrix.
int option_match(int argc, char *argv[], const char *string)
Checks if the program has been invoked with a particular command line argument ("string").
int no_function_component_flag
std::ostream & get_output_stream()
static bool in_hessian_phase
void hess_routine_slave(void)
static int Hybrid_bounded_flag
static stddev_params * stddevptr[150]
Description not yet available.
void reset_gradient_stack(void)
Rewind buffer.
static void set_YES_DERIVATIVES(void)
Enable accumulation of derivative information.
Description not yet available.
static int negative_eigenvalue_flag
dvector value(const df1_one_vector &v)
static int stddev_scale(const dvector &d, const dvector &x)
void pre_userfunction(void)
void depvars_routine(void)
Calculate the derivatives of dependent variables with respect to the independent variables.
void hess_routine_random_effects(void)
Description not yet available.
void hess_routine_noparallel(void)
static unsigned int wd_flag
void hess_errorreport(void)
static int alternative_user_function_flag
Fundamental data type for reverse mode automatic differentiation.
df1_one_variable inv(const df1_one_variable &x)
void hess_routine_master(void)
static void set_inactive_only_random_effects(void)
static int random_effects_flag
static int num_stddev_params