for truncation level of and sample size of typical estimate is with an estimated relative error of we have two sources of error here the first is the error in approximating by ub howeveras the function decays exponentially fastb is more than enough to ensure this error is negligible the second type of error is the statistical errordue to the estimation process itself this can be quantified by the estimated relative errorand can be reduced by increasing the sample size let us now consider an importance sampling approach in which the importance sampling pdf is radially symmetric and decays exponentially in the radiussimilar to the function in particularwe simulate ( in way akin to example by first generating radius exp(land an angle th ( )and then returning cos(thand sin(thby the transformation rule (theorem we then have - + le (xfr,th (rthl -lr { the following codewhich imports the one given aboveimplements the importance sampling stepsusing the parameter impsamp py from impsamp import lam lambda lam*exp(-sqrt( ** ** )*lam)/sqrt( ** ** /( pi) rand( , ) rand( , -log( )/lam *cos ( pi*vx *sin ( pi*vz ( , )* / ( , estis np mean(zitem (obtain scalar reis np std( )estis /sqrt(nitem (print ('ci ({: ,{: }re { }format estis *( - reis)estis *( + reis),reis)ci ( , re typical estimate is with an estimated relative error of - which gives substantial variance reduction in terms of approximate confidence intervalswe have ( , in the cmc case versus ( , in the importance sampling case of coursewe could have reduced the truncation level to improve the performance of cmcbut then the approximation error might become more significant for the importance sampling casethe relative error is hardly affected by the threshold levelbut does depend on the choice of we chose such that the decay rate is slower than the decay rate of the function hwhich is as illustrated in the above examplea main difficulty in importance sampling is how to choose the importance sampling distribution poor choice of may seriously affect the accuracy of both the estimate and the confidence interval the theoretically optimal choice