Skip to content

Extension for MarginalLogDensities.jl #2421

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

torfjelde
Copy link
Member

This PR adds an extension for MarginalLogDensities.jl, allowing one to call marginalize on a Model, resulting in a MarginalLogDensity from MarginalLogDensities.jl.

Example:

julia> using Turing, MarginalLogDensities

julia> @model function demo()
           x ~ Normal(0, 1)
           y ~ Normal(x, 1)
       end
demo (generic function with 2 methods)

julia> model = demo();

julia> # Marginalize out `x`.
       marginalized = marginalize(model, [@varname(x)]);

julia> # Compute the marginal log-density of `y = 0.0`.
       abs(marginalized([0.0]) - logpdf(Normal(0, 2), 0.0)) < 1e-1
true

Ref: #2398

@torfjelde
Copy link
Member Author

A bit uncertain if we should export this marginalize or hide it for now.

@torfjelde
Copy link
Member Author

torfjelde commented Dec 5, 2024

Note that this will fail until ElOceanografo/MarginalLogDensities.jl#36 has made its way to the public (i.e. v0.3.6). Not entirely certain why this hasn't happened yet (it is in the registry 😕 )

EDIT: ElOceanografo/MarginalLogDensities.jl#36 (comment)

@torfjelde
Copy link
Member Author

We need TuringLang/DynamicPPL.jl#738 to go through before this will work 👍

@torfjelde
Copy link
Member Author

I'll have a look at this now; should be good now that the above PR has been merged 👍

@seabbs
Copy link

seabbs commented Jun 5, 2025

Found this after reading the recent Stan release and losing myself in a rabbit hole. This would be super handy for some modular fitting stuff as I think said elsewhere. What is the status? Anything aside from cheerleading to do?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants