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

Update AdvancedPS to match SSMProblems interface #93

Closed
wants to merge 4 commits into from

Conversation

THargreaves
Copy link
Contributor

Draft work on updating AdvancedPS to match the SSMProblems interface.

To run this code you need to dev SSMProblems in the AdvancedPS environment and dev AdvancedPS in the examples/particle-gibbs environment.

examples/particle-gibbs/script.jl Outdated Show resolved Hide resolved
examples/particle-gibbs/script.jl Outdated Show resolved Hide resolved
src/container.jl Outdated Show resolved Hide resolved
src/pgas.jl Outdated Show resolved Hide resolved
src/smc.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
f(θ::Parameters, state, t) = Normal(θ.a * state, θ.q)
g(θ::Parameters, state, t) = Normal(0, exp(0.5 * state))
f₀(θ::Parameters) = Normal(0, θ.q)
f₀(model::StochasticVolatilityModel) = Normal(0, model.q)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit redundant with transition!!. Consider merging these into the function transition!!.

pg = AdvancedPS.PG(Nₚ, 1.0)
chains = sample(rng, model, pg, Nₛ; progress=false);
chains = sample(rng, model, pg, Nₛ; observations=y, progress=false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue here is that AbstractMCMC does not forward data explicitly, it just assumes the obervables are internal to the model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. One way around this would be to define something like

struct ConditionedSSM
    ssm::AbstractStateSpaceModel
    observations::Vector{Vector{Float64}}
end

though that's one more bit of API bloat.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea; it is also how the condition mechanism works for DynamicPPL models.

Copy link
Member

@FredericWantiez FredericWantiez Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be nested, or another type, as long as these are defined by the user:

function emission_logensity(model::AbstractStateSpaceModel, state, step::Int) 
   return logpdf(Normal(state), observations[step]) # Global scope
end

or

function emission_logensity(model::AbstractStateSpaceModel, state, step::Int) 
   return logpdf(Normal(state), model.observations[step]) 
end

It's a bit what model() | (; y=observations) would do in DynamicPPL

p = particles[i]

# Obtain ``\\log p(yₜ | y₁, …, yₜ₋₁, x₁, …, xₜ, θ₁, …, θₜ)``, or `nothing` if the
# the execution of the model is finished.
# Here ``yᵢ`` are observations, ``xᵢ`` variables of the particle filter, and
# ``θᵢ`` are variables of other samplers.
isref = p === ref
score = advance!(p, isref)
score = advance!(p, y, isref)
Copy link
Member

@FredericWantiez FredericWantiez Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make backward compatibility with Libtask quite difficult @yebai

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@THargreaves can you revert this change for now? It will take a bit more work on the Turing side before we can do it.

@yebai yebai mentioned this pull request Apr 12, 2024
@yebai yebai closed this Apr 12, 2024
@yebai yebai deleted the th-ssmproblems-interface branch April 12, 2024 19:33
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

Successfully merging this pull request may close these issues.

3 participants