Skip to content

Optimization of the Map Coefficients ​

A crucial step in constructing transport maps is the optimization of the map coefficients, which determine how well the map represents the target distribution. This process can be approached in two distinct ways, depending on the available information about the target distribution [3].

Map-from-density ​

One way to construct a transport map is to directly optimize its parameters based on the (unnormalized) target density, as shown in Banana: Map from Density. This approach requires access to the target density function and uses quadrature schemes to approximate integrals, as introduced in Quadrature Methods.

Formally, we define the following optimization problem to determine the coefficients of the parameterized map :

Here, is the unnormalized target density, as in the Introduction. contains all nonlinear coefficients by default, so constant and linear terms remain unpenalized. With interactions_only=true, instead contains only terms involving at least two coordinates. The L1 term uses the differentiable approximation , controlled by l1_eps.

As noted by [3], this optimization problem is generally non-convex. Log-concavity of the target yields convexity in suitable spaces of maps, but does not by itself guarantee convexity in the coefficients of a nonlinearly rectified polynomial map. Bayesian posteriors may be log-concave or non-log-concave. See [4] for the role of the map representation in optimization.

Map optimization uses Optim.jl, which supports a range of optimizers and options, including convergence criteria and trace output. Specifically, we can pass our optimize! function the desired optimizer and options. For a full overview of available options, see the Optim.jl configuration documentation.

To perform the optimization of the map coefficients, we call:

julia
optimize!(M::PolynomialMap, target::AbstractMapDensity, quadrature::AbstractQuadratureWeights;
  optimizer::Optim.AbstractOptimizer = LBFGS(), options::Optim.Options = Optim.Options(),
  λ1::Real = 0, λ2::Real = 0, l1_eps::Real = 1e-8,
  interactions_only::Bool = false)

Provide the polynomial map M, a MapTargetDensity wrapping the target log-density, and a quadrature scheme for the reference distribution. Optionally, we can specify the optimizer, its options, and L1 or L2 regularization. For example, λ1=1e-3 shrinks every nonlinear term, while combining it with interactions_only=true shrinks only mixed-coordinate terms. These keywords are also available for density-based optimize_adaptive_transportmap calls.

Set initial coefficients

As the starting point of the optimization, the map coefficients can be set using setcoefficients!(M, coeffs), where coeffs is a vector of coefficients.

Usage ​

First we load the packages:

julia
using TransportMaps
using Optim
using Distributions

Then, define the target density and quadrature scheme. Here, we use the same banana-shaped density as in Banana: Map from Density:

julia
logtarget(x) = logpdf(Normal(), x[1]) + logpdf(Normal(), x[2] - x[1]^2)
target = MapTargetDensity(logtarget)
M_gd = PolynomialMap(2, 2)
quadrature = GaussHermiteWeights(3, M_gd)

Store the trace for the convergence comparison below:

julia
opts_trace = Optim.Options(iterations = 200, store_trace = true)

We will try the following optimizers from Optim.jl, ordered from simplest to most sophisticated:

Gradient Descent ​

The most basic optimization algorithm, Gradient Descent iteratively moves in the direction of the negative gradient. It is simple and robust, but can be slow to converge, especially for ill-conditioned problems.

julia
res_gd = optimize!(M_gd, target, quadrature; optimizer = GradientDescent(), options = opts_trace)
┌ Warning: Optimization has not converged.
└ @ TransportMaps ~/work/TransportMaps.jl/TransportMaps.jl/src/optimization/mapfromdensity.jl:300

Conjugate Gradient ​

Conjugate Gradient improves upon basic gradient descent by using conjugate directions, which can accelerate convergence for large-scale or quadratic problems. It requires gradient information but not the Hessian.

julia
M_cg = PolynomialMap(2, 2)
res_cg = optimize!(M_cg, target, quadrature; optimizer = ConjugateGradient(), options = opts_trace)

Nelder-Mead ​

Nelder-Mead is a derivative-free optimizer that uses a simplex of points to search for the minimum. It is useful when gradients are unavailable or unreliable, but may be less efficient for high-dimensional or smooth problems.

julia
M_nm = PolynomialMap(2, 2)
res_nm = optimize!(M_nm, target, quadrature; optimizer = NelderMead(), options = opts_trace)
┌ Warning: Optimization has not converged.
└ @ TransportMaps ~/work/TransportMaps.jl/TransportMaps.jl/src/optimization/mapfromdensity.jl:300

BFGS ​

BFGS is a quasi-Newton method that builds up an approximation to the Hessian matrix using gradient evaluations. It is generally faster and more robust than gradient descent and conjugate gradient for smooth problems.

julia
M_bfgs = PolynomialMap(2, 2)
res_bfgs = optimize!(M_bfgs, target, quadrature; optimizer = BFGS(), options = opts_trace)

LBFGS ​

LBFGS is a limited-memory version of BFGS, making it suitable for large-scale problems where storing the full Hessian approximation is impractical. It is the default optimizer in many scientific computing packages due to its efficiency and reliability.

julia
M_lbfgs = PolynomialMap(2, 2)
res_lbfgs = optimize!(M_lbfgs, target, quadrature; optimizer = LBFGS(), options = opts_trace)

Compare map quality on the same reference samples. The other optimizer results use the same diagnostic:

julia
samples_z = randn(1000, 2)
v_lbfgs = variance_diagnostic(M_lbfgs, target, samples_z)
0.00042625773522699217

We can visualize the convergence of all optimizers: Optimization ConvergenceOptimization Convergence

It becomes clear, that LBFGS and BFGS are the most efficient optimizers in this case, while Nelder-Mead struggles to keep up.

Map-from-samples ​

Another strategy of constructing a transport map is to use samples of the target density, as seen in Banana: Map from Samples. A log-concave reference gives a convex objective in the monotone map itself [3]. The integrated rectification used here depends nonlinearly on the coefficients, so this does not establish convexity of the finite-dimensional coefficient problem [4].

When the map is constructed from samples, the optimization problem is formulated by minimizing    and approximating the target expectation with a sample average, as derived in the Introduction. We denote the transport map by , which pushes forward the target distribution to the reference distribution. This leads to the following optimization problem:

where are samples from the target distribution, and   is the density of the reference distribution.

To perform the optimization, we can use the same optimize! function as before, but now we pass samples instead of a target density and quadrature scheme. Similarly, we can specify the optimizer and options:

julia
optimize!(M::PolynomialMap, samples::AbstractArray{<:Real};
  optimizer::Optim.AbstractOptimizer = LBFGS(), options::Optim.Options = Optim.Options())

This page was generated using Literate.jl.