Skip to content

Commit

Permalink
suggested changes to allow retrieving measurement log-likelihood from…
Browse files Browse the repository at this point in the history
… the UKF
  • Loading branch information
William Kreamer committed May 29, 2016
1 parent 0061879 commit 77e5a4f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions filterpy/kalman/UKF.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
from numpy import eye, zeros, dot, isscalar, outer
from scipy.linalg import inv, cholesky

from scipy.stats import multivariate_normal

class UnscentedKalmanFilter(object):
# pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -56,12 +56,17 @@ class UnscentedKalmanFilter(object):
Readable Attributes
-------------------
xp : numpy.array(dim_x)
predicted state (result of predict())
x : numpy.array(dim_x)
predicted/updated state (result of predict()/update())
P : numpy.array(dim_x, dim_x)
predicted/updated covariance matrix (result of predict()/update())
Pp : numpy.array(dim_x, dim_x)
predicted covariance matrix (result of predict())
likelihood : scalar
Likelihood of last measurement update.
log_likelihood : scalar
Log likelihood of last measurement update.
References
----------
Expand Down Expand Up @@ -214,6 +219,7 @@ def residual(a, b):
self.points_fn = points
self.x_mean = x_mean_fn
self.z_mean = z_mean_fn
self.log_likelihood = 0.0

if sqrt_fn is None:
self.msqrt = cholesky
Expand Down Expand Up @@ -340,7 +346,12 @@ def update(self, z, R=None, UT=None, hx_args=()):
y = self.residual_z(z, zp) #residual
self.x = self.x + dot(K, y)
self.P = self.P - dot3(K, Pz, K.T)
self.log_likelihood = multivariate_normal.logpdf(
np.zeros((len(y))), y, Pxz+Pz, allow_singular=True)

@property
def likelihood(self):
return math.exp(self.log_likelihood)

def batch_filter(self, zs, Rs=None, residual=None, UT=None):
""" Performs the UKF filter over the list of measurement in `zs`.
Expand Down

0 comments on commit 77e5a4f

Please sign in to comment.