Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinAlgError: 1-th leading minor of the array is not positive definite #296

Open
Mahdi22223 opened this issue Nov 3, 2023 · 1 comment
Open

Comments

@Mahdi22223
Copy link

Mahdi22223 commented Nov 3, 2023

Dear Friends,

I am a beginner in using the Unscented Kalman Filter (UKF) and would greatly appreciate your assistance with an issue I'm encountering. Despite my efforts, I consistently receive the error: LinAlgError: 1-th leading minor of the array is not positive definite.

I've tried to mitigate this issue by adding a regularization term to relax the condition when the state covariance matrix P becomes non-positive definite after the prediction step. However, despite numerous adjustments to the parameters, the error persists.

Currently, I'm working with a simple degradation model that incorporates a Wiener process. My goal is to understand and resolve this issue before further refining the model.

Any guidance or suggestions would be immensely helpful.

from filterpy.kalman import UnscentedKalmanFilter as UKF
from filterpy.kalman import MerweScaledSigmaPoints
import numpy as np
import matplotlib.pyplot as plt
degradation_rate = 0.1 # Set this to your desired degradation rate

Define the state transition function

def f(x, dt):
degradation_rate = 0.1 # Set this to your desired degradation rate
w = np.random.normal(0, 1) # Wiener process
return np.abs(x - dt * degradation_rate + w) # Use absolute value to ensure the state is non-negative

def h(x):
return x

dt = 0.1 # time step

points = MerweScaledSigmaPoints(1, alpha=0.001, beta=2., kappa=0)

ukf = UKF(dim_x=1, dim_z=1, dt=dt, fx=f, hx=h, points=points)

ukf.x = np.array([1.]) # initial RUL

ukf.P = np.eye(1) * 10.0 # Set P to be a diagonal matrix

regularization_value = 1e-3

ukf.Q = np.eye(1) * 10.0 + regularization_value # Set Q to be a diagonal matrix and add regularization

ukf.R = np.array([[0.1]])+ regularization_value

Generate ground truth and observations

t = np.arange(0, 10, dt)
ground_truth = 100 - t * degradation_rate
observations = ground_truth + np.random.normal(0, np.sqrt(ukf.R[0, 0]), size=t.shape)

Apply the UKF and collect predictions

predictions = []
for z in observations:
ukf.predict()
ukf.update(np.array([z]))
predictions.append(ukf.x[0])

Plot ground truth, UKF predictions, and observations

plt.figure(figsize=(10, 6))
plt.plot(t, ground_truth, 'g-', label='Ground Truth')
plt.plot(t, predictions, 'r-', label='UKF Predictions')
plt.scatter(t, observations, c='b', label='Observations')
plt.legend()
plt.xlabel('Time')
plt.ylabel('RUL')
plt.title('UKF for RUL Estimation')
plt.grid(True)
plt.show()

@efeerdogannn
Copy link

Hello,

I have the same problem as you when using the UKF. Did you make any progress onsolving the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants