Skip to content

Reference and Target Densities

Index

Types

TransportMaps.MapTargetDensity Type
julia
MapTargetDensity

Wrapper for target density functions used in transport map optimization. Stores the log-density function and its gradient, with support for automatic differentiation backends via DifferentiationInterface.jl.

Fields

  • logdensity<:Function: Function computing log-density log π(x)

  • ad_backend<:Union{Nothing,ADTypes.AbstractADType}: AD backend or nothing for analytical

  • grad_logdensity<:Function: Function computing gradient ∇ log π(x)

  • prepared_gradient: Optional prepared gradient for performance (can be nothing)

Constructors

  • MapTargetDensity(logdensity, grad_logdensity): Provide both log-density and analytical gradient.

  • MapTargetDensity(logdensity, backend::ADTypes.AbstractADType, d::Int): Use AD backend with prepared gradient.

  • MapTargetDensity(logdensity, backend::ADTypes.AbstractADType): Use AD backend without preparation.

  • MapTargetDensity(logdensity): Use ForwardDiff.

Examples

julia
# Use ForwardDiff (default, not prepared)
density = MapTargetDensity(logπ)

# Use ForwardDiff with prepared gradient (faster for repeated evaluations)
density = MapTargetDensity(logπ, AutoForwardDiff(), d)

# Use Mooncake with preparation
density = MapTargetDensity(logπ, AutoMooncake(), d)

# Use FiniteDiff
density = MapTargetDensity(logπ, AutoFiniteDiff(), d)

# Use analytical gradient
density = MapTargetDensity(logπ, grad_logπ)
source
TransportMaps.MapReferenceDensity Type
julia
MapReferenceDensity

Wrapper for reference density (typically standard Gaussian) used in transport maps. The reference density defines the space from which samples are drawn and mapped to the target distribution.

Fields

  • logdensity<:Function: Function computing log-density log ρ(z)

  • ad_backend<:ADTypes.AbstractADType: AD backend for gradient computation

  • grad_logdensity<:Function: Function computing gradient ∇ log ρ(z)

  • densitytype::Distributions.UnivariateDistribution: Univariate density type (e.g., Normal())

  • prepared_gradient: Prepared gradient for performance (can be nothing)

Constructors

  • MapReferenceDensity(): Use standard normal with ForwardDiff (default, not prepared).

  • MapReferenceDensity(densitytype): Specify distribution with ForwardDiff (not prepared).

  • MapReferenceDensity(densitytype, backend): Specify distribution and AD backend (not prepared).

  • MapReferenceDensity(densitytype, backend, d): Specify distribution, AD backend, and dimension (prepared, recommended for performance).

source

Functions

Distributions.pdf Function
julia
pdf(density::AbstractMapDensity, x)

Evaluate the probability density at point(s) x.

Arguments

  • density::AbstractMapDensity: Target or reference density

  • x: Point (vector) or multiple points (matrix, rows are samples) at which to evaluate

Returns

  • Scalar density value for vector input, or vector of densities for matrix input

Note

This computes exp(logpdf(density, x)). For numerical stability, prefer using logpdf when possible.

source
Distributions.logpdf Function
julia
logpdf(density::AbstractMapDensity, x)

Evaluate the log-density at point(s) x.

Arguments

  • density::AbstractMapDensity: Target or reference density

  • x: Point (vector) or multiple points (matrix, rows are samples) at which to evaluate

Returns

  • Scalar log-density value for vector input, or vector of log-densities for matrix input
source
TransportMaps.grad_logpdf Function
julia
grad_logpdf(density::AbstractMapDensity, x)

Evaluate the gradient of log-density at point(s) x.

Arguments

  • density::AbstractMapDensity: Target or reference density

  • x: Point (vector) or multiple points (matrix, rows are samples) at which to evaluate

Returns

  • Gradient vector for vector input, or matrix of gradients (one per row) for matrix input
source