-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I compute a likelyhood from a model? #228
Comments
Hi! Your model is specified in a different style. You don't need to pass the data as an argument to the model; think of the argument as simply allowing your So to write your Beta-Bernoulli model, you can let your argument be the number of observations: julia> m0 = @model N begin
a ~ Beta(1,1)
X ~ Bernoulli(a) |> iid(N)
end;
julia> rand(m0(N=3))
(a = 0.626776184502901, X = Bool[1, 1, 1]) Then, the (log) likelihood of julia> logpdf(m0(N=3), (a=0.5, X = [1, 1, 0],))
-2.0794415416798357 |
Hello Joey, thank you for the response. I still don't understand what's wrong with my first model. And the fact that
gives zero for ANY value of of Can you give me a bit more about how to think about this? Pointer to what I should read is of course welcome! Thank you and kind greetings, z. PS.: |
A model is a random generative process. An easy way to check a model is to see what code is generated for julia> sourceRand(m0)
:(_rng->begin
a = rand(_rng, Beta(1, 1))
N = length(X)
(N = N, a = a, X = X)
end)
julia> sourceLogpdf(m0)
quote
_ℓ = 0.0
_ℓ += logpdf(Beta(1, 1), a)
N = length(X)
return _ℓ
end Randomness of Compare with @millerjoey 's suggestion (I'll call it julia> sourceRand(m1)
:(_rng->begin
a = rand(_rng, Beta(1, 1))
X = rand(_rng, iid(N, Bernoulli(a)))
(a = a, X = X)
end)
julia> sourceLogpdf(m1)
quote
_ℓ = 0.0
_ℓ += logpdf(Beta(1, 1), a)
_ℓ += logpdf(Bernoulli(a) |> iid(N), X)
return _ℓ
end |
Thank you Chad, I will have a deeper look here. I still don't understand why
where
doesnt change the result of logpdf when I change N.
and
both give -2.0794415416798357 Kind greetings, z. |
Ahh, good catch. That's because the dimension is currently only used for generation, when there's no value known. The code for this is in function Distributions.logpdf(d::iid,x)
s = zero(Float64)
Δs(xj) = logpdf(d.dist, xj)
@inbounds @simd for j in eachindex(x)
s += Δs(x[j])
end
s
end |
Hi,
say I have a model
now, for
m0(X = [false, false, false, true, true])
, I want to compute the likelyhood witha = 0.5
, is there a Soss way to do that?(I see there is a method called likelihood, however, it returns a model, not a number.)
Thank you, z.
The text was updated successfully, but these errors were encountered: