Skip to content

add faq about ssm integration#685

Open
hardik-xi11 wants to merge 1 commit intoTuringLang:mainfrom
hardik-xi11:docs-ssm-integration
Open

add faq about ssm integration#685
hardik-xi11 wants to merge 1 commit intoTuringLang:mainfrom
hardik-xi11:docs-ssm-integration

Conversation

@hardik-xi11
Copy link

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

Copy link
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

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.

@hardik-xi11
Copy link
Author

Yess i get that so should I first work on writing up the documentation by adding a new page like this usage/external-likelihoods/index.qmd instead of the current changes i pushed.

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

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.

Integrate SSMProblems & GeneralisedFilters with Turing.jl

2 participants