I have a positive semidefinite matrix A \in \mathbb{R}^{n \times n} and its Cholesky factorization is A = L L^T. I would like to update the Cholesky factorization by removing the last row and column of L.
What is the correct way to update the Cholesky factorization object returned by cholesky() in this way? I’d like to pass the updated Cholesky factorization object to linear system solvers later in my program. I imagine this is easy to do since we are just throwing data away; but I can’t figure out how to access the Cholesky factorization object in the right way.
Here’s an example of what I’d want.
using LinearAlgebra
# create a positive definite matrix
A = [2 0 1; 0 3 0; 1 0 2]
# obtain cholesky factorization
C = cholesky(A)
L = C.L
# I want to update C to have this lower triangular matrix
L_sub = L[1:end-1,1:end-1]
# solve this linear system, but with updated Cholesky
x = (L_sub' * L_sub) \ ones(2) # answer = (1/2, 1/3)
This is pretty hacky, but I don’t see a better way. Using your C above:
C2 = Cholesky(C.factors[1:end-1, 1:end-1], :U, 0)
This uses the direct Cholesky constructor rather than cholesky, which actually performs the factorization. It needs the factor, whether it is upper (default) or lower triangular, and the return code where 0 is success. I found the constructors here.
Thanks for your response, @jkbest2! I’ll give this a try in my code. The only thing I’m worried about is the overhead I’d incur by writing C.factors again in memory.
I’ll keep this question open in case anyone has other suggestions. I’ll also take a look through the constructors link you sent.
This is getting pretty far outside my experience, but maybe you could avoid allocations by using a view into the original C.factors? It might cause problems down the line because the view wouldn’t be strided so couldn’t be passed to eg BLAS. Not sure about that though.