Skip to content

Commit 60ce2dd

Browse files
committed
Custom unscented_transform for rts #151
The RTS smoother of the UKF didn't let you specify a custom unscented transform function.
1 parent 700a1a8 commit 60ce2dd

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ linux-64/
1919
osx-64/
2020
filterpy/kalman/i.py
2121
filterpy/inprogress.py
22+
.pytest_cache
2223

filterpy/changelog.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
Version x.x.x
2+
=============
3+
* Improved documentation
4+
* Github #151 - added ability to specify unscented transform function for
5+
the UKF RTS smoother.
6+
7+
18
Version 1.4.2
29
=============
310

411
* added a fast inverse of a diagonal matrix function common.inv_diagonal()
512

6-
* added ability to order Q matrix by dimension or derivative with the helper
13+
* added ability to order Q matrix by dimension or derivative with the helper
714
functions
815

916
* mahalanobis, log-likelihood, and likelihood only computed when requested;

filterpy/kalman/UKF.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def batch_filter(self, zs, Rs=None, dts=None, UT=None, saver=None):
611611

612612
return (means, covariances)
613613

614-
def rts_smoother(self, Xs, Ps, Qs=None, dts=None):
614+
def rts_smoother(self, Xs, Ps, Qs=None, dts=None, UT=None):
615615
"""
616616
Runs the Rauch-Tung-Striebal Kalman smoother on a set of
617617
means and covariances computed by the UKF. The usual input
@@ -637,6 +637,12 @@ def rts_smoother(self, Xs, Ps, Qs=None, dts=None):
637637
an array, then each element k contains the time at step k.
638638
Units are seconds.
639639
640+
UT : function(sigmas, Wm, Wc, noise_cov), optional
641+
Optional function to compute the unscented transform for the sigma
642+
points passed through hx. Typically the default function will
643+
work - you can use x_mean_fn and z_mean_fn to alter the behavior
644+
of the unscented transform.
645+
640646
Returns
641647
-------
642648
@@ -674,6 +680,9 @@ def rts_smoother(self, Xs, Ps, Qs=None, dts=None):
674680
if Qs is None:
675681
Qs = [self.Q] * n
676682

683+
if UT is None:
684+
UT = unscented_transform
685+
677686
# smoother gain
678687
Ks = zeros((n, dim_x, dim_x))
679688

@@ -688,7 +697,7 @@ def rts_smoother(self, Xs, Ps, Qs=None, dts=None):
688697
for i in range(num_sigmas):
689698
sigmas_f[i] = self.fx(sigmas[i], dts[k])
690699

691-
xb, Pb = unscented_transform(
700+
xb, Pb = UT(
692701
sigmas_f, self.Wm, self.Wc, self.Q,
693702
self.x_mean, self.residual_x)
694703

0 commit comments

Comments
 (0)