question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MerweScaledSigmaPoints weights do not sum to 1, documentation says it should

See original GitHub issue

For example:

import numpy as np
from filterpy.kalman import MerweScaledSigmaPoints as SigmaPoints

sigma_points = SigmaPoints(n=9, alpha=0.001, beta=2, kappa=-6)
Wm, Wc = sigma_points.weights()
print np.sum(Wm)
print np.sum(Wc)

Which returns

1.0000000005238689
3.9999990007490851

While Wm is small enough to be rounding error, Wc seems to go against notes in the documentation. Now, I’m not saying MerweScaledSigmaPoints is set wrong – as far as I can tell all the equations are right. However, the book and documentation both say that Wc “must sum to 1”.

So what’s the deal?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
peter-morancommented, Aug 5, 2016

I have noticed also noticed that my 0’th weight is negative for all reasonable parameterizations and that I occasionally get non-positive semidefinite matracies.

I found additional discussion at Math Stack Exchange on these negative values.

I found Julier’s newer paper, The Scaled Unscented Transform, from the Wikipedia citations. Julier develops the scaled unscented transform which allows approximation of a Gaussian without spreading out the sigma points too much without the use of negative weights. Then there is equivalent alternative form given which does use negative weights, but which, by equivalence to the original method, will always generate true covariance matrices (disregarding numerical error). In the link there are some typos in particular equation (15) is contradictory to (24) for i=0i=0. The correct version is the one in (15) which implies that the zeroth weight is negative for small αα. Again, this is fine because of Theorem 3 in the appendix which shows the equivalence to the true covariance matrix P∗zzPzz∗.

In that same journal article, I found the warning

The predicted mean and covariance are accurate to the second order and P yy is guaranteed to be positive semidefinite if all of the untransformed weights are non-negative.

It looks like the Scaled Sigma Point selection used in this library is partially different. In the Scaled Sigma Point selection section in the Bayesian filtering book it says

Since 2005 or so research and industry have mostly settled on the version published by Rudolph Van der Merwe in his 2004 PhD dissertation [1]. It performs well with a variety of problems and it has a good tradeoff between performance and accuracy. It is a slight reformulation of the Scaled Unscented Transform published by Simon J. Julier [2].

While the Van der Merwe selection method is supposed to be based on Julier’s Scaled Unscented Transform, the weighting methods seems significantly. Particularly, in “The Scaled Unscented Transform” all weights are chosen to force the sum of them to be equal to 1. @rlabbe is there any chance you could help me understand the differences?

For now I have switched to using JulierSigmaPoints, but I would prefer a scaled sigma point selection method.

0reactions
KorgBoycommented, Oct 17, 2017

I confirm that the Wm values sum to 1, and the Wc values sum to 4. The covariance matrix for the output ‘Y’ doesn’t look right in my own testing. My covariance matrix… ie. Py has unusually large positive values for the variance (diagonal) terms. Just doesn’t look right. This is likely due to the weights not being what we need.

Peter-Moran said this : “Then wouldn’t the covariance grow as a function of the sum of your sigma points? If that is true, that would mean that your sigma point definition would seriously impact your system covariance, right?

That’s exactly what I’m seeing right now. I computed the Wc weight values…they do sum up to 4… and when I use those weights for getting the Py (ie. output covariance matrix) matrix, the elements of Py appear too large. Something isn’t right with the way that these weights are selected, or chosen. No problem with Wm weights though, as they definitely sum to 1. The problem is with the Wc weight values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for filterpy.kalman.sigma_points
[docs]class MerweScaledSigmaPoints(object): """ Generates sigma points and weights according to Van der Merwe's 2004 dissertation[1] for the ...
Read more >
10-Unscented-Kalman-Filter.ipynb
We must conclude that one sample will not work. ... The first two equations are the constraint that the weights must sum to...
Read more >
10-Unscented-Kalman-Filter.ipynb
We must conclude that a one point sample will not work. ... For this to work for identity we will want the sums...
Read more >
Scaling factor and weights in Unscented Transform (UKF)
I observe the same thing about the covariance weight. The sum of mean weight is 1 while the sum of covariance weight is...
Read more >
Kalman and Bayesian Filters in Python
I will teach you enough to get started; refer to NumPy's documentation if you ... 61 This is not a probability distribution because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found