Revision 1968
trunk/src/df1b2separable/df1b2lp4.cpp (revision 1968)  

1 
/* 

2 
* $Id$ 

3 
* 

4 
* Author: David Fournier 

5 
* Copyright (c) 20082012 Regents of the University of California 

6 
*/ 

7 
/** 

8 
* \file 

9 
* Description not yet available. 

10 
*/ 

11 
# include <admodel.h> 

12 
# include <df1b2fun.h> 

13 
# include <adrndeff.h> 

14 
void get_second_ders(int xs,int us,const init_df1b2vector y,dmatrix& Hess, 

15 
dmatrix& Dux, df1b2_gradlist * f1b2gradlist,function_minimizer * pfmin, 

16 
laplace_approximation_calculator* lap); 

17 
double calculate_laplace_approximation(const dvector& x,const dvector& u0, 

18 
const dmatrix& Hess,const dvector& _xadjoint,const dvector& _uadjoint, 

19 
const dmatrix& _Hessadjoint,function_minimizer * pmin); 

20  
21 
/** 

22 
* Description not yet available. 

23 
* \param 

24 
*/ 

25 
void get_second_ders_master(int xs,int us,const init_df1b2vector _y, 

26 
dmatrix& Hess, 

27 
dmatrix& Dux, df1b2_gradlist * f1b2gradlist,function_minimizer * pfmin, 

28 
laplace_approximation_calculator * lpc) 

29 
{ 

30 
// Note that xs is the number of active non random effects 

31 
// parameters 

32 
// us is the number of random effects parameters 

33 
int j; 

34 
int i; 

35 
ADUNCONST(init_df1b2vector,y) 

36 
int num_der_blocks=lpc>num_der_blocks; 

37 
int xsize=lpc>xsize; 

38 
int usize=lpc>usize; 

39  
40 
for (int ip=1;ip<=num_der_blocks;ip++) 

41 
{ 

42 
df1b2variable::minder=lpc>minder(ip); 

43 
df1b2variable::maxder=lpc>maxder(ip); 

44 
lpc>set_u_dot(ip); 

45 
df1b2_gradlist::set_yes_derivatives(); 

46 
(*re_objective_function_value::pobjfun)=0; 

47 
df1b2variable pen=0.0; 

48 
df1b2variable zz=0.0; 

49 
initial_df1b2params::reset(y,pen); 

50 
if (initial_df1b2params::separable_flag) 

51 
{ 

52 
initial_df1b2params::separable_calculation_type=2; 

53 
Hess.initialize(); 

54 
Dux.initialize(); 

55 
} 

56  
57 
//cout << "2D" << endl; 

58 
pfmin>user_function(); 

59  
60 
//pfmin>user_function(y,zz); 

61 
(*re_objective_function_value::pobjfun)+=pen; 

62 
(*re_objective_function_value::pobjfun)+=zz; 

63  
64 
if (!initial_df1b2params::separable_flag) 

65 
{ 

66 
set_dependent_variable(*re_objective_function_value::pobjfun); 

67 
df1b2_gradlist::set_no_derivatives(); 

68 
df1b2variable::passnumber=1; 

69 
df1b2_gradcalc1(); 

70  
71 
int mind=y(1).minder; 

72 
int jmin=max(mind,xsize+1); 

73 
int jmax=min(y(1).maxder,xsize+usize); 

74 
for (i=1;i<=usize;i++) 

75 
for (j=jmin;j<=jmax;j++) 

76 
Hess(i,jxsize)=y(i+xsize).u_bar[jmind]; 

77  
78 
jmin=max(mind,1); 

79 
jmax=min(y(1).maxder,xsize); 

80 
for (i=1;i<=usize;i++) 

81 
for (j=jmin;j<=jmax;j++) 

82 
Dux(i,j)=y(i+xsize).u_bar[j1]; 

83 
} 

84 
if (ip<num_der_blocks) 

85 
f1b2gradlist>reset(); 

86 
} 

87 
if (ad_comm::pvm_manager) 

88 
{ 

89 
if (ad_comm::pvm_manager>timing_flag) 

90 
ad_comm::pvm_manager>tm.get_elapsed_time_and_reset(); 

91 
} 

92  
93 
d3_array M1=get_dmatrix_from_slaves(); 

94  
95 
if (ad_comm::pvm_manager) 

96 
{ 
Also available in: Unified diff