-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Draft work on updating AdvancedPS to match the SSMProblems interface.
To run this code you need to
dev
SSMProblems in the AdvancedPS environment anddev
AdvancedPS in the examples/particle-gibbs environment.