Cholesky decomposition
\gdef\mat#1{\mathrm #1} \gdef\T{\mathrm T}
Positive definite matrices occur as covariance matrices. Given a positive definite matrix \mat M it can be factored into a triangular matrix \mat L such that
\mat M = \mat L ⋅ \mat L^\T
Computing the Cholesky decompostion
https://en.wikipedia.org/wiki/Cholesky_decomposition#The_Cholesky_algorithm
https://en.wikipedia.org/wiki/Cholesky_decomposition#The_Cholesky%E2%80%93Banachiewicz_and_Cholesky%E2%80%93Crout_algorithms
A reasonably efficient way to compute it is:
def cholesky(M):
L = np.()
for i in range(.[0]):
[:,] -=[,:] @[:,:].T
[:,] /= np.([,])
return L
But it's more efficient to use the LAPACK dpotrf function, available as np.linalg.cholesky.
https://netlib.org/lapack/explore-html/d2/d09/group__potrf_ga84e90859b02139934b166e579dd211d4.html#ga84e90859b02139934b166e579dd211d4
def cholesky_update(L, x):
for k in range(.[0]):
r = np.([,]**2 +[]**2)
c = r /[,]
s =[] /[,]
[,] = r
[+1:,] = ([+1:,] + s *[+1:]) /c
[+1:] = c *[+1:] - s *[+1:,]def cholesky_subset(L, mask):
L = L.()
for i in range(.[0]):
if not[]:
([+1:,+1:],[+1:,])
return[.(,)]Subset of Cholesky
References
https://algowiki-project.org/en/Cholesky_decomposition
https://www.cs.utexas.edu/users/flame/Notes/NotesOnCholReal.pdf
https://www.cs.utexas.edu/users/flame/pubs/flawn41.pdf
https://christian-igel.github.io/paper/AMERCMAUfES.pdf
https://github.com/scipy/scipy/issues/8188
https://link.springer.com/article/10.1007/BF01933218