DiscreteGaussianIntegerSampler

Struct DiscreteGaussianIntegerSampler 

Source
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 probability
  • s: specifies the Gaussian parameter, which is proportional to the standard deviation sigma * sqrt(2 * pi) = s
  • lower_bound: specifies the lower bound to sample uniformly from
  • interval_size: specifies the interval size to sample uniformly from
  • lookup_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 precomputed
  • table: 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

Source

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

  • center as the center of the discrete Gaussian to sample from,
  • s defining the Gaussian parameter, which is proportional to the standard deviation sigma * sqrt(2 * pi) = s,
  • lower_bound as ⌈center - 6 * s⌉,
  • interval_size as ⌊center + 6 * s⌋ - ⌈center - 6 * s⌉ + 1, and
  • table as an empty HashMap to store evaluations of the Gaussian function.

Parameters:

  • n: specifies the range from which is sampled
  • center: as the center of the discrete Gaussian to sample from
  • s: specifies the Gaussian parameter, which is proportional to the standard deviation sigma * 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
Source

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

Source§

fn clone(&self) -> DiscreteGaussianIntegerSampler

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DiscreteGaussianIntegerSampler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DiscreteGaussianIntegerSampler

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for DiscreteGaussianIntegerSampler

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,