Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bit confused regarding the interface #9

Closed
torfjelde opened this issue Jun 13, 2023 · 4 comments
Closed

A bit confused regarding the interface #9

torfjelde opened this issue Jun 13, 2023 · 4 comments

Comments

@torfjelde
Copy link
Member

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

transition!!(rng, step, particle[, cache])

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

transition!!(rng, model, step, particle[, cache])

?

@yebai
Copy link
Member

yebai commented Jun 13, 2023

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.

@torfjelde
Copy link
Member Author

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:

  1. PackageA defines a certain SMC sampler, e.g. PG.
  2. 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?

@FredericWantiez
Copy link
Member

FredericWantiez commented Jun 19, 2023

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.

@yebai
Copy link
Member

yebai commented Sep 13, 2023

Should be fixed by #16

@yebai yebai closed this as completed Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants