Nucleide

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:

ww[ve][g]={null_valueif rel_error[ve][g]>toleranceϕ[ve][g]2 max⁡ve′ϕ[ve′][g]otherwise\text{ww}[ve][g] = \begin{cases} \text{null\_value} & \text{if rel\_error}[ve][g] > \text{tolerance} \\ \dfrac{\phi[ve][g]}{2 \, \max_{ve'} \phi[ve'][g]} & \text{otherwise} \end{cases}

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 [0,1)[0, 1), it returns a bin index in O(1)O(1) 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 {0,0.2,0.4,10}\{0, 0.2, 0.4, 10\} 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