TuringLang / SSMProblems.jl

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

Update documentation #16

Closed FredericWantiez closed 1 year ago

FredericWantiez commented 1 year ago

573cab3 actually feels a bit weird, the model definition is now specialized to the concrete particle type:

function transition!!(rng::AbstractRNG, t::Int, particle::Particle{<:LinearSSM})
    if t == 1
        return Particle(LinearSSM(rand(rng, f0(t))))
    else
        return Particle(LinearSSM(rand(rng, f(t, particle.model.state))))
    end
end

where if we just dispatch on the model, like in 6394704, we can drop-in different particle estimators with different specialization of AbastractParticle{T}

yebai commented 1 year ago
function transition!!(rng::AbstractRNG, t::Int, particle::Particle{<:LinearSSM})
    if t == 1
        return Particle(LinearSSM(rand(rng, f0(t))))
    else
        return Particle(LinearSSM(rand(rng, f(t, particle.model.state))))
    end
end

function transition!!(rng::AbstractRNG, t::Int, m::LinearSSM, particle::Particle)
    if t == 1
        return Particle(rand(rng, f0(t)), m)
    else
        return Particle(rand(rng, f(t, particle.model.state)), m)
    end
end

struct Particle{T}
  z::T
end
Particle(z, m) = particleof(m)(z)

function particleof(::AbstractSSMProblem) 

particleof(::LinearSSM) = Vector{Float32}
yebai commented 1 year ago

@devmotion can you take a look at this PR? I'm very involved in the discussions so might be slightly biased.