00001
00002
00003
00004
00005
00006
00011 #include "fvar.hpp"
00012
00017 dvariable ghk(const dvar_vector& lower,const dvar_vector& upper,
00018 const dvar_matrix& Sigma, const dmatrix& eps)
00019 {
00020 RETURN_ARRAYS_INCREMENT();
00021 int n=lower.indexmax();
00022 int m=eps.indexmax();
00023 dvariable ssum=0.0;
00024 dvar_matrix ch=choleski_decomp(Sigma);
00025 dvar_vector l(1,n);
00026 dvar_vector u(1,n);
00027
00028 for (int k=1;k<=m;k++)
00029 {
00030 dvariable weight=1.0;
00031 l=lower;
00032 u=upper;
00033 for (int j=1;j<=n;j++)
00034 {
00035 l(j)/=ch(j,j);
00036 u(j)/=ch(j,j);
00037 dvariable Phiu=cumd_norm(u(j));
00038 dvariable Phil=cumd_norm(l(j));
00039 weight*=Phiu-Phil;
00040 dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil+1.e-30);
00041 for (int i=j+1;i<=n;i++)
00042 {
00043 dvariable tmp=ch(i,j)*eta;
00044 l(i)-=tmp;
00045 u(i)-=tmp;
00046 }
00047 }
00048 ssum+=weight;
00049 }
00050 RETURN_ARRAYS_DECREMENT();
00051 return ssum/m;
00052 }
00053
00058 dvariable ghk_m(const dvar_vector& upper,const dvar_matrix& Sigma, const dmatrix& eps)
00059 {
00060 RETURN_ARRAYS_INCREMENT();
00061 int n=upper.indexmax();
00062 int m=eps.indexmax();
00063 dvariable ssum=0.0;
00064 dvar_vector u(1,n);
00065 dvar_matrix ch=choleski_decomp(Sigma);
00066
00067 for (int k=1;k<=m;k++)
00068 {
00069 dvariable weight=1.0;
00070 u=upper;
00071 for (int j=1;j<=n;j++)
00072 {
00073 u(j)/=ch(j,j);
00074 dvariable Phiu=cumd_norm(u(j));
00075 weight*=Phiu;
00076 dvariable eta=inv_cumd_norm(1.e-30+Phiu*eps(k,j));
00077 for (int i=j+1;i<=n;i++)
00078 {
00079 dvariable tmp=ch(i,j)*eta;
00080 u(i)-=tmp;
00081 }
00082 }
00083 ssum+=weight;
00084 }
00085 RETURN_ARRAYS_DECREMENT();
00086 return ssum/m;
00087 }
00088
00093 dvariable ghk_choleski(const dvar_vector& lower,const dvar_vector& upper,
00094 const dvar_matrix& ch, const dmatrix& eps)
00095 {
00096 RETURN_ARRAYS_INCREMENT();
00097 int n=lower.indexmax();
00098 int m=eps.indexmax();
00099 dvariable ssum=0.0;
00100 dvar_vector l(1,n);
00101 dvar_vector u(1,n);
00102
00103 for (int k=1;k<=m;k++)
00104 {
00105 dvariable weight=1.0;
00106 l=lower;
00107 u=upper;
00108 for (int j=1;j<=n;j++)
00109 {
00110 l(j)/=ch(j,j);
00111 u(j)/=ch(j,j);
00112 dvariable Phiu=cumd_norm(u(j));
00113 dvariable Phil=cumd_norm(l(j));
00114 weight*=Phiu-Phil;
00115 dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil);
00116 for (int i=j+1;i<=n;i++)
00117 {
00118 dvariable tmp=ch(i,j)*eta;
00119 l(i)-=tmp;
00120 u(i)-=tmp;
00121 }
00122 }
00123 ssum+=weight;
00124 }
00125 RETURN_ARRAYS_DECREMENT();
00126 return ssum/m;
00127 }
00128
00133 dvariable ghk_choleski_m(const dvar_vector& upper,
00134 const dvar_matrix& ch, const dmatrix& eps)
00135 {
00136 RETURN_ARRAYS_INCREMENT();
00137 int n=upper.indexmax();
00138 int m=eps.indexmax();
00139 dvariable ssum=0.0;
00140 dvar_vector u(1,n);
00141
00142 for (int k=1;k<=m;k++)
00143 {
00144 dvariable weight=1.0;
00145 u=upper;
00146 for (int j=1;j<=n;j++)
00147 {
00148 u(j)/=ch(j,j);
00149 dvariable Phiu=cumd_norm(u(j));
00150 weight*=Phiu;
00151 dvariable eta=inv_cumd_norm(1.e-30+Phiu*eps(k,j));
00152 for (int i=j+1;i<=n;i++)
00153 {
00154 dvariable tmp=ch(i,j)*eta;
00155 u(i)-=tmp;
00156 }
00157 }
00158 ssum+=weight;
00159 }
00160 RETURN_ARRAYS_DECREMENT();
00161 return ssum/m;
00162 }
00163
00164 void ghk_test(const dmatrix& eps,int i);
00165
00170 dvariable ghk(const dvar_vector& lower,const dvar_vector& upper,
00171 const dvar_matrix& Sigma, const dmatrix& eps,int i)
00172 {
00173 RETURN_ARRAYS_INCREMENT();
00174 int n=lower.indexmax();
00175 dvar_matrix ch=choleski_decomp(Sigma);
00176 dvar_vector l(1,n);
00177 dvar_vector u(1,n);
00178
00179 ghk_test(eps,i);
00180
00181 dvariable weight=1.0;
00182 int k=i;
00183 {
00184 l=lower;
00185 u=upper;
00186 for (int j=1;j<=n;j++)
00187 {
00188 l(j)/=ch(j,j);
00189 u(j)/=ch(j,j);
00190 dvariable Phiu=cumd_norm(u(j));
00191 dvariable Phil=cumd_norm(l(j));
00192 weight*=Phiu-Phil;
00193 dvariable eta=inv_cumd_norm((Phiu-Phil)*eps(k,j)+Phil+1.e-30);
00194 for (int i=j+1;i<=n;i++)
00195 {
00196 dvariable tmp=ch(i,j)*eta;
00197 l(i)-=tmp;
00198 u(i)-=tmp;
00199 }
00200 }
00201 }
00202 RETURN_ARRAYS_DECREMENT();
00203 return weight;
00204 }
00205
00210 dvariable ghk_choleski_m_cauchy(const dvar_vector& upper,
00211 const dvar_matrix& ch, const dmatrix& eps)
00212 {
00213 RETURN_ARRAYS_INCREMENT();
00214 int n=upper.indexmax();
00215 int m=eps.indexmax();
00216 dvariable ssum=0.0;
00217 dvar_vector u(1,n);
00218
00219 for (int k=1;k<=m;k++)
00220 {
00221 dvariable weight=1.0;
00222 u=upper;
00223 for (int j=1;j<=n;j++)
00224 {
00225 u(j)/=ch(j,j);
00226 dvariable Phiu=cumd_cauchy(u(j));
00227 weight*=Phiu;
00228 dvariable eta=inv_cumd_cauchy(Phiu*eps(k,j));
00229 for (int i=j+1;i<=n;i++)
00230 {
00231 dvariable tmp=ch(i,j)*eta;
00232 u(i)-=tmp;
00233 }
00234 }
00235 ssum+=weight;
00236 }
00237 RETURN_ARRAYS_DECREMENT();
00238 return ssum/m;
00239 }
00240
00245 dvariable ghk_choleski_m_logistic(const dvar_vector& upper,
00246 const dvar_matrix& ch, const dmatrix& eps)
00247 {
00248 RETURN_ARRAYS_INCREMENT();
00249 int n=upper.indexmax();
00250 int m=eps.indexmax();
00251 dvariable ssum=0.0;
00252 dvar_vector u(1,n);
00253
00254 for (int k=1;k<=m;k++)
00255 {
00256 dvariable weight=1.0;
00257 u=upper;
00258 for (int j=1;j<=n;j++)
00259 {
00260 u(j)/=ch(j,j);
00261 dvariable Phiu=cumd_logistic(u(j));
00262 weight*=Phiu;
00263 dvariable eta=inv_cumd_logistic(Phiu*eps(k,j));
00264 for (int i=j+1;i<=n;i++)
00265 {
00266 dvariable tmp=ch(i,j)*eta;
00267 u(i)-=tmp;
00268 }
00269 }
00270 ssum+=weight;
00271 }
00272 RETURN_ARRAYS_DECREMENT();
00273 return ssum/m;
00274 }