60 if (ad_comm::time_flag)
64 ad_comm::ptm1->get_elapsed_time_and_reset();
68 ad_comm::ptm->get_elapsed_time_and_reset();
71 if (ad_comm::time_flag)
75 double time=ad_comm::ptm->get_elapsed_time();
78 (*ad_comm::global_logfile) <<
" Time pos 0 "
93 uhat=get_uhat_quasi_newton(
x,pfmin);
98 uhat=get_uhat_quasi_newton_qd(
x,pfmin);
102 uhat=get_uhat_lm_newton(
x,pfmin);
105 if (ad_comm::time_flag)
109 double time=ad_comm::ptm->get_elapsed_time_and_reset();
112 (*ad_comm::global_logfile) <<
" Time in inner optimization "
120 for (
int i=1;i<=xsize;i++)
124 for (
int i=1;i<=usize;i++)
132 niters=num_nr_iters+1;
142 if (used_flags.indexmax() != nv)
144 used_flags.safe_deallocate();
149 used_flags.safe_allocate(1,nv);
153 for(
int ii=1;ii<=niters;ii++)
162 output_stream <<
"Newton raphson " << ii <<
endl;
163 pmin->inner_opt_flag=1;
165 pmin->inner_opt_flag=0;
195 if (ad_comm::time_flag)
199 double time=ad_comm::ptm->get_elapsed_time_and_reset();
202 (*ad_comm::global_logfile) <<
" Time in newton-raphson " << ii
203 <<
" " << time <<
endl;
210 int print_hess_in_newton_raphson_flag=0;
211 if (print_hess_in_newton_raphson_flag)
216 (*ad_comm::global_logfile) << setprecision(4) <<
setscientific()
218 (*ad_comm::global_logfile) << setprecision(4) <<
setscientific()
219 << setw(12) << Hess <<
endl;
224 #if defined(USE_ATLAS)
234 step=-
solve(Hess,grad);
253 int trust_update_flag=0;
257 if (saddlepointflag==1 || saddlepointflag==2)
272 dvector s(grad.indexmin(),grad.indexmax());
274 if (saddlepointflag==2)
277 const dvector & cmgrad = -grad;
280 step=local_minimization(s,mHess,mgrad,lambda);
284 step=local_minimization(s,Hess,grad,lambda);
289 for (
int i=1;i<=usize;i++)
313 else if (trust_update_flag==1)
315 cout <<
"Found positive definite Hessian with trust region method"
319 while (ierror==1 && icount<100);
322 cerr <<
"Can't make a positive definite Hessian" <<
endl;
328 if (ad_comm::time_flag)
332 double time=ad_comm::ptm->get_elapsed_time_and_reset();
335 (*ad_comm::global_logfile) <<
" time_in solve " << ii <<
" "
349 if (trust_update_flag==0)
357 double maxg_old=maxg;
358 pmin->inner_opt_flag=1;
373 for (
int i=1;i<=usize;i++)
384 for (
int i=1;i<=usize;i++)
389 if (ad_comm::time_flag)
393 double time=ad_comm::ptm->get_elapsed_time_and_reset();
396 (*ad_comm::global_logfile) <<
" Time in reset and evaluate function"
402 pmin->inner_opt_flag=0;
405 if (saddlepointflag==2)
408 for (
int i=1;i<=xsize+usize;i++)
410 localx(i)=
value(y(i));
416 pmin->inner_opt_flag=1;
418 pmin->inner_opt_flag=0;
419 xadjoint -=
solve(Hess,uadjoint)*Dux;
434 if (ad_comm::time_flag)
438 double time=ad_comm::ptm->get_elapsed_time_and_reset();
441 (*ad_comm::global_logfile) <<
" Time in dget second ders "
449 if (num_importance_samples==0)
457 if (isfunnel_flag==0)
474 if (ad_comm::time_flag)
478 double time=ad_comm::ptm->get_elapsed_time_and_reset();
481 (*ad_comm::global_logfile) <<
482 " Time in calculate laplace approximation " << time <<
endl;
487 for (
int ip=num_der_blocks;ip>=1;ip--)
491 int mind=y(1).minder;
492 int jmin=
max(mind,xsize+1);
493 int jmax=
min(y(1).maxder,xsize+usize);
494 for (
int i=1;i<=usize;i++)
496 for (
int j=jmin;j<=jmax;j++)
499 y(i+xsize).get_u_bar_tilde()[j-mind]=Hessadjoint(i,j-xsize);
505 for (
int j=1;j<=xsize+usize;j++)
507 *y(j).get_u_tilde()=0;
515 if (ip<num_der_blocks)
520 (*re_objective_function_value::pobjfun)=0;
530 (*re_objective_function_value::pobjfun)+=pen;
531 (*re_objective_function_value::pobjfun)+=zz;
539 for (
int i=1;i<=usize;i++)
541 for (
int j=jmin;j<=jmax;j++)
544 y(i+xsize).get_u_bar_tilde()[j-mind]=Hessadjoint(i,j-xsize);
564 if (ad_comm::time_flag)
568 double time=ad_comm::ptm->get_elapsed_time_and_reset();
571 (*ad_comm::global_logfile) <<
" time for 3rd derivatives "
578 for (
int i=1;i<=xsize;i++)
580 dtmp(i)=*y(i).get_u_tilde();
585 assert(nvar <= INT_MAX);
589 dvector sscale=scale(1,Dux(1).indexmax());
590 for (
int i=1;i<=usize;i++)
597 for (
int i=1;i<=xsize;i++)
599 xadjoint(i)+=dtmp(i);
601 for (
int i=1;i<=usize;i++)
602 uadjoint(i)+=*y(xsize+i).get_u_tilde();
613 block_diagonal_flag=0;
615 assert(nvar <= INT_MAX);
627 dvector sscale=scale(1,Dux(1).indexmax());
629 for (
int i=1;i<=usize;i++)
642 for (
int i=1;i<=usize;i++)
651 for (
int i=1;i<=xsize;i++)
669 ad_comm::ptm->get_elapsed_time_and_reset();
673 #if defined(USE_ATLAS)
682 xadjoint -=
solve(Hess,uadjoint)*Dux;
686 xadjoint -=
solve(Hess,uadjoint)*Dux;
692 double time=ad_comm::ptm->get_elapsed_time_and_reset();
695 (*ad_comm::global_logfile) <<
" Time in second solve "
701 double time=ad_comm::ptm1->get_elapsed_time_and_reset();
704 (*ad_comm::global_logfile) <<
" Total time in function evaluation "
721 if (ad_comm::time_flag)
725 (*ad_comm::global_logfile) <<
" Starting Newton-Raphson "
730 for (
int ip=1;ip<=num_der_blocks;ip++)
738 check_for_need_to_reallocate(ip);
742 (*re_objective_function_value::pobjfun)=0;
755 if (ad_comm::time_flag)
759 time1 = ad_comm::ptm->get_elapsed_time();
765 if (ad_comm::time_flag)
771 double time=ad_comm::ptm->get_elapsed_time();
772 (*ad_comm::global_logfile) <<
773 " Time in user_function() " << ip <<
" " << time-time1
782 (*re_objective_function_value::pobjfun)+=pen;
783 (*re_objective_function_value::pobjfun)+=zz;
793 int mind=y(1).minder;
794 int jmin=
max(mind,xsize+1);
795 int jmax=
min(y(1).maxder,xsize+usize);
796 for (
int i=1;i<=usize;i++)
797 for (
int j=jmin;j<=jmax;j++)
798 Hess(i,j-xsize)=y(i+xsize).u_bar[j-mind];
832 for (
int j=jmin;j<=jmax;j++)
835 if (ip<num_der_blocks)
842 if (ad_comm::time_flag)
846 ad_comm::ptm->get_elapsed_time();
861 for (
int i=mmin;i<=mmax;i++)
873 unsigned int num_active_parameters =
nvar;
881 if (tmppool->
nvar != num_active_parameters)
884 int found_pool_flag=0;
901 if (!found_pool_flag)
905 cerr <<
"Need to increase adpool_vectorsize" <<
endl;
917 cerr <<
"Memory allocation error" <<
endl;
928 cerr <<
"Memory allocation error" <<
endl;
static int straight_through_flag
void initialize(void)
Description not yet available.
static void reset(const init_df1b2vector &, const df1b2variable &)
Description not yet available.
static void set_yes_derivatives(void)
df1b2_gradlist * f1b2gradlist
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
void set_dependent_variable(const df1b2variable &_x)
Description not yet available.
static adpool * adpool_vector[]
static void set_no_derivatives(void)
Description not yet available.
double calculate_importance_sample(const dvector &x, const dvector &u0, const dmatrix &Hess, const dvector &_xadjoint, const dvector &_uadjoint, const dmatrix &_Hessadjoint, function_minimizer *pmin)
Description not yet available.
static void set_NO_DERIVATIVES(void)
Disable accumulation of derivative information.
Description not yet available.
static void set_active_random_effects(void)
static ofstream * global_logfile
void check_pool_size(void)
Description not yet available.
dvector atlas_solve_spd(const dmatrix &M, const dvector &x)
static void get_Lxu_contribution(dmatrix &)
dvector eigenvalues(const banded_symmetric_dmatrix &_SS)
Description not yet available.
dmatrix trans(const dmatrix &m1)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Vector of double precision numbers.
dvector choleski_solve_neghess_error(dmatrix M, dvector &v, int &ierror)
Description not yet available.
static int separable_flag
static void get_cgradient_contribution(dvector, int)
Description not yet available.
static unsigned int nvar_vector[]
static void set_blocksize(void)
Description not yet available.
static re_objective_function_value * pobjfun
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
dvector evaluate_function_with_quadprior(const dvector &x, int usize, function_minimizer *pfmin)
Description not yet available.
static void get_cHessian_contribution_from_vHessian(dmatrix, int)
Description not yet available.
df1_two_variable fabs(const df1_two_variable &x)
double calculate_laplace_approximation(const dvector &x, const dvector &u0, const dmatrix &Hess, const dvector &_xadjoint, const dvector &_uadjoint, const dmatrix &_Hessadjoint, function_minimizer *pmin)
Description not yet available.
static int where_are_we_flag
void initialize(void)
Description not yet available.
Description not yet available.
static dvariable reset(const dvar_vector &x)
static const int adpool_vectorsize
Description not yet available.
void set_u_dot(int i)
Description not yet available.
Description not yet available.
void initialize(void)
Description not yet available.
double evaluate_function(const dvector &x, function_minimizer *pfmin)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
prescientific setscientific(void)
Description not yet available.
static int print_hess_and_exit_flag
static laplace_approximation_calculator * lapprox
dmatrix sort(const dmatrix &m, int column, int NSTACK)
Description not yet available.
dvector default_calculations(const dvector &_x, const double &_f, function_minimizer *pfmin)
Description not yet available.
dmatrix atlas_solve_spd_trans(const dmatrix &M, const dmatrix &x)
prnstream & endl(prnstream &)
static void set_active_only_random_effects(void)
double calculate_importance_sample_funnel(const dvector &x, const dvector &u0, const dmatrix &Hess, const dvector &_xadjoint, const dvector &_uadjoint, const dmatrix &_Hessadjoint, function_minimizer *pmin)
Description not yet available.
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Description not yet available.
double norm2(const d3_array &a)
Return sum of squared elements in a.
void evaluate_function_gradient(double &f, const dvector &x, function_minimizer *pfmin, dvector &xadjoint, dvector &uadjoint)
Description not yet available.
std::ostream & get_output_stream()
void get_newton_raphson_info(int xs, int us, const init_df1b2vector _y, dmatrix &Hess, dvector &grad, df1b2_gradlist *f1b2gradlist, function_minimizer *pfmin)
Description not yet available.
Description not yet available.
double evaluate_function_quiet(const dvector &x, function_minimizer *pfmin)
Description not yet available.
static int set_index(void)
dvector choleski_solve_error(dmatrix M, dvector &v, int &ierror)
Description not yet available.
Description not yet available.
Description not yet available.
static void increment_adpool_counter(void)
Description not yet available.
static void set_YES_DERIVATIVES(void)
Enable accumulation of derivative information.
void get_newton_raphson_info(function_minimizer *pmin)
Description not yet available.
virtual void user_function()
void get_second_ders(int xs, int us, const init_df1b2vector y, dmatrix &Hess, dmatrix &Dux, df1b2_gradlist *f1b2gradlist, function_minimizer *pfmin)
static void get_cHessian_contribution(dmatrix, int)
Description not yet available.
static int get_num_quadratic_prior(void)
dvector value(const df1_one_vector &v)
static int stddev_scale(const dvector &d, const dvector &x)
static int adpool_counter
static int get_num_quadratic_prior(void)
static double fun_without_pen
void reset(void)
Description not yet available.
static int first_hessian_flag
dmatrix choleski_decomp_positive(const dmatrix &MM, double bound)
Description not yet available.
void df1b2_gradcalc1(void)
Description not yet available.
static void set_inactive_only_random_effects(void)
static int separable_calculation_type
static int in_qp_calculations