ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
c_ghk.cpp
Go to the documentation of this file.
1 
6 #include "fvar.hpp"
7 
12 double ghk(const dvector& lower,const dvector& upper,const dmatrix& Sigma,
13  const dmatrix& eps)
14 {
15  int m=eps.indexmax();
16  int n=lower.indexmax();
17  double ssum=0.0;
18  dmatrix ch=choleski_decomp(Sigma);
19  dvector l(1,n);
20  dvector u(1,n);
21 
22  for (int k=1;k<=m;k++)
23  {
24  double weight=1.0;
25  l=lower;
26  u=upper;
27  for (int j=1;j<=n;j++)
28  {
29  l(j)/=ch(j,j);
30  u(j)/=ch(j,j);
31  double Phiu=cumd_norm(u(j));
32  double Phil=cumd_norm(l(j));
33  weight*=Phiu-Phil;
34  double eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil);
35  for (int i=j+1;i<=n;i++)
36  {
37  double tmp=ch(i,j)*eta;
38  l(i)-=tmp;
39  u(i)-=tmp;
40  }
41  }
42  ssum+=weight;
43  }
44  return ssum/m;
45 }
46 
51 void ghk_test(const dmatrix& eps,int i)
52 {
53  if (i<eps.indexmin())
54  {
55  cerr << "Index too low in function ghk -- min is "
56  << eps.indexmin() << " you have " << i << endl;
57  ad_exit(21);
58  }
59  else if (i>eps.indexmax())
60  {
61  cerr << "Index too high in function ghk -- max is "
62  << eps.indexmax() << " you have " << i << endl;
63  ad_exit(21);
64  }
65 }
66 
71 double ghk(const dvector& lower,const dvector& upper,const dmatrix& Sigma,
72  const dmatrix& eps,int _i)
73 {
74  int n=lower.indexmax();
75  dmatrix ch=choleski_decomp(Sigma);
76  dvector l(1,n);
77  dvector u(1,n);
78 
79  ghk_test(eps,_i); // test for valid i range
80  double weight=1.0;
81  int k=_i;
82  {
83  l=lower;
84  u=upper;
85  for (int j=1;j<=n;j++)
86  {
87  l(j)/=ch(j,j);
88  u(j)/=ch(j,j);
89  double Phiu=cumd_norm(u(j));
90  double Phil=cumd_norm(l(j));
91  weight*=Phiu-Phil;
92  double eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil);
93  for (int i=j+1;i<=n;i++)
94  {
95  double tmp=ch(i,j)*eta;
96  l(i)-=tmp;
97  u(i)-=tmp;
98  }
99  }
100  }
101  return weight;
102 }
double ghk(const dvector &lower, const dvector &upper, const dmatrix &Sigma, const dmatrix &eps)
Description not yet available.
Definition: c_ghk.cpp:12
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Definition: fvar.hpp:2917
double inv_cumd_norm(const double &x)
Description not yet available.
Definition: cumdist.cpp:78
exitptr ad_exit
Definition: gradstrc.cpp:53
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
Definition: df11fun.cpp:606
prnstream & endl(prnstream &)
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Definition: fvar.hpp:2819
int indexmax() const
Definition: fvar.hpp:2921
double eps
Definition: ftweak.cpp:13
void ghk_test(const dmatrix &eps, int i)
Description not yet available.
Definition: c_ghk.cpp:51
double cumd_norm(const double &x)
Culative normal distribution; constant objects.
Definition: cumdist.cpp:90