TuringLang / GeneralisedFilters.jl

Filtering and smoothing algorithms for state space models with analytic (or approximately/partially analytic) solutions
MIT License
0 stars 0 forks source link

Discrete SSMs and the Forward Algorithm #3

Closed THargreaves closed 1 month ago

THargreaves commented 1 month ago

Changes:

Issues/questions

This implementation has opened some interesting questions on how we parameterise the types of the dynamics/observations.

The discrete latent dynamics in some sense have two type parameters which we'll call:

I've ignored these in the current implementation, hardcoding T_prob -> Float64

The former is used for the state and so this is the type that would be passed on to the parent LatentDynamics{T}:

abstract type DiscreteLatentDynamics{T_state, T_prob} <: LatentDynamics{T_state} end

T_prob is used for preallocating a vector to store the filtered states and could also be used as a type constraint in the filtering methods, e.g.

function predict(
    model::DiscreteStateSpaceModel{T_state, T_prob},
    ::ForwardAlgorithm,
    step::Integer,
    state::Vector{T_prob},  # <--
    extra,
)
    ...
end

I'm generally a bit ignorant as to what the benefits of/conventions for type parameterisation are especially when it comes to AD support, so I'm not sure whether this is a good design choice or just overcomplicating things.

Any thoughts/feedback would be welcome.

yebai commented 1 month ago

Generally, parametric types are more autodiff-friendly. So what you do above is sensible.