Closed torfjelde closed 1 year ago
Yes, the Particle
type fully specifies a model -- each model defines its Particle
type and the transition!!
method. But it is good to know this is confusing, maybe we can reconsider the signature to clarify this.
each model defines its Particle type
How do I define different SMC samplers from this that are applicable to more than a single model type?
I would have imagined something like:
PackageA
defines a certain SMC sampler, e.g. PG.PackageB
then defines a few methods, e.g. transition!!
, in such a way that it can take advantage of the SMC sampler defined in PackageA
.But if the Particle
and the model is coupled, then things become a bit more annoying, no?
Feel like the naming is a bit unfortunate here, Particle
really is the Model
as you see it @torfjelde. The actual Particle
implementation should be left to the sampler implementation.
Roughly, the way I think this could work:
SSMProblems
:
abstract type AbstractStateSpaceModel end
function transition!!(::AbstractStateSpaceModel) end
function emission_logdensity(::AbstractStateSpaceModel) end
function isdone(::AbstractSpaceModel) end
PackageA
: (SMC implementation)
struct Particle{T<:AbstractStateSpaceModel}
model::T
parent::Particle{T} # Whatever datastructure the specialization needs
end
function sample(model::AbstractStateSpaceModel, ::Particle) end
PackageB
(Model Implementation)
struct LinearSSM{T} <: AbstractStateSpaceModel
state::T
end
function transition!!(::LinearSSM) end
...
otherwise you end up having to deal with particle dynamics (copying, memory layout ...) in the model part and that doesn't feel quite right.
Should be fixed by #16
I'm slightly confused as to what the intention of the interface methods are.
Take the
transition!!
method for example. IIUC this is supposed to be implemented on a per-model basis, no?But the current code seems to indicate that this method should have the signature
But this is completely lacking any way to dispatch on the target model.
So am I misunderstanding this? Or is the
Particle
supposed to define all the behavior (including the model)? Or is this simply a typo, and it should indeed be?