Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…e `UQTargetDensity` struct
89e7b01 to
4225122
Compare
AnderGray
requested changes
Mar 27, 2026
Contributor
AnderGray
left a comment
There was a problem hiding this comment.
Very extensive and very well written, with great documentation and tests. This is awesome.
I may have found a couple of things:
- Is the
AutoMooncake()option working as intended? When I try it in your example, the code errors. - I don't know if it's only because it's in development mode, but some of docs/transportmaps hasn't rendered properly, in particular I'm seeing some unrendered math, and some loose bullet points.
- You compute the mode of the transport map is the mapping of the zero in standard normal space. Is that always correct? It may be a good approximation in many cases, but I am finding examples where it is not the actual mode. Below is a simple example.
using UncertaintyQuantification
using Distributions
using ForwardDiff
using Plots
# Smooth target on all of R: skewed Gaussian mixture
dist = MixtureModel(
[Normal(-1.0, 0.7), Normal(1.2, 0.9)],
[0.75, 0.25],
)
# TransportMaps expects vector input even in 1D
logq(x::AbstractVector) = logpdf(dist, x[1])
dlogq(x::AbstractVector) = ForwardDiff.gradient(y -> logpdf(dist, y[1]), x)
target = MapTargetDensity(logq, dlogq)
# Learn a 1D transport map
M = PolynomialMap(1, 8, Normal(), Softplus())
quadrature = GaussHermiteWeights(35, 1)
tm_opt = mapfromdensity(M, target, quadrature, [:x1])
x_mode_tm = UncertaintyQuantification.mode(tm_opt.d)
# ------------------------------------------------------------
# Plot TM density and mode
xs = range(-4.0, 4.0, length=1000)
tm_pdf = [pdf(tm_opt, [x]) for x in xs]
plot(xs, tm_pdf, label="Transport map", lw=2)
vline!([x_mode_tm], label="TM mode", linestyle=:dashdot)
In this example, the reported mode does not appear to coincide with the mode of the learned transport-map density.
Member
Author
|
Thanks for the review @AnderGray!
|
Member
Author
|
This is the example again with using UncertaintyQuantification
using Distributions
using ForwardDiff
using Plots
# Smooth target on all of R: skewed Gaussian mixture
dist = MixtureModel(
[Normal(-1.0, 0.7), Normal(1.2, 0.9)],
[0.75, 0.25],
)
# TransportMaps expects vector input even in 1D
logq(x::AbstractVector) = logpdf(dist, x[1])
dlogq(x::AbstractVector) = ForwardDiff.gradient(y -> logpdf(dist, y[1]), x)
target = MapTargetDensity(logq, dlogq)
# Learn a 1D transport map
M = PolynomialMap(1, 8, Normal(), Softplus())
quadrature = GaussHermiteWeights(35, 1)
tm_opt = mapfromdensity(M, target, quadrature, [:x1])
x_mean_tm = median(tm_opt.d)
x_med_ana = median(dist)
# ------------------------------------------------------------
# Plot TM density and mode
xs = range(-4.0, 4.0, length=1000)
tm_pdf = [pdf(tm_opt, [x]) for x in xs]
mix_pdf = [pdf(dist, x) for x in xs]
plot(xs, tm_pdf, label="Transport map", lw=2)
plot!(xs, mix_pdf, label="Traget pdf", lw=2, ls=:dash)
vline!([x_mean_tm], label="Median TM", linestyle=:dashdot)
vline!([x_med_ana], label="Median", linestyle=:dashdot) |
AnderGray
approved these changes
Mar 31, 2026
Contributor
AnderGray
left a comment
There was a problem hiding this comment.
Great stuff ! Thanks for your changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR adds triangular transport maps (TMs) using
TransportMaps.jlas the backend.Transport Maps are added in
inputsas a subtype ofMultivariateDistribution, making them compatible with theJointDistributioninterface. There are two different types added:TransportMapwhich are constructed as a mapping from a target density in the physical space to a standard normal densityTransportMapFromSampleswhich are constructed starting with samples of the target density and map those to the standard normal space.Also, TMs are used for model updating with the
bayesianupdatingfunction.There,
TransportMapBayesianwraps all the different objects and options of the map construction which is passed to thebayesianupdatingfunction with a similar interface as for the sampling methods. The function returns the optimized map as aJointDistribution.This PR also adds extensive documentation, tests and a literate example for Bayesian updating with transport maps.