using Turing
myloglikelihood(x, μ) = loglikelihood(Normal(μ, 1), x)
@model function demo(x)
~ Normal()
μ @addlogprob! myloglikelihood(x, μ)
end
demo (generic function with 2 methods)
Turing accumulates log probabilities internally in an internal data structure that is accessible through the internal variable __varinfo__
inside of the model definition. To avoid users having to deal with internal data structures, Turing provides the @addlogprob!
macro which increases the accumulated log probability. For instance, this allows you to include arbitrary terms in the likelihood
demo (generic function with 2 methods)
and to force a sampler to reject a sample:
demo (generic function with 2 methods)
Note that @addlogprob! (p::Float64)
adds p
to the log likelihood. If instead you want to add to the log prior, you can use