def calibrateEB(variances, sigma2):
if (sigma2 <= <NUM_LIT:0> or min(variances) == max(variances)):<EOL><INDENT>return(np.maximum(variances, <NUM_LIT:0>))<EOL><DEDENT>sigma = np.sqrt(sigma2)<EOL>eb_prior = gfit(variances, sigma)<EOL>part = functools.partial(gbayes, g_est=eb_prior,<EOL>sigma=sigma)<EOL>if len(variances) >= <NUM_LIT:200>:<EOL><INDENT>calib_x = np.percentile(variances,<EOL>np.arange(<NUM_LIT:0>, <NUM_LIT>, <NUM_LIT:2>))<EOL>calib_y = list(map(part, calib_x))<EOL>calib_all = np.interp(variances, calib_x, calib_y)<EOL><DEDENT>else:<EOL><INDENT>calib_all = list(map(part, variances))<EOL><DEDENT>return np.asarray(calib_all)<EOL>
Calibrate noisy variance estimates with empirical Bayes.

Parameters
----------
vars: ndarray
    List of variance estimates.
sigma2: int
    Estimate of the Monte Carlo noise in vars.

Returns
-------
An array of the calibrated variance estimates