Variance reduction
Generate MAGIC weight windows and sample source voxels with alias tables.
The vr-tools crate provides variance-reduction tools used with MCNP
mesh tallies and caller particle data: MAGIC weight-window generation,
Walker/Vose alias-table source sampling, and Gaussian KDE source
resampling.
MAGIC weight windows
Given a mesh tally, MAGIC produces lower weight-window bounds:
You can run it on energy-integrated totals or per energy group. After generating bounds, the energy upper-bound structure is plotted as a step line on a logarithmic energy axis.
Alias-table sampling
AliasTable implements Walker’s method with Vose’s construction. Given a
non-negative PDF and two uniform random numbers in , it returns a bin
index in time. MeshSourceSampler applies this to a mesh tally,
supporting analog, uniform, and user-biased modes (the demo below
exposes the analog and uniform modes). Non-finite tally, tolerance,
null-value, or PDF entries are rejected with an inline error before any
computation runs.
KDE source resampling
KdeSampler fits an axis-aligned Gaussian KDE over caller-supplied
particle rows (for example projected MCPL fields) and deterministically
resamples with caller-supplied uniforms and normals — no RNG inside.
Three bandwidth rules mirror the Python kwargs: Silverman (one global
width per dimension, the default), fixed caller widths, and adaptive
per-sample kNN widths (k/scale, defaults 1/1.0). The demo below
fits the synthetic hand vector, highlights the
fitted bandwidths, evaluates the density curve, and draws a resampled
row. Zero-variance dimensions and duplicate-point zero distances raise
a clear error.
Loading the live demo…
See also
- Theory: Variance reduction
- Crate docs:
crates/vr-tools/src/lib.rs