Skip to main content

Numba-accelerated Jackknife

high performance computing
programming
statistics
Published

May 21, 2020

My resample library implements the jackknife and bootstrap resampling techniques. The implementations use pure-Python. Since resampling techniques are computationally expensive, it is important to ask whether we can speed up these methods with Numba. In this notebook I compare a JIT-compiled implementation of the Jackknife with the pure Python implementation from resample.

Since Numba currently does not support JIT-compiled functions which accept other functions as arguments, the JIT-compiled version has to work a little differently from the pure-Python version. It creates a two-dimensional array with all leave-one-out samples at once inside the compiled code. This array is then passed to Python and the function is evaluated over this array. This has a downside: For large samples, creating an N x (N-1) array in memory becomes dangerous since the memory allocation may bring the computer down and very slow.

Fortunately, it turns out that there is nothing to gain from JIT-compiling and thus there is no need to accept this caveat.

105 ms ± 10.6 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
119 ms ± 6.34 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

The results are comparable. This also remains so when we benchmark samples of varying size.