Skip to content

Commit b9f5e4c

Browse files
author
Closed-Limelike-Curves
committed
Add Turing method for naive_lpd
1 parent bb20f52 commit b9f5e4c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/NaiveLPD.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Tullio
33

44

55
"""
6-
naive_lpd()
6+
naive_lpd(log_likelihood::AbstractArray{<:Real, 3})
77
88
Calculate the naive (in-sample) estimate of the expected log probability density, otherwise
99
known as the in-sample Bayes score. Not recommended for most uses.

src/TuringHelpers.jl

+12
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ function psis(model::DynamicPPL.Model, chain::Chains, args...; kwargs...)
8383
log_ratios = pointwise_log_likelihoods(model, chain)
8484
return psis(-log_ratios, args...; kwargs...)
8585
end
86+
87+
88+
"""
89+
naive_lpd(model::DynamicPPL.Model, chain::Chains, args...; kwargs...)
90+
91+
Calculate the naive (in-sample) estimate of the log probability density, otherwise
92+
known as the Bayes score. Not recommended for most uses.
93+
"""
94+
function naive_lpd(model::DynamicPPL.Model, chain::Chains, args...; kwargs...)
95+
log_ratios = pointwise_log_likelihoods(model, chain)
96+
return naive_lpd(log_ratios, args...; kwargs...)
97+
end

test/tests/TuringTests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ using Distributions, Random, MCMCChains, Turing
9292
psis_output = psis(model(data), chain; r_eff=r_eff)
9393
@test isa(psis_output, Psis)
9494

95+
@test ParetoSmooth.naive_lpd(model(data), chain)
96+
psis_loo_output.estimates(:naive_est, :total)
97+
9598
end

0 commit comments

Comments
 (0)