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

numerical issue in UnscentedKalmanFilterBase::computeWeights() #30

Open
jwdinius opened this issue Mar 19, 2019 · 0 comments
Open

numerical issue in UnscentedKalmanFilterBase::computeWeights() #30

jwdinius opened this issue Mar 19, 2019 · 0 comments

Comments

@jwdinius
Copy link

jwdinius commented Mar 19, 2019

The current implementation is

            ...
            T L = T(State::RowsAtCompileTime);
            lambda = alpha * alpha * ( L + kappa ) - L;
            gamma = std::sqrt( L + lambda );
            
            // Make sure L != -lambda to avoid division by zero
            assert( std::abs(L + lambda) > 1e-6 );
            
            // Make sure L != -kappa to avoid division by zero
            assert( std::abs(L + kappa) > 1e-6 );
            
            T W_m_0 = lambda / ( L + lambda );
            T W_c_0 = W_m_0 + (T(1) - alpha*alpha + beta);
            T W_i   = T(1) / ( T(2) * alpha*alpha * (L + kappa) );

For numerical reasons (i.e. not doing the divide when you could do a multiply), a better implementation would be:
The proposed implementation is

            ...
            T L = T(State::RowsAtCompileTime);
            T alphaSquared = alpha * alpha;
            lambda = alphaSquared * ( L + kappa ) - L;
            gamma = std::sqrt( L + lambda );
            
            // Make sure L != -lambda to avoid division by zero
            assert( std::abs(L + lambda) > 1e-6 );
            
            // Make sure L != -kappa to avoid division by zero
            assert( std::abs(L + kappa) > 1e-6 );
            
            T W_m_0 = lambda / ( L + lambda );
            T W_c_0 = W_m_0 + (T(1) - alphaSquared + beta);
            T W_i   = T(0.5) / (L + lambda);

I made this change when I found that the weights computed by this implementation were significantly different from this for alpha=1e-3, beta=2, kappa=0. Note: the proposed changes were shown to match the desired values.

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

1 participant