Constraints and named parameters

Use transform= when the target has constrained or named parameters. The sampler works in flat numerical coordinates and presents logical parameters to the target.

Named constrained parameters

This target has three positive weights that sum to one, a positive rate, and a real offset.

using ImportanceSamplers, PureRNGs, Statisticslayout = (    weights=(1:2 => SimplexTransform(3)),    rate=(3 => PositiveTransform()),    offset=(4 => IdentityTransform()),)function logtarget(theta, p)    value = -theta.rate - theta.offset^2 / 2    for i in eachindex(p.alpha)        value += (p.alpha[i] - 1) * log(theta.weights[i])    end    return valueendp = (; alpha=[2.0, 3.0, 4.0])algorithm = AMIS(    SphericalGaussian(zeros(4), 1.0);    rounds=3, round_size=2_000,)prepared = prepare_sampler(    Threefry4x32(42), logtarget, p, algorithm;    transform=layout,)samples = importance_sample!(prepared)mean(samples)
(weights = [0.22100525716528652, 0.3321734416919308, 0.44682130114278135], rate = 0.9819333077771915, offset = -0.026969405653486524)

The target receives a named tuple with weights, rate, and offset. The reference means are [2, 3, 4] / 9, one, and zero.

The proposal has four coordinates, although the logical sample contains five scalar values:

Numerical coordinatesLogical fieldTransform
1:2Three simplex weightsSimplexTransform(3)
3Positive ratePositiveTransform()
4Real offsetIdentityTransform()

An integer selector gives a scalar field. A range gives a vector field. A K-component simplex consumes K - 1 coordinates.

Sample structure

(    weights=size(samples.samples.weights),    rates=length(samples.samples.rate),    first=samples[1].sample,)
(weights = (3, 6000), rates = 6000, first = (weights = [0.07128458719257827, 0.20745183935546652, 0.7212635734519552], rate = 0.2750498111641814, offset = -0.6312397673331561))

Returned samples use logical coordinates. Weights and provenance remain aligned. A full Gaussian or Student-t factor can capture correlations between named fields. Names do not impose independence.

The flat selectors must cover every numerical coordinate exactly once. Use bare selectors for unconstrained fields, such as offset=4 or coefficients=5:8. These are equivalent to 4=>IdentityTransform() and 5:8=>IdentityTransform(). Every output field still has an explicit name. Omitting transform leaves the whole sample unchanged.

Scalar transforms

SupportConstructorMap
Real lineIdentityTransform()$z$
PositivePositiveTransform()$e^z$
PositiveSoftplusTransform()$\log(1+e^z)$
Above aIntervalTransform(a, nothing)$a+e^z$
Below bIntervalTransform(nothing, b)$b-e^z$
Between a and bIntervalTransform(a, b)Scaled logistic

Endpoints are excluded. For example, IntervalTransform(0.0, 10.0) maps into (0, 10).

Use bounds with the coordinate precision, such as IntervalTransform(0f0, 1f0). Nonfinite or rounded boundary values fail instead of being silently clipped.

For a Gaussian base, the exponential map gives a lognormal upper tail. Softplus gives a lighter, Gaussian-like upper tail. Neither choice guarantees finite importance-weight variance.

Target Jacobian

For a map $\theta=T(z)$, the sampler evaluates

\[\log\pi(T(z))+\log|\det J_T(z)|.\]

The target returns the log density in logical coordinates without this Jacobian.

current_proposal(prepared) returns the fitted proposal in numerical coordinates. Keep the layout when using that proposal in another sampler.

If another package already supplies an unconstrained target with its Jacobian, do not apply the transform again.

Proposal transforms

TransformedProposal applies the change of variables at the proposal boundary. For fixed IS with a constrained proposal:

proposal = TransformedProposal(    SphericalGaussian(0.0, 1.0),    PositiveTransform(),)positive = importance_sample(    Threefry4x32(9), x -> -x,    ImportanceSampling(proposal; nsamples=5_000),)mean(positive)
1.054403447460019

The target here is an unnormalized exponential density on the positive line. The proposal evaluates its normalized density with the inverse Jacobian. Do not also pass the same transformation through transform=.

For independent named blocks, combine ProductProposal and TransformedProposal:

structured = TransformedProposal(    ProductProposal((        scale=SphericalGaussian(0.0, 1.0),        offset=SphericalGaussian(0.0, 1.0),    )),    (scale=PositiveTransform(),),)draw, next_rng = rand_next(Threefry4x32(9), structured)draw
(scale = 1.8471970130362276, offset = 1.2964849622862424)

An omitted known product field uses identity. Here offset stays unconstrained. For flat layouts, omit the transform with a bare selector, not the field name or selector. A flat proposal has no field names to infer for omitted indices.

Gradients, devices, and the simplex measure

Native flat layouts work with adaptive methods and supported devices. Plain and static MIS also support same-precision Gaussian products with named outputs on accelerators. Correlated products keep blockwise CPU execution where available and become dense joint proposals during explicit device transfer. Generic products retain CPU execution. Use an explicit native flat layout for adaptive methods. Explicit named gradients differentiate the logical target. The package supplies the transform pullback and Jacobian derivative. See Gradients.

A simplex density uses the first-coordinate measure $dx_1\cdots dx_{K-1}$ with $x_K=1-\sum_{i<K}x_i$. The orthonormal-logit construction has forward log Jacobian

\[\log|J|=\tfrac12\log K+\sum_{i=1}^K\log x_i.\]

The constant matters for normalizers. It does not disappear from the proposal density. The simplex reproducer checks this measure against a normalized Dirichlet density.