You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently discovered that cholesky decomposition of toeplitz matrices (useful for GPs evaluated on a grid) can be done with O(n^2) rather than the standard cholesky O(n^3). I found an implementation here, where an academic has posted C, C++, Fortran, MATLAB & Python code (also mirrored in separate repositories here). I took a look at the python and it wasn't particularly optimized (used loops instead of vectorized alternatives), so in case it's useful here's the vectorized version I came up with:
importnumpyasnpdefcholesky_toeplitz(r):
""" Cholesky decomposition of a Toeplitz matrix. :param r: the first row of the Toeplitz matrix :return: the lower triangular matrix L """n=len(r)
l=np.zeros([n, n])
l[:, 0] =rg=np.zeros([2, n])
g[0, 1:] =r[0:(n-1)]
g[1, 1:] =r[1:]
foriinrange ( 1, n ):
rho=-g[1,i] /g[0,i]
gam=np.sqrt ( ( 1.0-rho ) * ( 1.0+rho ) )
alf=g[0, i:n]
bet=g[1, i:n]
temp_g_0= (alf+rho*bet) /gamtemp_g_1= (rho*alf+bet) /gamg[0, i:n] =temp_g_0g[1, i:n] =temp_g_1l[i:n, i] =g[0, i:n]
g[0, i+1:n] =g[0, i:n-1]
g[0,i] =0.0return(l)
And in some light testing, it does seem to outperform scipy.linalg.cholesky() when n is large (& n.b. scipy uses LAPACK, so my comparison was native python vs compiled fortran).
The text was updated successfully, but these errors were encountered:
Oh, and Aki just made me aware that the case of decomposing the correlation matrix (one can add the amplitude parameter later by multiplication), it's a symmetric circulant matrix that can be decomposed using FFT methods in O(n*log(n)).
I recently discovered that cholesky decomposition of toeplitz matrices (useful for GPs evaluated on a grid) can be done with O(n^2) rather than the standard cholesky O(n^3). I found an implementation here, where an academic has posted C, C++, Fortran, MATLAB & Python code (also mirrored in separate repositories here). I took a look at the python and it wasn't particularly optimized (used loops instead of vectorized alternatives), so in case it's useful here's the vectorized version I came up with:
And in some light testing, it does seem to outperform
scipy.linalg.cholesky()
when n is large (& n.b. scipy uses LAPACK, so my comparison was native python vs compiled fortran).The text was updated successfully, but these errors were encountered: