Skip to content

Commit 0445092

Browse files
committed
Fix LogDensityAt struct
1 parent 2d11ad7 commit 0445092

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/logdensityfunction.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,18 @@ struct LogDensityAt{M<:Model,V<:AbstractVarInfo,C<:AbstractContext}
212212
end
213213
function (ld::LogDensityAt)(x::AbstractVector)
214214
varinfo_new = unflatten(ld.varinfo, x)
215-
return getlogp(last(evaluate!!(ld.model, varinfo_new, ld.context)))
215+
varinfo_eval = last(evaluate!!(ld.model, varinfo_new, ld.context))
216+
has_prior = hasacc(varinfo_eval, Val(:LogPrior))
217+
has_likelihood = hasacc(varinfo_eval, Val(:LogLikelihood))
218+
if has_prior && has_likelihood
219+
return getlogjoint(varinfo_eval)
220+
elseif has_prior
221+
return getlogprior(varinfo_eval)
222+
elseif has_likelihood
223+
return getloglikelihood(varinfo_eval)
224+
else
225+
error("LogDensityFunction: varinfo tracks neither log prior nor log likelihood")
226+
end
216227
end
217228

218229
### LogDensityProblems interface

0 commit comments

Comments
 (0)