Skip to content

Commit

Permalink
New feature: Kalman filter with missing (NaN) values
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
matyasfarkas authored Nov 22, 2024
1 parent 8e2b8f5 commit c3023b3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/MacroModelling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8635,7 +8635,8 @@ function run_kalman_iterations(A::Matrix{S}, 𝐁::Matrix{S}, C::Matrix{Float64}
Ptmp = similar(P)

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

mul!(Ctmp, C, P) # use Octavian.jl
Expand Down

0 comments on commit c3023b3

Please sign in to comment.