-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
Current log density definition:
using AdvancedHMC, AbstractMCMC
using LogDensityProblems, LogDensityProblemsAD, ADTypes # For defining the target distribution & its gradient
using ForwardDiff # An example AD backend
using Random # For initial parameters
# 1. Define the target distribution using the LogDensityProblems interface
struct LogTargetDensity
dim::Int
end
# Log density of a standard multivariate normal distribution
LogDensityProblems.logdensity(p::LogTargetDensity, θ) = -sum(abs2, θ) / 2
LogDensityProblems.dimension(p::LogTargetDensity) = p.dim
# Declare that the log density function is defined
function LogDensityProblems.capabilities(::Type{LogTargetDensity})
return LogDensityProblems.LogDensityOrder{0}()
end
# Set parameter dimensionality
D = 10
# 2. Wrap the log density function and specify the AD backend.
# This creates a callable struct that computes the log density and its gradient.
ℓπ = LogTargetDensity(D)
model = AdvancedHMC.LogDensityModel(LogDensityProblemsAD.ADgradient(AutoForwardDiff(), ℓπ))It could be replaced with a one-liner, e.g., via logpdf from Distributions.jl.
Metadata
Metadata
Assignees
Labels
No labels