ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
v_ghk.cpp
Go to the documentation of this file.
1 
9 #include "fvar.hpp"
10 
15 dvariable ghk(const dvar_vector& lower,const dvar_vector& upper,
16  const dvar_matrix& Sigma, const dmatrix& eps)
17 {
20 
21  int n=lower.indexmax();
22  int m=eps.indexmax();
23  dvariable ssum=0.0;
24  dvar_matrix ch=choleski_decomp(Sigma);
25  dvar_vector l(1,n);
26  dvar_vector u(1,n);
27 
28  for (int k=1;k<=m;k++)
29  {
30  dvariable weight=1.0;
31  l=lower;
32  u=upper;
33  for (int j=1;j<=n;j++)
34  {
35  l(j)/=ch(j,j);
36  u(j)/=ch(j,j);
37  dvariable Phiu=cumd_norm(u(j));
38  dvariable Phil=cumd_norm(l(j));
39  weight*=Phiu-Phil;
40  dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil+1.e-30);
41  for (int i=j+1;i<=n;i++)
42  {
43  dvariable tmp=ch(i,j)*eta;
44  l(i)-=tmp;
45  u(i)-=tmp;
46  }
47  }
48  ssum+=weight;
49  }
51  return ssum/m;
52 }
53 
58 dvariable ghk_m(const dvar_vector& upper,const dvar_matrix& Sigma,
59  const dmatrix& eps)
60 {
63  int n=upper.indexmax();
64  int m=eps.indexmax();
65  dvariable ssum=0.0;
66  dvar_vector u(1,n);
67  dvar_matrix ch=choleski_decomp(Sigma);
68 
69  for (int k=1;k<=m;k++)
70  {
71  dvariable weight=1.0;
72  u=upper;
73  for (int j=1;j<=n;j++)
74  {
75  u(j)/=ch(j,j);
76  dvariable Phiu=cumd_norm(u(j));
77  weight*=Phiu;
78  dvariable eta=inv_cumd_norm(1.e-30+Phiu*eps(k,j));
79  for (int i=j+1;i<=n;i++)
80  {
81  dvariable tmp=ch(i,j)*eta;
82  u(i)-=tmp;
83  }
84  }
85  ssum+=weight;
86  }
88  return ssum/m;
89 }
90 
95 dvariable ghk_choleski(const dvar_vector& lower,const dvar_vector& upper,
96  const dvar_matrix& ch, const dmatrix& eps)
97 {
100  int n=lower.indexmax();
101  int m=eps.indexmax();
102  dvariable ssum=0.0;
103  dvar_vector l(1,n);
104  dvar_vector u(1,n);
105 
106  for (int k=1;k<=m;k++)
107  {
108  dvariable weight=1.0;
109  l=lower;
110  u=upper;
111  for (int j=1;j<=n;j++)
112  {
113  l(j)/=ch(j,j);
114  u(j)/=ch(j,j);
115  dvariable Phiu=cumd_norm(u(j));
116  dvariable Phil=cumd_norm(l(j));
117  weight*=Phiu-Phil;
118  dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil);
119  for (int i=j+1;i<=n;i++)
120  {
121  dvariable tmp=ch(i,j)*eta;
122  l(i)-=tmp;
123  u(i)-=tmp;
124  }
125  }
126  ssum+=weight;
127  }
129  return ssum/m;
130 }
131 
137  const dvar_matrix& ch, const dmatrix& eps)
138 {
141 
142  int n=upper.indexmax();
143  int m=eps.indexmax();
144  dvariable ssum=0.0;
145  dvar_vector u(1,n);
146 
147  for (int k=1;k<=m;k++)
148  {
149  dvariable weight=1.0;
150  u=upper;
151  for (int j=1;j<=n;j++)
152  {
153  u(j)/=ch(j,j);
154  dvariable Phiu=cumd_norm(u(j));
155  weight*=Phiu;
156  dvariable eta=inv_cumd_norm(1.e-30+Phiu*eps(k,j));
157  for (int i=j+1;i<=n;i++)
158  {
159  dvariable tmp=ch(i,j)*eta;
160  u(i)-=tmp;
161  }
162  }
163  ssum+=weight;
164  }
166  return ssum/m;
167 }
168 
169 void ghk_test(const dmatrix& eps,int i);
170 
175 dvariable ghk(const dvar_vector& lower,const dvar_vector& upper,
176  const dvar_matrix& Sigma, const dmatrix& eps,int _i)
177 {
180 
181  int n=lower.indexmax();
182  dvar_matrix ch=choleski_decomp(Sigma);
183  dvar_vector l(1,n);
184  dvar_vector u(1,n);
185 
186  ghk_test(eps,_i);
187 
188  dvariable weight=1.0;
189  int k=_i;
190  {
191  l=lower;
192  u=upper;
193  for (int j=1;j<=n;j++)
194  {
195  l(j)/=ch(j,j);
196  u(j)/=ch(j,j);
197  dvariable Phiu=cumd_norm(u(j));
198  dvariable Phil=cumd_norm(l(j));
199  weight*=Phiu-Phil;
200  dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil+1.e-30);
201  for (int i=j+1;i<=n;i++)
202  {
203  dvariable tmp=ch(i,j)*eta;
204  l(i)-=tmp;
205  u(i)-=tmp;
206  }
207  }
208  }
210  return weight;
211 }
212 
218  const dvar_matrix& ch, const dmatrix& eps)
219 {
222 
223  int n=upper.indexmax();
224  int m=eps.indexmax();
225  dvariable ssum=0.0;
226  dvar_vector u(1,n);
227 
228  for (int k=1;k<=m;k++)
229  {
230  dvariable weight=1.0;
231  u=upper;
232  for (int j=1;j<=n;j++)
233  {
234  u(j)/=ch(j,j);
235  dvariable Phiu=cumd_cauchy(u(j));
236  weight*=Phiu;
237  dvariable eta=inv_cumd_cauchy(Phiu*eps(k,j));
238  for (int i=j+1;i<=n;i++)
239  {
240  dvariable tmp=ch(i,j)*eta;
241  u(i)-=tmp;
242  }
243  }
244  ssum+=weight;
245  }
247  return ssum/m;
248 }
249 
255  const dvar_matrix& ch, const dmatrix& eps)
256 {
259  int n=upper.indexmax();
260  int m=eps.indexmax();
261  dvariable ssum=0.0;
262  dvar_vector u(1,n);
263 
264  for (int k=1;k<=m;k++)
265  {
266  dvariable weight=1.0;
267  u=upper;
268  for (int j=1;j<=n;j++)
269  {
270  u(j)/=ch(j,j);
271  dvariable Phiu=cumd_logistic(u(j));
272  weight*=Phiu;
273  dvariable eta=inv_cumd_logistic(Phiu*eps(k,j));
274  for (int i=j+1;i<=n;i++)
275  {
276  dvariable tmp=ch(i,j)*eta;
277  u(i)-=tmp;
278  }
279  }
280  ssum+=weight;
281  }
283  return ssum/m;
284 }
double ghk(const dvector &lower, const dvector &upper, const dmatrix &Sigma, const dmatrix &eps)
Description not yet available.
Definition: c_ghk.cpp:12
double ghk_choleski(const dvector &lower, const dvector &upper, const dmatrix &ch, const dmatrix &eps)
double inv_cumd_norm(const double &x)
Description not yet available.
Definition: cumdist.cpp:78
dvariable ghk_m(const dvar_vector &upper, const dvar_matrix &Sigma, const dmatrix &eps)
Description not yet available.
Definition: v_ghk.cpp:58
ADMB variable vector.
Definition: fvar.hpp:2172
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
Definition: df11fun.cpp:606
double inv_cumd_logistic(const double &x)
Description not yet available.
Definition: ccumdlog.cpp:30
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
Description not yet available.
Definition: fvar.hpp:2819
int indexmax() const
Definition: fvar.hpp:2921
dvariable ghk_choleski_m(const dvar_vector &upper, const dvar_matrix &ch, const dmatrix &eps)
Description not yet available.
Definition: v_ghk.cpp:136
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
double inv_cumd_cauchy(const double &x)
Description not yet available.
Definition: cumd_cau.cpp:49
double eps
Definition: ftweak.cpp:13
double cumd_cauchy(const double &x)
Description not yet available.
Definition: cumd_cau.cpp:17
void ghk_test(const dmatrix &eps, int i)
Description not yet available.
Definition: c_ghk.cpp:51
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
double cumd_logistic(const double &x)
Description not yet available.
Definition: ccumdlog.cpp:13
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
dvariable ghk_choleski_m_cauchy(const dvar_vector &upper, const dvar_matrix &ch, const dmatrix &eps)
Description not yet available.
Definition: v_ghk.cpp:217
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Definition: cumdist.cpp:90
int indexmax() const
Definition: fvar.hpp:2292
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
dvariable ghk_choleski_m_logistic(const dvar_vector &upper, const dvar_matrix &ch, const dmatrix &eps)
Description not yet available.
Definition: v_ghk.cpp:254