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

New feature: Kalman filter with missing (NaN) values #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matyasfarkas
Copy link

Hi Thore, I saw it on your to-do list.

I always wished to be contributor to your wonderful project, thus I decided to make it happen, not the least it comes handy in my own work.

The change is super simple and works. In the Kalman iteration just replace:

ℒ.axpby!(1, data_in_deviations[:, t], -1, z)

with:

z = replace(ℒ.axpby!(1, data_in_deviations[:, t], -1, z),NaN=>0) # v = data_in_deviations[:, t] - z

Using julia's missing gave me type errors and headache with Turing. Changing to NaN -s opened a shortcut to just call a replace whenever a missing value it is encountered in the KF iteration, due to missing data, then the prediction error is set to zero, leading to no update. Let me know what you think!

Hi Thore, I saw it on your to-do list. 

I always wished to be contributor to your wonderful project, thus I decided to make it happen, not the least it comes handy in my own work.

The change is super simple and works. In the Kalman iteration just replace:

ℒ.axpby!(1, data_in_deviations[:, t], -1, z)  

with:

z = replace(ℒ.axpby!(1, data_in_deviations[:, t], -1, z),NaN=>0)  
# v = data_in_deviations[:, t] - z

Using julia's missing gave me type errors and headache with Turing. Changing to NaN -s opened a shortcut to just call a replace whenever a missing value it is encountered in the KF iteration, due to missing data, then the prediction error is set to zero, leading to no update. Let me know what you think!
@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.58%. Comparing base (414d765) to head (c3023b3).
Report is 35 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (414d765) and HEAD (c3023b3). Click for more details.

HEAD has 22 uploads less than BASE
Flag BASE (414d765) HEAD (c3023b3)
23 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #94       +/-   ##
===========================================
- Coverage   85.23%   61.58%   -23.66%     
===========================================
  Files           8        8               
  Lines        5492     6653     +1161     
===========================================
- Hits         4681     4097      -584     
- Misses        811     2556     +1745     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@thorek1
Copy link
Owner

thorek1 commented Nov 23, 2024

Hi Matyas,

Thanks for pushing this issue forward.

I see the following todo's before merging this:

  • Construct diverse test cases (n time series, with missing values in m<=n time series. Catch potential filter breakdowns for different degrees of missingness. Missing values at beginning, end, or at random.). See current Kalman related test cases.
  • benchmark/profile solution for speed (categorical replace might be slower than if NaN... else. Not sure about overall overhead for that operation... benchmarking will reveal it)

Best

Thore

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

Successfully merging this pull request may close these issues.

3 participants