(f, xs, iters)
| 205 | |
| 206 | |
| 207 | def bootstrap_stderr(f, xs, iters): |
| 208 | import multiprocessing as mp |
| 209 | |
| 210 | pool = mp.Pool(mp.cpu_count()) |
| 211 | # this gives a biased estimate of the stderr (i.e w/ the mean, it gives something |
| 212 | # equivalent to stderr calculated without Bessel's correction in the stddev. |
| 213 | # Unfortunately, I haven't been able to figure out what the right correction is |
| 214 | # to make the bootstrap unbiased - i considered multiplying by sqrt(n/(n-1)) but |
| 215 | # that would be ad-hoc and I can't prove that that would actually be an unbiased estimator) |
| 216 | # Thankfully, shouldn't matter because our samples are pretty big usually anyways |
| 217 | res = [] |
| 218 | chunk_size = min(1000, iters) |
| 219 | from tqdm import tqdm |
| 220 | |
| 221 | print("bootstrapping for stddev:", f.__name__) |
| 222 | for bootstrap in tqdm( |
| 223 | pool.imap( |
| 224 | _bootstrap_internal(f, chunk_size), |
| 225 | [(i, xs) for i in range(iters // chunk_size)], |
| 226 | ), |
| 227 | total=iters // chunk_size, |
| 228 | ): |
| 229 | # sample w replacement |
| 230 | res.extend(bootstrap) |
| 231 | |
| 232 | pool.close() |
| 233 | return sample_stddev(res) |
| 234 | |
| 235 | |
| 236 | def stderr_for_metric(metric, bootstrap_iters): |
no test coverage detected