从数学上来说,通过 Cholesky 分解对正定矩阵求逆比仅使用 更快np.linalg.inv(X)。然而,当我对两者进行实验时,发现 Cholesky 分解的性能更差!
# Inversion through Cholesky\np = X.shape[0]\nIp = np.eye(p)\n%timeit scipy.linalg.cho_solve(scipy.linalg.cho_factor(X,lower=True), Ip)\n\nThe slowest run took 17.96 times longer than the fastest. This could mean that an intermediate result is being cached.\n10000 loops, best of 3: 107 \xc2\xb5s per loop\n\n\n# Simple inversion\n%timeit np.linalg.inv(X)\n\nThe slowest run took 58.81 times longer than the fastest. This could mean that an intermediate result is being cached.\n10000 loops, best of 3: 25.9 \xc2\xb5s per loop\nRun Code Online (Sandbox Code Playgroud)\n\n后者花费的时间更短。为什么是这样?在 中R …