pub struct DiscreteGaussianIntegerSampler {
pub center: Q,
pub s: Q,
pub lower_bound: Z,
pub interval_size: Z,
pub lookup_table_setting: LookupTableSetting,
pub table: HashMap<Z, f64>,
pub rng: SamplerRng,
}Expand description
Enables for discrete Gaussian sampling out of
[⌈center - s * tailcut⌉ , ⌊center + s * tailcut⌋ ].
WARNING: If the attributes are not set using DiscreteGaussianIntegerSampler::init,
we can’t guarantee sampling from the correct discrete Gaussian distribution.
Altering any value will invalidate the HashMap in table and might invalidate
other attributes, too.
Attributes:
center: specifies the position of the center with peak probabilitys: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = slower_bound: specifies the lower bound to sample uniformly frominterval_size: specifies the interval size to sample uniformly fromlookup_table_setting: Specifies whether a lookup-table should be used and how it should be filled, i.e. lazily on-the-fly (impacting sampling time slightly) or precomputedtable: the lookup-table if one is usedrng: defines theThreadRngor seededStdRngthat’s used for sampling.
§Examples
use qfall_math::utils::sample::discrete_gauss::{DiscreteGaussianIntegerSampler, LookupTableSetting};
let center = 0.0;
let gaussian_parameter = 1.0;
let tailcut = 6.0;
let mut dgis = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::NoLookup, None).unwrap();
let sample = dgis.sample_z();Fields§
§center: Q§s: Q§lower_bound: Z§interval_size: Z§lookup_table_setting: LookupTableSetting§table: HashMap<Z, f64>§rng: SamplerRngImplementations§
Source§impl DiscreteGaussianIntegerSampler
impl DiscreteGaussianIntegerSampler
Sourcepub fn init(
center: impl Into<Q>,
s: impl Into<Q>,
tailcut: impl Into<Q>,
lookup_table_setting: LookupTableSetting,
seed: Option<[u8; 32]>,
) -> Result<Self, MathError>
pub fn init( center: impl Into<Q>, s: impl Into<Q>, tailcut: impl Into<Q>, lookup_table_setting: LookupTableSetting, seed: Option<[u8; 32]>, ) -> Result<Self, MathError>
Initializes the DiscreteGaussianIntegerSampler with
centeras the center of the discrete Gaussian to sample from,sdefining the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = s,lower_boundas⌈center - 6 * s⌉,interval_sizeas⌊center + 6 * s⌋ - ⌈center - 6 * s⌉ + 1, andtableas an emptyHashMapto store evaluations of the Gaussian function, andrngas aStdRngseeded withseedifseedis provided, and as a freshThreadRngotherwise.
Parameters:
center: as the center of the discrete Gaussian to sample froms: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = stailcut: specifies the number of Gaussian parameterssthe interval to sample from reaches fromcenterto both sideslookup_table_setting: specifies whether a lookup-table should be used and how it should be filledseed: specifies an optional 256-bit seed for the internalStdRng. IfNoneis provided, a freshThreadRngis used instead.
Returns a DiscreteGaussianIntegerSampler or a MathError
if the specified parameters were not chosen appropriately,
i.e. tailcut < 0 or s < 0.
§Examples
use qfall_math::utils::sample::discrete_gauss::{DiscreteGaussianIntegerSampler, LookupTableSetting};
let center = 0.0;
let gaussian_parameter = 1.0;
let tailcut = 6.0;
let dgis = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::Precompute, None).unwrap();
let mut dgis_seeded_0 = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::Precompute, Some([42; 32])).unwrap();
let mut dgis_seeded_1 = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::Precompute, Some([42; 32])).unwrap();
assert_eq!(dgis_seeded_0.sample_z(), dgis_seeded_1.sample_z());§Errors and Failures
- Returns a
MathErrorof typeInvalidIntegerInputiftailcut < 0ors < 0.
Sourcepub fn sample_z(&mut self) -> Z
pub fn sample_z(&mut self) -> Z
Chooses a sample according to the discrete Gaussian distribution out of
[lower_bound , lower_bound + interval_size ].
This function implements discrete Gaussian sampling according to the definition of SampleZ as in [1].
§Examples
use qfall_math::utils::sample::discrete_gauss::{DiscreteGaussianIntegerSampler, LookupTableSetting};
let center = 0.0;
let gaussian_parameter = 1.0;
let tailcut = 6.0;
let mut dgis = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::Precompute, None).unwrap();
let sample = dgis.sample_z();