HMatrices.jl icon indicating copy to clipboard operation
HMatrices.jl copied to clipboard

Cholesky factorization

Open chaozg opened this issue 1 year ago • 11 comments

Hi there,

I just found HMatrices.jl and everything looks great. Meanwhile, I'm curious if there is any plan to add methods to perform Cholesky factorization of the approximated matrix.

Regards, Charlie

chaozg avatar Mar 26 '24 14:03 chaozg

Hi Charlie,

This should be relatively easy to do by mirroring the first 80 lines or so of the lu.jl file, but I have not done it since SPD matrices don't show up that frequently in my research (and I can always do an LU in those cases at 2x performance hit). What is your use case? Is LU not enough?

Regards, Luiz


p.s. it would probably also be good to indicate whether an HMatrix is symmetric by e.g. passing a symmetric keyword argument to the constructor and wrapping the returned HMatrix object in a (lazy) Symmetric type. That way you can also save a 2x time and memory at assembly.

maltezfaria avatar Mar 26 '24 19:03 maltezfaria

Hi Luiz,

Thanks for the swift reply!

Yes, Cholesky factorization will be particularly useful in my case/plan for generating Gaussian random signals. Let's say we have a covariance/kernel matrix K = LL^T, then Lx, with x being an iid draw from a standard normal distribution, will be one sample of the desired distribution.

It will be great if we have Cholesky in HMatrices.jl : )

Regards, Charlie

chaozg avatar Mar 26 '24 19:03 chaozg

I see, thanks for the explanation. If I find some free time in the next couple of days I will try to add it.

Depending on how much Julia you know, you can also take a crack at it by replicating the lu.jl file (I would be happy to review/contribute to a PR if you put a draft together).

maltezfaria avatar Mar 27 '24 09:03 maltezfaria

Hi Luiz,

I'll try to give it a go and let you know if I have any progress or give up at some point : )

Charlie

chaozg avatar Mar 27 '24 09:03 chaozg

Did you get a chance to look at it? I can probably give this a shot in the next couple of days. Let me know.

maltezfaria avatar Apr 06 '24 09:04 maltezfaria

Hi Luiz,

That's GREAT! please go ahead and I'm looking forward to your implementation. I haven't started my try yet...sorry

Charlie

chaozg avatar Apr 06 '24 09:04 chaozg

I haven't forgotten about this, just did not find the time to get it yet!

In the meantime, a quick question: at twice the computational cost, you can use the lu factorization right? If the matrix is SPD, lu will essentially compute a chol doing a bunch of redundant operations. You just have to be careful with the normalization of the diagonal entries in L, essentially taking its square root to get your Cholesky correct at the main diagonal.

maltezfaria avatar Apr 17 '24 20:04 maltezfaria

No worries at all. I was also busy with other work recently and didn't have time to explore HMatrices.jl. Please take your time. And please don't feel pressured: it's definitely not an urgent task or something : )

chaozg avatar Apr 29 '24 09:04 chaozg

No pressure felt, don't worry 😉

I have a half-working version on a local branch and was wondering if you could provide a MWE using e.g. a dense matrix representation so I can test against it.

maltezfaria avatar Apr 29 '24 11:04 maltezfaria

Ok, I tested this, and it seems things are working on the dev branch (see the cholesky_test.jl file). There may still be a few functionalities missing for what you need, but the core should be there. Let me know.

maltezfaria avatar Apr 29 '24 15:04 maltezfaria

@chaozg Did you get a chance to test this on the dev branch?

maltezfaria avatar May 04 '24 07:05 maltezfaria