It's mathematically known that inverting a positive definite matrix via Cholesky decomposition is faster than just using np.linalg.inv(X)
. However, when I experimented with both and it turns out Cholesky decomposition's performance is worse!
# Inversion through Cholesky
p = X.shape[0]
Ip = np.eye(p)
%timeit scipy.linalg.cho_solve(scipy.linalg.cho_factor(X,lower=True), Ip)
The slowest run took 17.96 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 107 µs per loop
# Simple inversion
%timeit np.linalg.inv(X)
The slowest run took 58.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 25.9 µs per loop
The latter took shorter. Why is this? In R
, chol2inv(chol(X))
is usually faster than solve(X)
.