# Shifted ldlfact and cholfact

**URL:** <https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 11, 2017, 10:19am UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206 "2017-06-11T10:19:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [June 11, 2017, 10:19am UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/1 "2017-06-11T10:19:42Z")

</div>

Hi all,

The calls to `ldlfact` and `cholfact`, in the case of `SparseMatrixCSC` arguments, call the appropriate functions in SuiteSparse and return `CHOLMOD.Factor` objects. These calls also support a named argument `shift`, which adds `shift*I` to the matrix to be factored. This is documented [here](https://docs.julialang.org/en/latest/stdlib/linalg/#Base.LinAlg.cholfact).

However, I’ve always used SuiteSparse from MATLAB, and there one can use `LD = ldlchol (A,beta)` to compute the Cholesky factorization of `A*A'+beta*I`. This is convenient because one can perform such factorization (I guess) without the need of forming `A*A'`.

Is there a way to do the same in Julia? Or am I missing something?

Thank you!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 11, 2017, 11:06am UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/2 "2017-06-11T11:06:30Z")

</div>

`cholfact(A, shift=β)` and `ldltfact(A, shift=β)` are supported for sparse matrices (only) and will do what you want.

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [June 11, 2017, 11:27am UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/3 "2017-06-11T11:27:14Z")

</div>

Thank you. That computes the Cholesky factor of `A + b*I`, as documented. My question is whether there’s a way to factor `A*A'+ b*I` _without_ actually computing the matrix-matrix product, as I believe MATLAB’s interface to SuiteSparse allows (using `ldlchol`).

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 11, 2017, 1:06pm UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/4 "2017-06-11T13:06:07Z")

</div>

Not entirely an answer to your original question, but if you perform the QR factorization of `[A' ; sqrt(b) * speye(size(A,1))]`, the transpose of the R factor will be the Cholesky factor that you’re after. (I’m assuming `A'` has more rows than columns and `b > 0`.)

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [June 11, 2017, 4:08pm UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/5 "2017-06-11T16:08:36Z")

</div>

Yes, that’s an option. However I would like to better understand what SuiteSparse allows to do, and how `cholfact` and `ldltfact` are connected to it. I’ll probably dive into the code and see!

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 11, 2017, 4:25pm UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/6 "2017-06-11T16:25:27Z")

</div>

It’s SuiteSparse that computes sparse QR factorization (via SuiteSparseQR) and it’s really the stable way to obtain the factor you’re looking for.

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [June 11, 2017, 5:13pm UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/7 "2017-06-11T17:13:21Z")

</div>

Well if that’s how `ldlchol` does that in MATLAB (I’m going to check) than you completely answered my question! However, I’m not sure why you need to make that assumption on the shape of `A`, since for `b > 0` the matrix I’m factoring is always spd.

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 11, 2017, 5:36pm UTC](https://discourse.julialang.org/t/shifted-ldlfact-and-cholfact/4206/8 "2017-06-11T17:36:51Z")

</div>

You’re right. No assumption on the shape of `A` if you’re regularizing. I’m not sure if that’s how Matlab does it.
