MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / bootstrap_stderr

Function bootstrap_stderr

test/general/lm_eval/metrics.py:207–233  ·  view source on GitHub ↗
(f, xs, iters)

Source from the content-addressed store, hash-verified

205
206
207def 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
236def stderr_for_metric(metric, bootstrap_iters):

Callers 1

stderr_for_metricFunction · 0.85

Calls 2

_bootstrap_internalClass · 0.85
sample_stddevFunction · 0.85

Tested by

no test coverage detected