scipy - Numpy inaccurate matrix inverse -
While computing the matrix in the numpy (solving the linear system) numpy, I feel that it is a huge mistake.
- Is this a normal level of inaccuracy?
- How can I improve the accuracy of this calculation?
- In addition to this, is there a way to solve this system more efficiently in a sample or suspicious (
scipy.linalg.cho_solve
was promising, but what do I do? is)?
In the code given below, cholM
is a 128 x 128 matrix. Matrix data is too big to include here but is located on the pastebine.
In addition, the original vector, ovec
, is being randomly selected, therefore the accuracy of the ovec
varies, but, in most cases In, the error is still not highly acceptable.
Edit There is very little error in solving the system using singular value decomposition compared to other methods.
import num rpm as numpy.random import numpy.linalg as lynx import numpy np cholM = np.loadtxt ('cholM.txt') dims = len (cholM ) Print 'dimension', retard ovec = rnd.normal (size = dim) rvec = np.dot (cholM.T, ovec) invCholM = lin.inv (cholM.T) svec = np.dot (invCholM, rvec) svec1 = Lin .solve (cholM.T, rvec) def back_substitute (M, v): r = np.zeros (lane) k = len (v) -1 r [k] = v [k] / m [ For the k, K] the emerange (len (v) -2, -1, -1): r [k] = (v [k] -np.dot (m [k, k + 1:], r [k] + 1:])) / m [k] returns r svec2 = back_substitute (cholM.T, rvec) u, s, v = lin.svd (cholm) svec3 = np.dot (u, np.dot (np diameter) G (1./s), np.dot (v, rvec)) for k in Xrange, print '% 20.3f% 20.3f% 20.3f% 20.3f '% (ovec [k] -svec [K], ovec [k] -svec1 [k], ovec [k] -svec2 [k], ovec [k] -svec3 [k]) np.all (np .abs (ovec-svec) & lt; 1e-5) Use NP.All (NP.Abs (OVC-SVC1) & lt; 1e-5)
As written by Cryig J Copi and @ PV, the size of the cholM
matrix is around 10 ^ 16, It shows that to achieve high accuracy in inversion, very high numerical precision is necessary.
The position number can be determined on the basis of the minimum singular value of the ratio of the maximum singular values. In this example, this ratio is not the same as the proportion of eagenvalues.
Comments
Post a Comment