# Cholesky decomposition in error covariance [closed]

I try to implement Unscented Kalman Filter. Everything seems to be done correctly but I do receive an error about Cholesky decomposition

raise LinAlgError('Matrix is not positive definite - '
numpy.linalg.linalg.LinAlgError: Matrix is not positive definite - Cholesky decomposition     cannot be computed


The problem is that the fail occurs always after some runs of the algorithm. I keep checking determinant and it's not zero. I tried to remove dependencies from the model.

I don't have any idea how to proceed from now.

I don't know it it will be any help, but this is my python's implementation of Sigma point:

def SigmaPoints(xm, P, kappa):
''' SigmaPoints calculation'''
n = len(xm)
xm = np.asmatrix(xm)         # checks how big is state vector
Xi = np.asmatrix(np.zeros((n,n*2+1)))# creates zero matrix sigmaPoints n-rows, 2n+1 col
W = np.zeros((n*2+1,1)) # weights for each sigmaPoint as a vector
Xi[:,0] = xm            # 1st column init to input xm
W[0] = kappa*1.0/(n+kappa) # update first weight
U = np.linalg.cholesky(P*(n+kappa)) #  returns identityMat * value
for k in range(n):
Xi[:,k] = xm + U[k-1, :].T
W[k] = 1.0/(2.0*(n+kappa))
for k in range(n):
Xi[:, n+k] = xm - U[k-1,:].T
W[n+k]=1.0/(2.0*(n+kappa))
return (Xi, W)

• There's nothing in your code that can help us say any more than the error message does (your matrix is not positive definite), because it reveals nothing at all about the values of P, n, or kappa which form the argument to the Cholesky decomposition. As Mike Nute points out, checking the determinant does you no good. Even two by two matrices with positive determinant can be non-positive definite (such as any diagonal matrix with two negative values).
– whuber
Commented Aug 14, 2013 at 19:08
• I have voted to close this question because you haven't responded to the request for information needed to answer it.
– whuber
Commented Sep 13, 2013 at 19:22
• @whuber thank you for the input. The problem was in the model, not the Cholesky procedure. in the model I had some dependency, which turned up to crop up in some situations. Probably I should really need to completely re-write the question, but it would be different story. If anyone provide the answer such "start with analysing dependences in the model ..." I would be very happy to accept the answer, although thank you very much for what was already written. Commented Sep 14, 2013 at 20:59