Revision 1651
trunk/src/df1b2separable/df1b2lp5.cpp (revision 1651)  

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  
12 
#if defined(USE_LAPLACE) 

13 
# include <admodel.h> 

14 
# include <df1b2fun.h> 

15 
# include <adrndeff.h> 

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

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

18 
laplace_approximation_calculator* lap); 

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

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

21 
const dmatrix& _Hessadjoint,function_minimizer * pmin); 

22  
23 
#if defined(USE_ADPVM) 

24 
/** 

25 
* Description not yet available. 

26 
* \param 

27 
*/ 

28 
void get_second_ders_slave(int xs,int us,const init_df1b2vector _y, 

29 
dmatrix& Hess, 

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

31 
laplace_approximation_calculator * lpc) 

32 
{ 

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

34 
// parameters 

35 
// us is the number of random effects parameters 

36 
int j; 

37 
int i; 

38 
ADUNCONST(init_df1b2vector,y) 

39 
int num_der_blocks=lpc>num_der_blocks; 

40 
int xsize=lpc>xsize; 

41 
int usize=lpc>usize; 

42  
43 
for (int ip=1;ip<=num_der_blocks;ip++) 

44 
{ 

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

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

47 
lpc>set_u_dot(ip); 

48 
df1b2_gradlist::set_yes_derivatives(); 

49 
(*re_objective_function_value::pobjfun)=0; 

50 
df1b2variable pen=0.0; 

51 
df1b2variable zz=0.0; 

52 
initial_df1b2params::reset(y,pen); 

53 
if (initial_df1b2params::separable_flag) 

54 
{ 

55 
initial_df1b2params::separable_calculation_type=2; 

56 
Hess.initialize(); 

57 
Dux.initialize(); 

58 
} 

59  
60 
//cout << "2D" << endl; 

61 
pfmin>user_function(); 

62  
63 
//pfmin>user_function(y,zz); 

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

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

66  
67 
if (!initial_df1b2params::separable_flag) 

68 
{ 

69 
set_dependent_variable(*re_objective_function_value::pobjfun); 

70 
df1b2_gradlist::set_no_derivatives(); 

71 
df1b2variable::passnumber=1; 

72 
df1b2_gradcalc1(); 

73  
74 
int mind=y(1).minder; 

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

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

77 
dmatrix tHess(1,usize,jmin,jmax); 

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

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

80 
{ 

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

82 
tHess(i,j)=y(i+xsize).u_bar[jmind]; 

83 
} 

84 
send_dmatrix_to_master(tHess); 

85  
86 
jmin=max(mind,1); 

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

88 
if (jmax>=jmin) 

89 
{ 

90 
dmatrix tDux(1,usize,jmin,jmax); 

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

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

93 
{ 

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

95 
tDux(i,j)=y(i+xsize).u_bar[j1]; 

96 
} 
Also available in: Unified diff