My understanding is that a Cholesky decomposition should work on any square, positive definite matrix. I am encountering an issue where chol() fails and give the error: "the leading minor of order 3 is not positive definite" This occurs on multiple machines and version of R. Here is a minimal reproducible example: # initialize matrix values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.644,0,0,0.664,1) B = matrix(values, 4,4) # show that singular values are positive svd(B)$d # show that matrix is symmetric isSymmetric(B) # B is symmetric positive definite, but Cholesky still fails chol(B) Is this a numerical stability issue? How can I predict which matrices will fail? - Gabriel [[alternative HTML version deleted]]
Eigen shows that the matrix is not positive definite (it has a negative eigenvalue). And isSymmetric() also shows it is not symmetric - compare (3,4) and (4,3) On Tue, Nov 13, 2018 at 5:39 PM Hoffman, Gabriel <gabriel.hoffman at mssm.edu> wrote:> My understanding is that a Cholesky decomposition should work on any > square, positive definite matrix. I am encountering an issue where chol() > fails and give the error: "the leading minor of order 3 is not positive > definite" > > This occurs on multiple machines and version of R. > > Here is a minimal reproducible example: > > # initialize matrix > values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.644,0,0,0.664,1) > B = matrix(values, 4,4) > > # show that singular values are positive > svd(B)$d > > # show that matrix is symmetric > isSymmetric(B) > > # B is symmetric positive definite, but Cholesky still fails > chol(B) > > Is this a numerical stability issue? How can I predict which matrices > will fail? > > - Gabriel > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Your understanding is wrong. The eigenvalues, not singular values, must be positive, and they are not. Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 13, 2018 at 7:39 AM Hoffman, Gabriel <gabriel.hoffman at mssm.edu> wrote:> My understanding is that a Cholesky decomposition should work on any > square, positive definite matrix. I am encountering an issue where chol() > fails and give the error: "the leading minor of order 3 is not positive > definite" > > This occurs on multiple machines and version of R. > > Here is a minimal reproducible example: > > # initialize matrix > values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.644,0,0,0.664,1) > B = matrix(values, 4,4) > > # show that singular values are positive > svd(B)$d > > # show that matrix is symmetric > isSymmetric(B) > > # B is symmetric positive definite, but Cholesky still fails > chol(B) > > Is this a numerical stability issue? How can I predict which matrices > will fail? > > - Gabriel > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Aren't singular values always positive or zero? Look at eigen(B)$values to check for positive definiteness. Fix your example - your B is not symmetric. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Nov 13, 2018 at 7:30 AM, Hoffman, Gabriel <gabriel.hoffman at mssm.edu> wrote:> My understanding is that a Cholesky decomposition should work on any > square, positive definite matrix. I am encountering an issue where chol() > fails and give the error: "the leading minor of order 3 is not positive > definite" > > This occurs on multiple machines and version of R. > > Here is a minimal reproducible example: > > # initialize matrix > values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.644,0,0,0.664,1) > B = matrix(values, 4,4) > > # show that singular values are positive > svd(B)$d > > # show that matrix is symmetric > isSymmetric(B) > > # B is symmetric positive definite, but Cholesky still fails > chol(B) > > Is this a numerical stability issue? How can I predict which matrices > will fail? > > - Gabriel > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
There was a typo in my example. Here is the fixed version: # initialize matrix values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.664,0,0,0.664,1) B = matrix(values, 4,4) # show that singular values are positive svd(B)$d # show that matrix is symmetric isSymmetric(B) # B is symmetric positive definite, but Cholesky still fails chol(B) # It turns out the the *eigen* values are mixed sign. # That explains the issue eigen(B)$values Thanks for you help, especially Bert. - Gabriel From: William Dunlap <wdunlap at tibco.com<mailto:wdunlap at tibco.com>> Date: Tuesday, November 13, 2018 at 12:31 PM To: Gabriel Hoffman <gabriel.hoffman at mssm.edu<mailto:gabriel.hoffman at mssm.edu>> Cc: "r-help at r-project.org<mailto:r-help at r-project.org>" <r-help at r-project.org<mailto:r-help at r-project.org>> Subject: Re: [R] Unexpected failure of Cholesky docomposition Aren't singular values always positive or zero? Look at eigen(B)$values to check for positive definiteness. Fix your example - your B is not symmetric. Bill Dunlap TIBCO Software wdunlap tibco.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__tibco.com&d=DwMFaQ&c=shNJtf5dKgNcPZ6Yh64b-A&r=KdYcmw5SdXylMrTGSuNVkNJulowod64k0PTDC5BHZkk&m=Vq3YaG1EYDN2Fp8XpmcP8kVgEmHvlDEIwLveBpn4R4Q&s=1NN3MX73Jjmlphkfkm-NlTB-XWOrrMMN3zOGzX3y0RE&e=> On Tue, Nov 13, 2018 at 7:30 AM, Hoffman, Gabriel <gabriel.hoffman at mssm.edu<mailto:gabriel.hoffman at mssm.edu>> wrote: My understanding is that a Cholesky decomposition should work on any square, positive definite matrix. I am encountering an issue where chol() fails and give the error: "the leading minor of order 3 is not positive definite" This occurs on multiple machines and version of R. Here is a minimal reproducible example: # initialize matrix values = c(1,0.725,0,0,0.725,1,0.692,0,0,0.692,1,0.644,0,0,0.664,1) B = matrix(values, 4,4) # show that singular values are positive svd(B)$d # show that matrix is symmetric isSymmetric(B) # B is symmetric positive definite, but Cholesky still fails chol(B) Is this a numerical stability issue? How can I predict which matrices will fail? - Gabriel [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help<https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwMFaQ&c=shNJtf5dKgNcPZ6Yh64b-A&r=KdYcmw5SdXylMrTGSuNVkNJulowod64k0PTDC5BHZkk&m=Vq3YaG1EYDN2Fp8XpmcP8kVgEmHvlDEIwLveBpn4R4Q&s=NwgJPwLPzWkHUywq-roE7bv0dcwMA2p5a3-ON2AbycQ&e=> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwMFaQ&c=shNJtf5dKgNcPZ6Yh64b-A&r=KdYcmw5SdXylMrTGSuNVkNJulowod64k0PTDC5BHZkk&m=Vq3YaG1EYDN2Fp8XpmcP8kVgEmHvlDEIwLveBpn4R4Q&s=6s9m-E3Y4eRcJL-jWgz1Pbf4nQED9bgK0CB3r3KAhp8&e=> and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]