Proposals and transforms

Proposals explains scale conventions. Constraints and named parameters explains coordinates and Jacobian adjustments.

Native families

ImportanceSamplers.FactorGaussian — Function
FactorGaussian(location, factor)

Construct a normalized vector Gaussian proposal with affine map x = location + L * z, where z is standard normal and L is a finite lower-triangular factor with positive diagonal. A Cholesky factorization is accepted through its lower factor. The covariance is L * L'; pass a factor, not an inverse covariance. Density evaluation uses triangular solves and never forms a covariance inverse.

See FactorStudentT for heavier tails and BatchedFactorExecution for matrix-based draws and densities in ImportanceSampling.

source
ImportanceSamplers.BoxUniform — Function
BoxUniform(lower, upper)

Normalized uniform proposal on a scalar interval or an independent vector box. Bounds must be finite Float32 or Float64 values of matching precision and shape, with lower < upper in every coordinate. Vector inputs are copied. Density evaluation includes the endpoints and returns -Inf outside the box. Finite intervals with an overflowing upper - lower remain supported.

The proposal is fixed. It does not use Gaussian covariance adaptation.

source
ImportanceSamplers.IndependentGamma — Function
IndependentGamma(shape, scale)

Normalized Gamma proposal with shape–scale parameters, or a product of independent Gamma coordinates. Parameters must be finite, strictly positive, matching Float32 or Float64 scalars or vectors. Vector inputs are copied. The mean is shape .* scale and variance is shape .* scale.^2.

Plain IS and homogeneous static MIS banks use fixed parameters. AMIS and NPMC fit weighted marginal moments, then use shape = mean^2 / variance and scale = variance / mean. This is moment matching, not maximum likelihood. Correlations are not fitted. Degenerate or unrepresentable fits fail without replacing the committed proposal. APIS and DeterministicMixturePMC instead update each mean at fixed coordinate variance, changing both shape and scale. Gamma proposals require a target supported on positive coordinates. Adaptation can produce tiny shapes whose draws underflow at the chosen precision. Native execution uses eight rejection candidates per coordinate. Exhaustion or a nonpositive/nonfinite rounded draw fails the entire call, without discarding selected samples.

source
ImportanceSamplers.IndependentLaplace — Function
IndependentLaplace(location, scale)

Normalized scalar Laplace proposal, or a product of independent Laplace coordinates. Parameters must be finite, matching Float32 or Float64 scalars or vectors, with strictly positive scales. Vector inputs are copied. The mean is location and coordinate variances are 2 .* scale.^2.

Plain IS and homogeneous static MIS banks use fixed parameters. AMIS and NPMC fit the weighted marginal mean and sqrt(variance / 2). This is moment matching, not the weighted-median/absolute-deviation maximum likelihood fit. Correlations are not fitted. Invalid fits fail without replacing the committed proposal. Each coordinate uses one uniform draw. A nonfinite rounded affine draw fails the call without redrawing. APIS, DeterministicMixturePMC, and LAIS update locations while retaining each coordinate scale.

source
ImportanceSamplers.proposal_scale_factor — Function
proposal_scale_factor(proposal)

Return the stored scale factor of a native Gaussian or Student-t proposal: a scalar for spherical proposals, a Diagonal wrapper for diagonal proposals, or the stored lower-triangular matrix for factor proposals. For a Student-t law this is an elliptical scale factor, not a covariance factor.

The result borrows the proposal's storage. Treat it as read-only, and copy it explicitly if independent mutable storage is needed. No parameters are copied, converted in precision, or transferred between devices. An independent current_proposal snapshot owns its parameters independently of the sampler and remains valid across subsequent sampling calls.

source

Composition and populations

ImportanceSamplers.AbstractProposalPopulation — Type
AbstractProposalPopulation

Abstract supertype for explicit populations of normalized proposals.

Population values are sampler configuration, not probability distributions. Concrete subtypes describe proposals that assignment and denominator schemes can use separately during preparation.

source
ImportanceSamplers.ProposalBank — Type
ProposalBank(proposals)
ProposalBank(proposals, masses)

Construct an explicit proposal population with copied proposals and normalized nonnegative masses. Omitted masses are equal and use the promoted precision of native proposals or Distributions.jl inputs; unknown generic proposals use Float64. Explicit masses keep their existing promotion rules. The readable proposals and masses fields preserve input order; masses sum to one. A configured positive mass must remain positive through floating conversion and normalization; otherwise construction rejects the bank instead of making that proposal inert.

Zero-mass proposals remain in the configuration and retain their stable one-based IDs, but are neither assigned nor evaluated. Positive-mass proposals must share a sample dimension. Generic CPU execution additionally requires one concrete proposal element type. Homogeneous native Gaussian, Student-t, BoxUniform, IndependentGamma, and IndependentLaplace banks with one scalar/vector layout and floating type may be packed during preparation. Loading Distributions.jl converts supported entries to their native forms during construction.

ProposalBank deliberately implements neither rand nor DensityInterface.logdensityof: a bank is a proposal population, not a mixture distribution. AbstractMISScheme independently selects both the assignment law and the density used in each MIS denominator. A pre-existing mixture object remains one atomic proposal unless its components are explicitly placed in a bank.

source
ImportanceSamplers.ProductProposal — Type
ProductProposal(blocks::NamedTuple)

Construct a proposal for the product of independent named proposal blocks. Blocks are drawn in field order with the supplied RNG, and their normalized log densities are summed. Plain and static MIS support native preparation of same-precision Gaussian blocks, preserving names, scalar/vector shapes, and within-block covariance. Diagonal products use native CPU execution. Correlated products retain blockwise generic CPU execution where available and become dense native proposals on explicit accelerator transfer. Heterogeneous banks without a generic CPU route use native packing. Supported named transforms also follow these paths. Other products remain CPU-only. PureRNGs.rand_next uses the original blocks. Named LogDensityProblems targets retain the generic CPU path; use a callable target to prepare a native named sampler.

source
ImportanceSamplers.TransformedProposal — Type
TransformedProposal(base, transform)

Construct a proposal that maps draws from base into logical values through transform. Its density uses the exact normalized change of variables log q_x(x) = log q_z(z) - log|J(z)|. The proposal applies this Jacobian; target densities must use the resulting logical reference measure without applying it again.

For named flat layouts, bare indices or ranges mean identity transforms, for example (rate=1=>PositiveTransform(), offsets=2:3). Every coordinate still requires a named selector.

source

Coordinate transforms

ImportanceSamplers.AbstractSampleTransform — Type
AbstractSampleTransform

Abstract supertype for transforms from unconstrained coordinates to a logical sample value. A TransformedProposal subtracts the forward log Jacobian from its base proposal density. A sampler's transform= adds it to the logical target composed with the transform. Apply each change of variables once.

source
ImportanceSamplers.IdentityTransform — Type
IdentityTransform()

Leave an unconstrained scalar or vector unchanged with zero log Jacobian. A named product layout inserts this transform for omitted known fields.

source
ImportanceSamplers.PositiveTransform — Type
PositiveTransform()

Map an unconstrained scalar z to exp(z) on the positive real line, with forward log Jacobian z. With a Gaussian base, this induces a lognormal upper tail, versus the Gaussian-like upper tail from SoftplusTransform. Proposal tails must cover target tails for stable importance weights; neither transform alone guarantees finite weight variance. Both Gaussian-based transforms can still be too light near zero for targets with substantial boundary mass.

source
ImportanceSamplers.SoftplusTransform — Type
SoftplusTransform()

Map an unconstrained scalar smoothly to the positive real line with softplus and its stable forward log Jacobian. With a Gaussian base, this induces a Gaussian-like upper tail, lighter than the lognormal upper tail from PositiveTransform. Proposal tails must cover target tails for stable importance weights; neither transform alone guarantees finite weight variance. Both Gaussian-based transforms can still be too light near zero for targets with substantial boundary mass.

source
ImportanceSamplers.IntervalTransform — Type
IntervalTransform(lower, upper)

Construct a scalar transform onto the open interval defined by finite Float32 or Float64 endpoints. Use nothing for the unbounded endpoint; at least one endpoint is required. (lower, nothing), (nothing, upper), and (lower, upper) represent lower-bounded, upper-bounded, and bounded support.

source
ImportanceSamplers.SimplexTransform — Type
SimplexTransform(K)

Transform K - 1 unconstrained coordinates into K positive weights that sum to one. The coordinates use an orthonormal embedding into the sum-zero logit subspace. The forward Jacobian is measured against the first K - 1 simplex coordinates, dx₁⋯dxₖ₋₁, and includes the full constant: log|J| = 0.5log(K) + sum(log, x).

source
ImportanceSamplers.QuadraticCoupling — Type
QuadraticCoupling(coefficients)

Map pairs by x[2j-1] = z[2j-1] and x[2j] = z[2j] + coefficients[j] * (z[2j-1]^2 - 1). The inverse subtracts the shift. The log absolute Jacobian determinant is zero. Coefficients are copied, must remain read-only, and must match the proposal precision. An unpaired final coordinate stays unchanged. Empty coefficients give the 1D identity. Supply floor(d/2) coefficients for an input vector of dimension d.

Pass transform= to prepare_sampler or importance_sample. Native samplers adapt in latent coordinates and return physical coordinates. Targets and explicit gradients use physical coordinates, including batch targets. CPU and accelerator execution need no per-sample host transfer.

See fit_transport and Fitted transport. This uses the additive map in Dinh et al., Section 3.2, not their neural-network training procedure or a general geometry fit.

source
ImportanceSamplers.fit_transport — Function
fit_transport(samples; scores=nothing, dof=5, ridge=1e-6, threaded=true)

Return a fitted (; proposal, transform) containing a latent FactorStudentT and a QuadraticCoupling, with CPU parameters. The weighted pilot must contain nonempty flat Float32/Float64 vectors. Inputs remain unchanged. Complete coordinate pairs are fitted and an unpaired final coordinate stays unchanged. Use a separate RNG and production sampler:

fit = fit_transport(pilot)production = importance_sample(rng, logtarget,    ImportanceSampling(fit.proposal; nsamples=100_000); transform=fit.transform)

The default fits weighted quadratic slopes with an intercept and a linear x_odd nuisance term. Linear dependence stays in the latent covariance. Optional scores fits the corresponding conditional-score surrogate. Supply finite ∇logtarget(x) values at the stored physical samples, matching their matrix shape, device, and precision. Scores need no Hessian and do not guarantee improvement.

Both fits match inverse-mapped weighted moments with fixed dof > 2. Add ridge * max(tr(covariance)/d, 1) to the covariance diagonal, then convert to Student-t scale. Undefined or ill-conditioned fits, nonnegative score slopes, and nonfinite parameters fail without clipping or an identity fallback.

Only fitted coefficients and moments return to CPU. Transfer the prepared sampler to the chosen device. threaded=false disables CPU workers, not accelerators. Production counts and methods stay independent of the pilot. Self-normalized estimates retain ratio bias. See Fitted transport.

source