mcintcv py from mcint import yc np sum( ** axis = control variable data yc true expectation of control variable np cov( ,ycsample covariance matrix cor [ ][ ]np sqrt( [ ][ ] [ ][ ]alpha [ ][ ] [ ][ est np mean(yalpha *(yc -yc)recv np sqrt (( cor ** )* [ ][ ] )/est relative error print ('estimate {: }ci ({: ,{: }corr {: }format (est est *( - *recv)est *( + *recv),cor)estimate ci ( , corr typical estimate of the correlation coefficient % ,ye is which gives reduction of the variance with factor - simulation speed-up of compared with crude monte carlo although the gain is small in this casedue to the modest correlation little extra work was required to achieve this variance reduction between and yone of the most important variance reduction techniques is importance sampling this technique is especially useful for the estimation of very small probabilities the standard setting is the estimation of quantity (xz (xf (xdx( where is real-valued function and the probability density of random vector xcalled the nominal pdf the subscript is added to the expectation operator to indicate that it is taken with respect to the density let be another probability density such that ( implies that (xf ( using the density we can represent as uz (xf (xh(xg(xdx eg (xg(xg(ximportance sampling nominal pdf ( consequentlyif ~iid gthen (xk uh(xk = (xk ( is an unbiased estimator of this estimator is called the importance sampling estimator and is called the importance sampling density the ratio of densitiesf ( )/ ( )is called the likelihood ratio the importance sampling pseudo-code is given in algorithm importance sampling estimator likelihood ratio