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>,
}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 used
§Examples
use qfall_math::{integer::Z, rational::Q};
use qfall_math::utils::sample::discrete_gauss::{DiscreteGaussianIntegerSampler, LookupTableSetting};
let n = Z::from(1024);
let center = 0.0;
let gaussian_parameter = 1.0;
let tailcut = 6.0;
let mut dgis = DiscreteGaussianIntegerSampler::init(center, gaussian_parameter, tailcut, LookupTableSetting::NoLookup).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>Implementations§
Source§impl DiscreteGaussianIntegerSampler
impl DiscreteGaussianIntegerSampler
Sourcepub fn init(
center: impl Into<Q>,
s: impl Into<Q>,
tailcut: impl Into<Q>,
lookup_table_setting: LookupTableSetting,
) -> Result<Self, MathError>
pub fn init( center: impl Into<Q>, s: impl Into<Q>, tailcut: impl Into<Q>, lookup_table_setting: LookupTableSetting, ) -> 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.
Parameters:
n: specifies the range from which is sampledcenter: as the center of the discrete Gaussian to sample froms: specifies the Gaussian parameter, which is proportional to the standard deviationsigma * sqrt(2 * pi) = s
Returns a sample chosen according to the specified discrete Gaussian distribution or
a MathError if the specified parameters were not chosen appropriately,
i.e. n > 1 or s > 0.
§Examples
use qfall_math::{integer::Z, rational::Q};
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).unwrap();§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::{integer::Z, rational::Q};
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).unwrap();
let sample = dgis.sample_z();Trait Implementations§
Source§impl Clone for DiscreteGaussianIntegerSampler
impl Clone for DiscreteGaussianIntegerSampler
Source§fn clone(&self) -> DiscreteGaussianIntegerSampler
fn clone(&self) -> DiscreteGaussianIntegerSampler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more