Conversation
penelopeysm
left a comment
There was a problem hiding this comment.
Thanks @hardik-xi11! While this is a nice and simple bit of example code, I worry that it will become out of date, and if that happens, there's no way for us to find out (because this code isn't executed). Maybe it would be good to make this an actual example, perhaps on its own page? And also it could be extended with a HiddenMarkovModels.jl extension?
I recognise this is scope creep and am not saying that that should all be done in this PR, but maybe we can try to move in that direction. For example, adding a page under the Usage section that's called something like 'external models', and then having a minimal but runnable example of SSMProblems with addlogprob! might be a good target.
|
Yess i get that so should I first work on writing up the documentation by adding a new page like this This is the code example I came up with using Turing, Distributions
# This represents an external filtering algorithm (for example from
# packages such as SSMProblems.jl or GeneralisedFilters.jl).
# For this runnable example we implement a simple function that returns
# a log-marginal likelihood.
function run_external_filter(data, θ)
return -0.5 * sum((data .- θ).^2)
end
@model function external_model(data)
# Prior over model parameters
θ ~ Normal(0, 1)
# Compute marginal log-likelihood using the external filter
logZ = run_external_filter(data, θ)
# Add the likelihood contribution to the model
Turing.@addlogprob! logZ
end
# Creating a 100-element sample vector data
data = randn(100)
model = external_model(data)
# Run the inference
chain = sample(model, NUTS(), 100)If im on the same page as you I can implement this example on a new page and make it runnable and push the changes for a review. After that is done I can later work on adding another example on the same page that can use the HMM library |
fixes TuringLang/Turing.jl#2428.
i have added a small faq in the documentation that explains GeneralisedFilters and ssm problems using the
Turing.@addlogprob!macro.i have implemented this instead of writing a full wrapper method instead and properly explained how the integration works