# Updating Cholesky Factorization submatrix

**URL:** https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913
**Category:** Numerics
**Tags:** question, linearalgebra
**Created:** [September 18, 2019, 7:30pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913 "2019-09-18T19:30:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![charshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charshaw/32/10361_2.png) [@charshaw](https://discourse.julialang.org/u/charshaw)
#### Post date: [September 18, 2019, 7:30pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/1 "2019-09-18T19:30:55Z")

</div>

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.

```julia
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)
```

---

<div class="post-metadata">

### Author: ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)
#### Post date: [September 18, 2019, 8:09pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/2 "2019-09-18T20:09:31Z")

</div>

This is pretty hacky, but I don’t see a better way. Using your `C` above:

```julia
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](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/cholesky.jl#L72).

---

<div class="post-metadata">

### Author: ![charshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charshaw/32/10361_2.png) [@charshaw](https://discourse.julialang.org/u/charshaw)
#### Post date: [September 18, 2019, 8:59pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/3 "2019-09-18T20:59:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)
#### Post date: [September 19, 2019, 4:07am UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/4 "2019-09-19T04:07:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [September 19, 2019, 4:37am UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/5 "2019-09-19T04:37:49Z")

</div>

Have you looked at  
[https://github.com/JuliaLang/julia/issues/2929](https://github.com/JuliaLang/julia/issues/2929)  
and  
[https://github.com/mpf/QRupdate.jl](https://github.com/mpf/QRupdate.jl)  
?

---

<div class="post-metadata">

### Author: ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)
#### Post date: [September 19, 2019, 6:16pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/6 "2019-09-19T18:16:51Z")

</div>

I had known about `lowrankupate` et al., but missed that they could be [used to remove rows/columns](https://math.stackexchange.com/questions/1896467/cholesky-decomposition-when-deleting-one-row-and-one-and-column#1896839). Thanks!

---

<div class="post-metadata">

### Author: ![mfalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfalt/32/12467_2.png) [@mfalt](https://discourse.julialang.org/u/mfalt)
#### Post date: [September 20, 2019, 11:42am UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/7 "2019-09-20T11:42:31Z")

</div>

I have implemented this functionality in my QP solver QPDAS.jl, see [https://github.com/mfalt/QPDAS.jl/blob/master/src/choleskySpecial.jl](https://github.com/mfalt/QPDAS.jl/blob/master/src/choleskySpecial.jl)

It actually sets any row and column to identity, and you are then able to reverse the update.

For your example:

```julia
import QPDAS, LinearAlgebra
using LinearAlgebra

A = [2 0 1; 0 3 0; 1 0 2] 
C = cholesky(A)
C2 = QPDAS.CholeskySpecial(C)
# Remove last row/column (actually sets it to identity)
QPDAS.deleterowcol!(C2, 3)
(C2\[ones(2),randn()])[1:2] # answer [1/2,1/3]

```

Edit: I am not sure how it will handle the semi-definite case, I have only used it for positive-definite factorizations.

---

<div class="post-metadata">

### Author: ![igorkohan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igorkohan/32/13759_2.png) [@igorkohan](https://discourse.julialang.org/u/igorkohan)
#### Post date: [August 26, 2020, 5:05pm UTC](https://discourse.julialang.org/t/updating-cholesky-factorization-submatrix/28913/8 "2020-08-26T17:05:00Z")

</div>

It is a late response :). For a case of positive-definite symmetric matrix you may use this approach:  
[Algorithms for updating Cholesky factorization](https://normalsplines.blogspot.com/2019/02/algorithms-for-updating-cholesky.html)  
BR,  
Igor
