Skip to content

Contexts and acclogp! #154

@treigerm

Description

@treigerm

If one wants to use the acclogp! function to manually increment the log probability manually then this prevents the use of PriorContext or LikelihoodContext to compute the prior or likelihood, respectively. This is due to the fact that acclogp! does not dispatch on the current context so it always increments lp.

MWE:

using Turing

@model function model(y)
    x ~ Normal(0, 1)
    y ~ Normal(x, 1)
    Turing.acclogp!(_varinfo, 1.0)
end

xval = 1.0
yval = 3.0

m = model(yval)
vi = Turing.VarInfo(m)
vi[@varname(x)] = [xval;]

m(vi, Turing.SampleFromPrior(), Turing.PriorContext())
lp = Turing.getlogp(vi)

@show lp
@show logpdf(Normal(0, 1), xval)

Results in:

lp = -0.41893853320467267
logpdf(Normal(0, 1), xval) = -1.4189385332046727

Is this behaviour intended? Is there a known way to work around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions