Replacing Cholesky factorization from IMSL MCHOL (Fortran) in C#

840 views Asked by At

I am converting a Fortran program to C#. This has to be done in bits and pieces, with proof of concepts along the way.

One of these initial steps is to replicate the IMSL functions it uses. Luckily, it only uses a chosen few: some trivial random number generation, some trivial normal distribution inverts but also one not-so-trivial one: MCHOL.

From the documentation:

Computes an upper triangular factorization of a real symmetric matrix A plus a diagonal matrix D, where D is determined sequentially during the Cholesky factorization in order to make A + D nonnegative definite.

Routine MCHOL computes a Cholesky factorization, RTR, of A + D where A is symmetric and D is a diagonal matrix with sufficiently large diagonal elements such that A + D is nonnegative definite. The routine is similar to one described by Gill, Murray, and Wright (1981, pages 108−111). Here, though, we allow A + D to be singular.

(There are more details and a sample at the link).

For my proof of concept, I need to able to replicate the results as provided in the sample for the MCHOL documentation: passing in this matrix from the sample:

  DATA (A(1,J),J=1,N)/36.0, 12.0, 30.0, 6.0, 18.0/
  DATA (A(2,J),J=1,N)/12.0, 20.0, 2.0, 10.0, 22.0/
  DATA (A(3,J),J=1,N)/30.0, 2.0, 29.0, 1.0, 7.0/
  DATA (A(4,J),J=1,N)/6.0, 10.0, 1.0, 14.0, 20.0/
  DATA (A(5,J),J=1,N)/8.0, 22.0, 7.0, 20.0, 40.0/

And getting the following in return:

  6.000   2.000   5.000   1.000   3.000
  0.000   4.000  -2.000   2.000   4.000
  0.000   0.000   0.000   0.000   0.000
  0.000   0.000   0.000   3.000   3.000
  0.000   0.000   0.000   0.000   2.449

So far, I've tried using Math.NET, but it will not run on this example matrix because it is not positive definite.

I've also tried parts of ALGLIB, specifically spdmatrixcholesky. It seems to work, but only for part of the matrix:

  6       2       5       1       3
  12      4       -2      2       4
  30      2       0       1       7
  6       10      1       14      20
  8       22      7       20      40

Does anyone have any idea what I am doing wrong here? Do I need to call a different function here?

Since a quick answer doesn't seem to be in the cards, it might be best if I understood the underlying mathematics so I can at least try to figure out what is going on here. Any theoretical underpinning or pointers appreciated as well.

2

There are 2 answers

0
Nathan Whitehead On BEST ANSWER

The MCHOL routine is not just doing Cholesky decomposition, it is doing the steps of Cholesky and keeping track of the D diagonals that let it keep going. It's a "modified" Cholesky. Normal Cholesky needs a positive definite input, which the example is not.

Here's an implementation of MCHOL in MATLAB. I would use this implementation to build a .NET version.

Wikipedia:Cholesky decomposition

2
Francois Jacq On

In your example a(5,1)=8 should be equal to a(1,5)=18. So your initial matrix is not symmetrical.