Proposals

A proposal supplies normalized draws and their log density. Its support must cover the regions that contribute to the target integral.

Reading native proposal parameters

Native Gaussian, Student-t, Gamma, Laplace, and box proposals support Statistics.mean, var, std, and cov. Scalar proposals return scalar moments; vector proposals return marginal means, variances and standard deviations, and a covariance matrix. Independent and spherical covariances retain a Diagonal representation; correlated covariances are materialized. Array results preserve precision and device placement without implicit host transfers. Means and diagonal standard deviations can borrow proposal storage; treat returned parameters as read-only or explicitly copy them before mutation. Moments are computed at the proposal's precision. Unrepresentable covariance matrices can contain Inf or NaN from overflow; std or the stored scale factor can remain usable when a variance or covariance cannot be represented.

using ImportanceSamplers, Statisticsq = DiagonalGaussian(Float32[1, -1], Float32[2, 3])(mean(q), var(q), cov(q), proposal_scale_factor(q))
(Float32[1.0, -1.0], Float32[4.0, 9.0], Diagonal(Float32[4.0, 9.0]), Diagonal(Float32[2.0, 3.0]))

proposal_scale_factor reads a Gaussian or Student-t proposal's stored scale: a scalar for spherical proposals, a Diagonal wrapper for diagonal proposals, or the stored lower-triangular matrix for factor proposals. The result borrows storage without copying or transferring parameters. For Student-t proposals this is an elliptical scale factor, not a covariance factor.

current_proposal still returns an independent native snapshot, so its parameters remain unchanged when the prepared sampler runs again. No methods for ProductProposal or TransformedProposal are supplied: named block layouts need an explicit covariance convention, and nonlinear transformed moments are not the moments of the base proposal. Individual product blocks or an explicit transformed proposal's .base can be inspected in their own coordinates.

With Distributions.jl loaded, Normal(q) converts a scalar native Gaussian and MvNormal(q) converts a vector native Gaussian. These constructors require CPU parameters: transfer accelerator proposals explicitly first. Spherical and diagonal Gaussian representations are retained. Factor conversion copies the stored lower factor and materializes the covariance required by Distributions, without refactorization or inversion. Vector means may share storage with the native proposal and must be treated as read-only. Spherical and diagonal conversion rejects coordinate variances that underflow to zero or overflow, since their ecosystem representation requires positive finite covariance values.

Gaussian proposals

using ImportanceSamplers, PureRNGs, LinearAlgebrascalar = SphericalGaussian(0.0, 2.0)spherical = SphericalGaussian(zeros(3), 2.0)diagonal = DiagonalGaussian(zeros(3), [0.5, 1.0, 2.0])C = [1.0 0.6 0.0; 0.6 2.0 0.2; 0.0 0.2 1.0]correlated = FactorGaussian(zeros(3), cholesky(Symmetric(C)))draw, next_rng = rand_next(Threefry4x32(7), correlated)draw
3-element Vector{Float64}:
 -1.5216967556805618
  0.2554427459962002
  2.1287530249270175
ConstructorScale argumentGaussian covariance
SphericalGaussian(mu, sigma)Standard deviation$\sigma^2 I$
DiagonalGaussian(mu, scales)Marginal standard deviationsDiagonal(scales .^ 2)
FactorGaussian(mu, L)Lower factor or CholeskyL * L'

The spherical form accepts a scalar or a vector location. The diagonal and factor forms take vector locations.

Factor a covariance once. Do not pass the covariance itself as L. The implementation uses multiplication and triangular solves, not a covariance inverse.

Student-t proposals

proposal = FactorStudentT(    5.0, zeros(3),    cholesky(Symmetric(C)),)draw, next_rng = rand_next(Threefry4x32(7), proposal)draw
3-element Vector{Float64}:
 -1.4283032565420568
  0.23976505476824983
  1.9981017022785075

Student-t constructors follow the same layouts:

SphericalStudentT(nu, mu, sigma)DiagonalStudentT(nu, mu, scales)FactorStudentT(nu, mu, L)

The first argument is the positive degrees of freedom nu. The factors define a scale matrix $S$, not the covariance:

\[\operatorname{Cov}(X)=\frac{\nu}{\nu-2}S,\qquad \nu>2.\]

To obtain a desired covariance factor Lcov, use sqrt((nu - 2) / nu) * Lcov as the Student-t factor.

A multivariate Student-t draw uses one shared random radial scale. A diagonal scale therefore does not make its coordinates independent.

mean is the location when nu > 1 and otherwise returns shape-preserving NaN values. Finite covariance exists only for nu > 2. Following Distributions.jl conventions, scalar var and std are Inf for 1 < nu <= 2 and NaN for nu <= 1; multivariate var, std, and cov return shape-preserving NaN values whenever nu <= 2. These values retain the proposal's floating-point precision.

The adaptive methods keep nu fixed. AMIS, NPMC, CAIS, and FirstOrderGRAMIS require nu > 2 because they fit covariance. Location-only methods accept any finite nu > 0. None fits nu by maximum likelihood.

Uniform boxes

BoxUniform(lower, upper) defines a scalar interval or a product of coordinate intervals. Bounds must be finite, ordered, and have matching precision and shape. The proposal copies vector bounds and has constant density within the box.

box = BoxUniform([-2.0, 0.0], [2.0, 3.0])box_samples = importance_sample(    Threefry4x32(17), box, ImportanceSampling(box; nsamples=256),)extrema(box_samples.logweights)
(0.0, 0.0)

The target equals the normalized proposal, so every log weight is zero. Scalar bounds, such as BoxUniform(0.0, 1.0), produce scalar samples. Density evaluation includes the endpoints and returns -Inf outside the box. Intervals with a finite pair of bounds remain supported even when their width overflows the chosen floating-point type.

Plain IS and static MIS accept fixed boxes. Covariance-adaptive methods do not adapt their bounds. A box cannot cover an unbounded target. For overlapping or disjoint boxes, the MIS scheme determines whether support coverage is required from the complete mixture, each proposal, or each group.

Independent Gamma proposals

IndependentGamma(shape, scale) uses the shape–scale convention, not shape–rate. Scalar parameters define one Gamma variable. Matching vectors define independent coordinates with means shape .* scale and variances shape .* scale.^2.

gamma = IndependentGamma([0.5, 5.0], [2.0, 0.2])gamma_samples = importance_sample(    Threefry4x32(18), gamma, ImportanceSampling(gamma; nsamples=256),)extrema(gamma_samples.logweights)
(0.0, 0.0)

Parameters are fixed in plain IS and homogeneous static MIS banks. AMIS and N-PMC fit Gamma shapes and scales from weighted marginal means and variances. Direct Gamma proposals differ from exponentiated Gaussian proposals, especially near zero.

DM-PMC and APIS instead retain each configured coordinate variance v and update the mean m. They reconstruct shape = m^2/v and scale = v/m. Holding the constructor's Gamma scale fixed would not preserve variance. The target must have positive-coordinate support. Resampling near zero can produce tiny shapes and cause underflow in later draws, especially in Float32. These calls fail explicitly without clipping parameters or discarding samples.

gamma_bank = ProposalBank([    IndependentGamma([20.0, 30.0], [0.25, 0.25]),    IndependentGamma([24.0, 28.0], [0.25, 0.25]),])gamma_target = IndependentGamma([30.0, 36.0], [0.2, 0.2])gamma_prepared = prepare_sampler(Threefry4x32(20), gamma_target,    APIS(gamma_bank; rounds=3, round_size=1_024))importance_sample!(gamma_prepared)current_proposal(gamma_prepared)
ProposalBank{Vector{ImportanceSamplers._GammaProposal{Vector{Float64}, Float64}}, Vector{Float64}}(ImportanceSamplers._GammaProposal{Vector{Float64}, Float64}[ImportanceSamplers._GammaProposal{Vector{Float64}, Float64}([29.32458243511964, 27.560281707404428], [0.20646150468359306, 0.2608307618158812], [-22.715248544857104, -26.065932227610787], -48.78118077246789), ImportanceSamplers._GammaProposal{Vector{Float64}, Float64}([24.43920093466593, 28.720308526343686], [0.24774341995444435, 0.24684507907046851], [-18.895820376100666, -26.774616619939437], -45.6704369960401)], [0.5, 0.5])

Native sampling reserves eight rejection candidates per coordinate. Gamma random buffers occupy 17 * dimension * nsamples floating-point elements; packed MIS also retains a coordinate draw buffer. Exhaustion, underflow to zero, or a nonfinite draw fails the complete call. No sample is discarded or clipped. Very small shapes may therefore be unusable at a chosen precision.

Independent Laplace proposals

IndependentLaplace(location, scale) defines a scalar Laplace law or independent coordinates. Its mean is location and its coordinate variances are 2 .* scale.^2. Each coordinate uses one uniform draw, without rejection sampling.

laplace = IndependentLaplace([0.0, 1.0], [1.0, 0.5])prepared = prepare_sampler(Threefry4x32(19), laplace,    AMIS(laplace; rounds=3, round_size=1_000))laplace_samples = importance_sample!(prepared)current_proposal(prepared)
ImportanceSamplers._LaplaceProposal{Vector{Float64}, Float64}([-0.008742616759641681, 1.0092984932257867], [1.0041480179917293, 0.5045254937560986], -0.7062968920540914)

AMIS and N-PMC fit independent Gamma and Laplace proposals by marginal moment matching. Gamma uses shape = mean^2 / variance and scale = variance / mean. Laplace uses location = mean and scale = sqrt(variance / 2). These fits do not learn correlations and are not maximum-likelihood fits. Nonpositive variances or unrepresentable fitted parameters fail the call without replacing the last committed proposal. No parameter clipping or Gaussian ridge is applied.

DM-PMC, APIS and LAIS also accept independent Laplace populations. They update locations and preserve coordinate scales. APIS uses local weighted means, not weighted medians. LAIS moves locations through its upper MCMC transition.

Method compatibility

FamilyFixed IS/static MISAMIS/N-PMCDM-PMC/APISLAISCAIS/FirstOrderGRAMIS
Gaussian, Student-tYesYesYesYesYes
Box-uniformYesNoNoNoNo
Independent GammaYesMarginal moment fitsFixed coordinate varianceNoNo
Independent LaplaceYesMarginal moment fitsFixed coordinate scaleFixed coordinate scaleNo

Moving or shrinking boxes can remove target support, so boxes remain fixed. Independent vectors cannot represent the full covariance updates used by CAIS and FirstOrderGRAMIS. Unshifted Gamma is not the lower translation family used by LAIS.

Proposal populations

bank = ProposalBank([    SphericalGaussian([-2.0, 0.0, 0.0], 1.0),    SphericalGaussian([ 2.0, 0.0, 0.0], 1.5),], [1.0, 2.0])bank.masses
2-element Vector{Float64}:
 0.3333333333333333
 0.6666666666666666

ProposalBank copies the inputs and normalizes the masses. Omitting masses gives equal masses. Some adaptive methods require equal positive masses.

A bank is sampler configuration, not a distribution. It has no standalone rand or logdensityof method. The MIS scheme defines assignment and weighting.

Native banks use one scalar/vector layout, dimension, floating type, and proposal family. Mixed-family banks are not supported. Student-t components may have different degrees of freedom.

Precision

Native proposals support Float32 and Float64 and copy their input arrays. Use matching types for locations, scales, factors, and Student-t degrees of freedom.

Omitted bank masses use the proposals' precision for native and Distributions.jl inputs. Unknown generic proposals default to Float64 masses. Explicit masses retain their precision, so use single-precision masses for a wholly single-precision weighted bank:

bank32 = ProposalBank([    SphericalGaussian(Float32[-1, 0], 1f0),    SphericalGaussian(Float32[ 1, 0], 1f0),], Float32[1, 1])eltype(bank32.masses)
Float32

Masses participate in numerical promotion. A device changes precision only when you request that conversion explicitly. For boxes, independent Gamma, and independent Laplace, a precision change revalidates rounded parameters and rebuilds density constants on CPU. Choose precision before accelerator transfer. To change an already resident proposal's precision, explicitly return it to CPU first.

Distributions.jl interface

Loading Distributions.jl activates native conversion for Uniform, Gamma, Laplace, Normal, conventional MvNormal forms, TDist, Cauchy, and supported multivariate Student-t forms. Uniform remains fixed. Gamma and Laplace also work with the AMIS/N-PMC marginal moment fits described above.

using Distributions, ImportanceSamplersproposal = MvNormal(zeros(3), [1.0 0.6 0.0; 0.6 2.0 0.2; 0.0 0.2 1.0])algorithm = AMIS(proposal; rounds=4, round_size=2_000)

Other normalized distributions remain generic CPU proposals. They do not gain adaptive or GPU support merely by loading the extension.

A mixture distribution remains one atomic proposal. To expose its components to MIS, construct ProposalBank(components(mixture), probs(mixture)) explicitly.

Custom CPU proposals

Implement these two operations for the same normalized measure:

PureRNGs.rand_next(rng, proposal)DensityInterface.logdensityof(proposal, sample)

rand_next returns the draw and the continued RNG. A draw may be a scalar, vector, or named tuple of scalar/vector leaves. Every draw must keep the same structure, numeric types, and dimensions.

See Custom proposals and transitions for a complete example. Use transforms for constrained support.