diff --git a/src/DynamicPPL.jl b/src/DynamicPPL.jl index 9d870c9e8..de304fd28 100644 --- a/src/DynamicPPL.jl +++ b/src/DynamicPPL.jl @@ -115,8 +115,9 @@ export AbstractVarInfo, # Convenience functions logprior, logjoint, - pointwise_loglikelihoods, + pointwise_prior_logdensities, pointwise_logdensities, + pointwise_loglikelihoods, condition, decondition, fix, @@ -190,7 +191,6 @@ include("logdensityfunction.jl") include("model_utils.jl") include("extract_priors.jl") include("values_as_in_model.jl") -include("deprecated.jl") include("debug_utils.jl") using .DebugUtils diff --git a/src/deprecated.jl b/src/deprecated.jl deleted file mode 100644 index 09e1ac84d..000000000 --- a/src/deprecated.jl +++ /dev/null @@ -1,9 +0,0 @@ -# https://invenia.github.io/blog/2022/06/17/deprecating-in-julia/ - -Base.@deprecate pointwise_loglikelihoods(model::Model, chain, keytype) pointwise_logdensities( - model::Model, LikelihoodContext(), chain, keytype) - -Base.@deprecate pointwise_loglikelihoods( - model::Model, varinfo::AbstractVarInfo) pointwise_logdensities( - model::Model, varinfo, LikelihoodContext()) - diff --git a/src/pointwise_logdensities.jl b/src/pointwise_logdensities.jl index f045f9ae2..9faca254a 100644 --- a/src/pointwise_logdensities.jl +++ b/src/pointwise_logdensities.jl @@ -322,3 +322,62 @@ function pointwise_logdensities(model::Model, end + + +""" + pointwise_loglikelihoods(model, chain[, keytype, context]) +Compute the pointwise log-likelihoods of the model given the chain. +This is the same as `pointwise_logdensities(model, chain, context)`, but only +including the likelihood terms. +See also: [`pointwise_logdensities`](@ref). +""" +function pointwise_loglikelihoods( + model::Model, + chain, + keytype::Type{T}=String, + context::AbstractContext=LikelihoodContext(), +) where {T} + if !(leafcontext(context) isa LikelihoodContext) + throw(ArgumentError("Leaf context should be a LikelihoodContext")) + end + + return pointwise_logdensities(model, chain, T, context) +end + +function pointwise_loglikelihoods( + model::Model, varinfo::AbstractVarInfo, context::AbstractContext=LikelihoodContext() +) + if !(leafcontext(context) isa LikelihoodContext) + throw(ArgumentError("Leaf context should be a LikelihoodContext")) + end + + return pointwise_logdensities(model, varinfo, context) +end + +""" + pointwise_prior_logdensities(model, chain[, keytype, context]) +Compute the pointwise log-prior-densities of the model given the chain. +This is the same as `pointwise_logdensities(model, chain, context)`, but only +including the prior terms. +See also: [`pointwise_logdensities`](@ref). +""" +function pointwise_prior_logdensities( + model::Model, chain, keytype::Type{T}=String, context::AbstractContext=PriorContext() +) where {T} + if !(leafcontext(context) isa PriorContext) + throw(ArgumentError("Leaf context should be a PriorContext")) + end + + return pointwise_logdensities(model, chain, T, context) +end + +function pointwise_prior_logdensities( + model::Model, varinfo::AbstractVarInfo, context::AbstractContext=PriorContext() +) + if !(leafcontext(context) isa PriorContext) + throw(ArgumentError("Leaf context should be a PriorContext")) + end + + return pointwise_logdensities(model, varinfo, context) +end + diff --git a/test/deprecated.jl b/test/deprecated.jl deleted file mode 100644 index 322029ec8..000000000 --- a/test/deprecated.jl +++ /dev/null @@ -1,28 +0,0 @@ -@testset "loglikelihoods.jl" begin - @testset "$(m.f)" for m in DynamicPPL.TestUtils.DEMO_MODELS - example_values = DynamicPPL.TestUtils.rand_prior_true(m) - - # Instantiate a `VarInfo` with the example values. - vi = VarInfo(m) - for vn in DynamicPPL.TestUtils.varnames(m) - vi = DynamicPPL.setindex!!(vi, get(example_values, vn), vn) - end - - # Compute the pointwise loglikelihoods. - lls = pointwise_loglikelihoods(m, vi) - - #if isempty(lls) - if isempty(lls) - # One of the models with literal observations, so we just skip. - continue - end - - loglikelihood = sum(sum, values(lls)) - loglikelihood_true = DynamicPPL.TestUtils.loglikelihood_true(m, example_values...) - - #priors = - - @test loglikelihood ≈ loglikelihood_true - end -end - diff --git a/test/pointwise_logdensities.jl b/test/pointwise_logdensities.jl index d91416a1f..d53c194dc 100644 --- a/test/pointwise_logdensities.jl +++ b/test/pointwise_logdensities.jl @@ -27,7 +27,7 @@ logp_true = logprior(m, vi) # Compute the pointwise loglikelihoods. - lls = pointwise_logdensities(m, vi, likelihood_context) + lls = pointwise_loglikelihoods(m, vi) #lls2 = pointwise_loglikelihoods(m, vi) if isempty(lls) # One of the models with literal observations, so we just skip. @@ -38,7 +38,7 @@ end # Compute the pointwise logdensities of the priors. - lps_prior = pointwise_logdensities(m, vi, prior_context) + lps_prior = pointwise_prior_logdensities(m, vi) logp = sum(sum, values(lps_prior)) logp1 = getlogp(vi) @test !isfinite(logp_true) || logp ≈ logp_true @@ -56,6 +56,7 @@ end end + @testset "pointwise_logdensities chain" begin @model function demo(x, ::Type{TV}=Vector{Float64}) where {TV} s ~ InverseGamma(2, 3) diff --git a/test/runtests.jl b/test/runtests.jl index 3632879f5..c78e8f941 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -60,8 +60,6 @@ include("test_util.jl") include("pointwise_logdensities.jl") include("lkj.jl") - - include("deprecated.jl") end @testset "compat" begin