This package contains common target distributions in Bayesian inference, with vectorised log-density and gradient evaluation supported.
target = Banana() # the banana distribution
x = randn(dim(target)) # size(x) is (2,)
@info logpdf(target, x) # -433.1
@info logpdf_grad(target, x) # (-433.1, [646.1, 129.8])
x = hcat(x, x) # size(x) is (2, 2)
@info logpdf(target, x) # [-433.1, -433.1]
@info logpdf_grad(target, x) # ([-433.1, -433.1], [646.1 646.1; 129.8 129.8])
All targets support logpdf_grad(target, x::VecOrMat)
, which returns a tuple of log-densities and their gradients.
The gradient in most cases (if I didn't hand-code them) is computed via ReverseDiff.jl, which compiles a tape for the gradient.
Thus, if you were to call the gradient multiple times, you can potentially save the compilation time by avoiding calling logpdf_grad
directly, but instead
gradfunc = gen_logpdf_grad(target, x)
gradfunc(x) # 1st time
gradfunc(x) # 2nd time
# ...
Also note that gen_logpdf_grad
still expects the second argument x::Union{AbstractVector, AbstractMatrix}
to correctly dispatch on vectorised mode or not.
-
Banana distribution
-
Multivariate diagonal Gaussian
-
Mixture of Gaussians
-
Spiral distribution
-
Logistic regression on the German credit dataset
-
Log-Gaussian Cox point process on the Finnish pine saplings dataset