Skip to content

Prior sampler should use PriorContext, not DefaultContext #2169

@torfjelde

Description

@torfjelde

Example Thanasi Bakis in Slack:

using Turing

function loglik(θ, x)
    println("In loglik")
    
    return logpdf(Normal(θ, 1), x)
end

@model function test(x)
    θ ~ Normal(0, 1)

    if DynamicPPL.leafcontext(__context__) !== Turing.PriorContext()
        println(DynamicPPL.leafcontext(__context__))
        Turing.@addlogprob! sum(loglik.(θ, x))
    end
end

sample(test(randn(100) * 1000), Prior(), 100)

results in DefaultContext rather than PriorContext.

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