-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cholesky Decomposition Fails for Larger Matrixes #7
Comments
Hey Sorry, after trying to track down the error. It might be simply that my virtual machine that I'm using is screwing up the IEEE 754 floating point standard. |
The issue has to do with unlucky picking of Floating point numbers. Apparently, there is a difference between how Linux (rhel specifically) and windows interact with Lapack. The solution that works well is to simply multiply the matrix by some scaling value before applying the cholesky this shifts the floating point representation and will usually cause the matrix decompose nicely. |
For me the test case works both on Linux (Debian) and Windows. If you're linking to system LAPACK on RHEL (i.e. not using |
I was building blas. It's randomly happening, I would need to give you the
test matrix I'm using which is a bit impractical as it's 500 by 500.
If I can find a smaller piece of it that fails I will post it.
…On Jun 9, 2017 6:22 PM, "Andrey Zholos" ***@***.***> wrote:
For me the test case works both on Linux (Debian) and Windows. If you're
linking to system LAPACK on RHEL (i.e. not using ./configure --build-blas),
then perhaps the difference is due to different LAPACK versions.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#7 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACDWYfvvPNUjBQjHAAhkYoHSaNbjbaNPks5sCcW_gaJpZM4N0gNP>
.
|
You can attach the kdb file with the matrix (i.e. I think it's probably a numerical problem, but it could also be an issue with how LAPACK is compiled on different machines (e.g. different compiler flags), so I'd like to investigate. |
Pretty sure it is a numerical problem, but it behaves differently on RHEL and Windows. |
Thanks!
I also tried using the recursive Cholesky function in LAPACK ( |
The way I solved it for my matrix is I added the following: Thanks again, |
Found the problem. This submatrix is not positive-definite (if that's a covariance matrix, you have perfect correlation between two variables):
Thus, the full matrix isn't positive-definite either, and Fiddling around with a scaling factor will make it positive-definite numerically, kind of like:
Dropping either of those variables works: I guess |
I did that as well, but I don't think it actually has an eigen value of zero. I think it is just very close to zero: I guess how you treat matrixes that are close to being semi positive definite instead of positive definite is a question. |
A simple test case:
a:500 500#250000?1.0
a:.qml.mm[a;flip a]
.qml.mchol[a]
In particular I get a matrix full of 0n for larger matrix
A simple solution I came up with borrows from J software's implementation of Cholesky. found here:
http://code.jsoftware.com/wiki/Essays/Cholesky_Decomposition
Here is the code I used which recursively calculates the cholesky for larger matrices using smaller matrices
The Code assumes upper triangular Cholesky: I added this function to .qml
.qml.mchollarge:{[m] $[100>l:count m;
.qml.mchol[m];
[a:.5*l;
A:m[b;b:til l-floor[a]];
B:m[c:ceiling[a]+til l-ceiling[a];b];
C:m[c;c];
L0:.qml.mchollarge A;
L1:.qml.mchollarge C-.qml.mm[T: .qml.mm[B;.qml.minv A];flip B];
Z:(count first L3;count L3:flip .qml.mm[T;L0])#0f;
(l;l)#raze (L0,'L3),(Z,'L1)]]};
The text was updated successfully, but these errors were encountered: