I’m trying to implement a model employing some linear algebra functions. I find the results is confusing. I generated a matrix (Phat) and use QR decomposition, SVD, and Cholesky decomposition on it. Here is the code and results.
print("1-1 P-hat: ", Phat) print(" QR - Q: ", qr_Q(Phat)) print(" QR - R: ", qr_R(Phat)) print(" determinant: ", determinant(Phat)) print(" eigonvalue: ", eigenvalues_sym(Phat)) print(" decompose: ", cholesky_decompose(Phat))
1-1 P-hat: [[1e+06,0,0,0,0,0,0,0,0],[0,416667,0,0,-83333.3,-83.3333,-83.3333,-83333.3,-83.3333],[0,0,1e+06,0,0,0,0,0,0],[0,0,0,1e+06,0,0,0,0,0],[0,-83333.3,0,0,416667,-83.3333,-83.3333,-83333.3,-83.3333],[0,-83.3333,0,0,-83.3333,0.416667,-0.0833333,-83.3333,-0.0833333],[0,-83.3333,0,0,-83.3333,-0.0833333,0.416667,-83.3333,-0.0833333],[0,-83333.3,0,0,-83333.3,-83.3333,-83.3333,416667,-83.3333],[0,-83.3333,0,0,-83.3333,-0.0833333,-0.0833333,-83.3333,0.416667]]
QR - Q: [[1,-0,0,0,-0,-0,-0,-0,-0],[0,0.96225,0,0,0.136083,-0.2357,-0.0007071,0.000408247,-0.00057735],[0,-0,1,0,-0,-0,-0,-0,-0],[0,-0,0,1,-0,-0,-0,-0,-0],[0,-0.19245,0,0,0.952579,-0.2357,-0.0007071,0.000408247,-0.00057735],[0,-0.00019245,0,0,-0.000272165,0.00329981,-0.7071,0.408247,-0.57735],[0,-0.00019245,0,0,-0.000272165,-0.000942803,0.707107,0.408247,-0.57735],[0,-0.19245,0,0,-0.272165,-0.942803,-0.0028284,0.00163299,-0.00057735],[0,-0.00019245,0,0,-0.000272165,-0.000942803,-2.8284e-06,-0.816496,-0.57735]]
QR - R: [[1e+06,0,0,0,0,0,0,0,0],[-0,433013,-0,-0,-144338,-48.1126,-48.1126,-144338,-48.1126],[0,0,1e+06,0,0,0,0,0,0],[0,0,0,1e+06,0,0,0,0,0],[-0,-0,-0,-0,408248,-68.0414,-68.0414,-204124,-68.0414],[-0,-0,-0,-0,-0,117.852,117.85,-353551,117.85],[-0,-0,-0,-0,-0,-0,0.707104,-1060.65,0.353549],[-0,-0,-0,-0,-0,-0,-0,612.372,-0.612372],[-0,-0,-0,-0,-0,-0,-0,-0,1.92624e-14]]
determinant: -5.20417e+18
eigonvalue: [5.22073e-12,0.5,0.5,250000,500000,500000,1e+06,1e+06,1e+06]
decompose:
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: cholesky_decompose: Matrix m is not positive definite
The results are hard to read, so I put them in Excel and format them.
The Cholesky decomposition causes error and says the matrix is not positive definite. The determinant is negative, but the eigenvalues are all positive. The multiplication of the diagonal elements of the matrix R of QR (1.74E+20) is different from the multiplication of the eigenvalues (8.16E+22).
The results are confusing for me. Am I using anything wrong? I use PyStan 2.19.1.1.