JuliaStats / TimeModels.jl

Modeling time series in Julia
Other
57 stars 28 forks source link

Allow evolution and observation matrix to vary with time #32

Closed rob-luke closed 9 years ago

rob-luke commented 9 years ago

It can be useful to have the system matrices vary with time. Is this within the scope of this package?

This is an initial implementation to open discussion. With a modified version of the oldkalman test

using TimeModels

function G1(n);  cos(2*pi*10*(1/1024)*n); end
function G2(n);  exp((1/8192)*n); end
function G3(n);  3.0; end

F = diagm([1.0])
V = diagm([2.0])
G = reshape([G1, G2, G3], 3, 1)
W = diagm([8.0, 2.5, 4.0])
x0 = randn(1)
P0 = diagm([1e7])
mod1 = StateSpaceModel(F, V, G, W, x0, P0);

x, y = simulate(mod1, 100)
filt = kalman_filter(y, mod1)
smooth = kalman_smooth(y, mod1)
milktrader commented 9 years ago

This looks interesting. cc @scidom

papamarkou commented 9 years ago

Yeap, that's a good idea - we may have optional or named arguments for G in StateSpaceModel to define default behaviour. How do you propose we set the default to behaviour, time-variant or invariant matrices?

Do you want to open a PR?

rob-luke commented 9 years ago

Glad people think its interesting. I think the current PR works with either time variant or time invariant matrices, what do you propose I should change?

Also is there a test suite available? I was a little worried id slip up on the i and i-1 s.

rob-luke commented 9 years ago

Ive also not optimised for speed or multiple types, this was just a first pass to see if there was interest (which it appears there is :) ).

papamarkou commented 9 years ago

Well, I must admit that we need to set up the test suite and also do a couple of nice changes in the interface we discussed with @milktrader a while ago regarding the type definitions of models. I need to put it in my todo list.

Yes, if you can write up a test, without worrying too much for its placement or name but mostly that it is operational, it would be helpful.

Great, any optimisations are welcome. Only one quick question, how is the time invariant case accounted for? As I can see G is time-dependent in the example above.

milktrader commented 9 years ago

Okay, I'll put the test suite back on my radar. I'll update travis.yml and get us up to speed on the latest best practices.

rob-luke commented 9 years ago

@scidom No problem, I can add a few tests. Ill have time before the end of the week.

@milktrader I would also be keen to hear about test suite best practices. Is there a standard for commenting/documentation yet? Ive been using Docile.j

papamarkou commented 9 years ago

Thanks @codles, appreciated. Once you add the test(s), we are ready to merge. Thanks for the PR.

milktrader commented 9 years ago

I'm thinking to go the readthedocs route for online documentation and just started playing with the new @doc macro that v0.4 just implemented for REPL documentation (supporting ? in REPL). I'll look at Docile.jl. Here is a link about the new macro discussion.https://github.com/JuliaLang/julia/issues/8966

milktrader commented 9 years ago

Oh I see. Docile.jl is being integrated into Base. So we're talking about the same thing.