TuringLang / SSMProblems.jl

Common abstractions for state-space models
http://turinglang.org/SSMProblems.jl/
MIT License
2 stars 2 forks source link

Update SSMProblems.jl interface #38

Closed THargreaves closed 1 month ago

THargreaves commented 3 months ago

An update to the SSMProblems.jl interface (changes to documentation and examples to come in a separate PR).

The key changes are as follows:

After discussing last week that we could pass extras in as a kwarg rather than as part of the conditional model, I realised that we could do the same with observations, making ConditionedStateSpaceModel redundant, hence it is not included in this PR.

A few features that I have not implemented in this PR yet in order to keep it simple:

A few things I wasn't sure about:

yebai commented 3 months ago

A few things I wasn't sure about:

Do we use US or UK spellings for method names? (initialise or initialize?)

It doesn't really matter -- happy to keep UK spelling.

Is there a type stability issue with the definitions of methods for StateSpaceModel? Is using hasmethod an efficient way to check if a transition distribution is defined? Would a try-catch or cached value be better?

I'll leave these questions for @FredericWantiez to answer.

THargreaves commented 1 month ago

Good point. I'll just remove the PDMat entirely. Seems overkill for what is meant to be an introductory example.

THargreaves commented 1 month ago

I'm a bit at a loss as to why the Kalman filter example doc page keeps failing:

ERROR: LoadError: LoadError: ParseError:
# Error @ /Users/tim/Particle Filtering/SSMProblems.jl/docs/src/examples/kalman-filter.md:10:52
    x_filts = Vector{Vector{latent_type}}(undef, T)
    P_filts = Vector{Matrix{latent_type}}(undef, T)
#                                                  └ ── Expected `end`
in expression starting at /Users/tim/Particle Filtering/SSMProblems.jl/docs/src/examples/kalman-filter.md:10
when executing the following code block from inputfile `~/Particle Filtering/SSMProblems.jl/examples/kalman-filter/script.jl`

```julia
function AbstractMCMC.sample(
    model::LinearGaussianSSM,
    ::KalmanFilter,
    observations::AbstractVector,
    extras::AbstractVector,
)
    T = length(observations)
    latent_type = only(typeof(model.latent_dynamics).parameters)
    x_filts = Vector{Vector{latent_type}}(undef, T)
    P_filts = Vector{Matrix{latent_type}}(undef, T)
```

Does Literate.jl not allow blank lines in functions or am I missing something obvious?

THargreaves commented 1 month ago

Simplified the interface to only contain simulate, logdensity, distribution. Docs and example updated. Think we're ready to merge now.

In the process I removed the SSM level versions of the old functions, since I realised they were largely redundant, and instead it makes more sense to define just a forward simulation method for each SSM type, which I've now added.

One thing to note is that the VSCode Julia extension doesn't play well with the function overloading and displays numerous "Possible method call error."s. I think this is more of a bug with the parser/linter and also occurred with the old-old interface, before splitting transition into two functions.