-
Notifications
You must be signed in to change notification settings - Fork 10
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
Kalman filter with inputs #5
Conversation
@@ -166,7 +191,7 @@ Kalman filter | |||
function kalmanfilter(yy::AbstractMatrix, M::LinearHomogSystem) | |||
d = size(M.Phi, 1) | |||
n = size(yy, 2) | |||
kalmanfilter!(0:n, yy, zeros(d, n), zeros(d, d, n), zeros(d, d, n), M) | |||
kalmanfilter!(1:n, yy, zeros(d, n), zeros(d, d, n), zeros(d, d, n), M) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, this is a mistake while rebasing.
Codecov Report
@@ Coverage Diff @@
## master #5 +/- ##
==========================================
+ Coverage 68.59% 71.27% +2.67%
==========================================
Files 6 7 +1
Lines 242 275 +33
==========================================
+ Hits 166 196 +30
- Misses 76 79 +3
Continue to review full report at Codecov.
|
I won't have time to look into it until next week, unfortunately, but so far it looks very nice. I assume that we'll need a function like EDIT: Nevermind, that's your |
It works! I get the same results as with my PR.
If I'm understanding things correctly, you do things this way because it's awkward to talk about the transition from t=0 to t=1, so you'd rather let the user directly specify the post-transition probability? The output I'm fine with merging this instead of my PR. |
if s == t # if `s == t`` no time has passed | ||
x + u, P, one(M.Phi) | ||
else | ||
M.Phi*x + M.b + u, M.Phi*P*M.Phi' + M.Q, M.Phi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand why you have both M.b
and u
, but the redundancy makes me a bit uncomfortable. They're the same quantity. Perhaps we should assert that uu==nothing
when using LinearEvolution
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How I think of them is that b
is the intrinsic drift and u
is an control/external signal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but unless I'm mistaken, u
is unspecified (implicitly 0?) when GenericLinearEvolution
is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericLinearEvolution will dispatch on function https://github.com/mschauer/Kalman.jl/pull/5/files/0826886fe9698002c68cc8c16c3c8c39a6e8d92e#diff-d0bf3c72d95233c17cc7933aeaa30298R37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. What I mean is that with LinearObservation
(line 33), the evolution is Phi*x + M.b + u
(transition matrix + intrinsic drift + control/external signal), whereas with GenericLinearEvolution
(line 39), it's Phi*x + b
Anyway, it's no big deal; just seemed a bit inconsistent.
|
||
|
||
function predict!(s, x, P, t, u, M) | ||
if s == t # if `s == t`` no time has passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this special-casing also be done in predict!(s, x, P, t, U, M::GenericLinearEvolution)
?
Perhaps timesteps should be assumed homogeneous, unless using |
In https://github.com/mschauer/Kalman.jl/pull/5/files#diff-d0bf3c72d95233c17cc7933aeaa30298R38 |
|
||
struct GenericLinearObservation <: AbstractObservation | ||
end | ||
struct GenericLinearEvolution{TPhi,Tb,TQ} <: AbstractEvolution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for this type to be parametric? GenericLinearObservation
is parameter-less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
I started building code on top of this PR. Is there any significant reason not to merge it? Small issues can be fixed afterwards... |
You are right, das Bessere ist der Feind des Guten ("The best is the enemy of the good.") |
Doch! |
@cstjean This would be my design for #4 . Can you give it a try? See the test file
testinput.jl
how to use the new set-up, a varyingb
would be achieved with theGenericLinearObserver
.Note that the time runs from
1:n
in the new parts and the prior is assumed to be valid for time1
.Smoother and all convenience wrapper as well as iterators are still missing.