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

Kalman filter with inputs #5

Merged
merged 1 commit into from
Mar 29, 2018
Merged

Kalman filter with inputs #5

merged 1 commit into from
Mar 29, 2018

Conversation

mschauer
Copy link
Owner

@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 varying b would be achieved with the GenericLinearObserver.
Note that the time runs from 1:n in the new parts and the prior is assumed to be valid for time 1.

Smoother and all convenience wrapper as well as iterators are still missing.

@@ -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)
Copy link
Owner Author

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-io
Copy link

codecov-io commented Feb 15, 2018

Codecov Report

Merging #5 into master will increase coverage by 2.67%.
The diff coverage is 87.5%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/Kalman.jl 88.88% <66.66%> (-0.48%) ⬇️
src/input.jl 92.3% <92.3%> (ø)
src/ellipse.jl 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b84e8bc...0826886. Read the comment docs.

@cstjean
Copy link
Collaborator

cstjean commented Feb 15, 2018

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 observe! for the transition model?

EDIT: Nevermind, that's your predict! function.

@cstjean
Copy link
Collaborator

cstjean commented Feb 19, 2018

It works! I get the same results as with my PR.

the prior is assumed to be valid for time 1.

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 xxf2 now contains the hidden state from t=2 to t=n+1, right?

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
Copy link
Collaborator

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?

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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
Copy link
Collaborator

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)?

@cstjean
Copy link
Collaborator

cstjean commented Feb 20, 2018

Perhaps timesteps should be assumed homogeneous, unless using GenericLinearEvolutionWithInhomogeneousTime(), in which case they are to be passed in U?

@mschauer
Copy link
Owner Author

In https://github.com/mschauer/Kalman.jl/pull/5/files#diff-d0bf3c72d95233c17cc7933aeaa30298R38
one would set Phi = I and b = 0 to achieve the same effect.


struct GenericLinearObservation <: AbstractObservation
end
struct GenericLinearEvolution{TPhi,Tb,TQ} <: AbstractEvolution
Copy link
Collaborator

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@cstjean
Copy link
Collaborator

cstjean commented Mar 29, 2018

I started building code on top of this PR. Is there any significant reason not to merge it? Small issues can be fixed afterwards...

@mschauer
Copy link
Owner Author

You are right, das Bessere ist der Feind des Guten ("The best is the enemy of the good.")

@mschauer mschauer merged commit 3e01e3c into master Mar 29, 2018
@cstjean
Copy link
Collaborator

cstjean commented Mar 29, 2018

Doch!

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.

None yet

3 participants