[][src]Trait concrete_lib::operators::math::random::Random

pub trait Random: Sized {
    fn rng_uniform_n_msb(t: &mut [Self], n: usize);
fn rng_uniform_n_lsb(k: &mut [Self], n: usize);
fn rng_uniform(k: &mut [Self]);
fn openssl_uniform(k: &mut [Self]);
fn rng_uniform_with_some_zeros(k: &mut [Self], probability: Self);
fn vectorial_rng_normal(k: &mut [Self], mean: f64, std_dev: f64);
fn vectorial_openssl_normal(k: &mut [Self], mean: f64, std_dev: f64);
fn rng_normal(mean: f64, std_dev: f64) -> Self;
fn openssl_normal(mean: f64, std_dev: f64) -> Self;
fn openssl_normal_couple(mean: f64, std_dev: f64) -> (Self, Self); }

Required methods

fn rng_uniform_n_msb(t: &mut [Self], n: usize)

fn rng_uniform_n_lsb(k: &mut [Self], n: usize)

fn rng_uniform(k: &mut [Self])

fn openssl_uniform(k: &mut [Self])

fn rng_uniform_with_some_zeros(k: &mut [Self], probability: Self)

fn vectorial_rng_normal(k: &mut [Self], mean: f64, std_dev: f64)

fn vectorial_openssl_normal(k: &mut [Self], mean: f64, std_dev: f64)

fn rng_normal(mean: f64, std_dev: f64) -> Self

fn openssl_normal(mean: f64, std_dev: f64) -> Self

fn openssl_normal_couple(mean: f64, std_dev: f64) -> (Self, Self)

Loading content...

Implementations on Foreign Types

impl Random for u32[src]

fn rng_uniform_n_msb(t: &mut [u32], n: usize)[src]

Fills a Torus tensor with uniform random in [0,2**n[ on the MSB

Arguments

  • t - a Torus tensor (output)
  • n - number of bit to fill with random

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random in the MSB (5 bits)
Random::rng_uniform_n_msb(&mut t, 5);

fn rng_uniform_n_lsb(k: &mut [u32], n: usize)[src]

Fills a Torus tensor with uniform random in [0,2**n[ on the LSB

Arguments

  • k - a Torus tensor (output)
  • n - number of bit to fill with random

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random in the LSB (5 bits)
Random::rng_uniform_n_lsb(&mut t, 5);

fn rng_uniform(k: &mut [u32])[src]

Fills a Torus tensor with uniform random

Arguments

  • k - a Torus tensor (output)

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random
Random::rng_uniform(&mut t);

fn openssl_uniform(k: &mut [u32])[src]

Fills a Torus tensor with uniform random using openssl CSPTRNG

Arguments

  • k - a Torus tensor (output)

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random
Random::openssl_uniform(&mut t);

fn rng_uniform_with_some_zeros(k: &mut [u32], probability: u32)[src]

Either fills elements of k with uniform random or with a zero according to probability if probability is set to 0.2 (0.2 * 2**TORUS_BIT), then there will be approximately 1/5 random elements and the rest will be set to zero

Arguments

  • k - Torus slice (output)
  • probability - the probability for an element to be uniformly random

Example

use concrete_lib::operators::math::Random;
type Torus = u32;
use concrete_lib::Types;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random 20 percents of the time
Random::rng_uniform_with_some_zeros(
    &mut t,
    (0.2 * f64::powi(2., <Torus as Types>::TORUS_BIT as i32)) as Torus,
);

fn vectorial_rng_normal(k: &mut [u32], mean: f64, std_dev: f64)[src]

Fills a Torus tensor with normal random

Arguments

  • k - a Torus tensor (output)
  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// allocation of a tensor
let mut t: Vec<Torus> = vec![0; k];

// fill with random
Random::vectorial_rng_normal(&mut t, 0., std_dev);

fn vectorial_openssl_normal(k: &mut [u32], mean: f64, std_dev: f64)[src]

Fills a Torus tensor with normal random using a CSPRNG and Box-Muller algorithm

Arguments

  • k - a Torus tensor (output)
  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// allocation of a tensor
let mut t: Vec<Torus> = vec![0; k];

// fill with random
Random::vectorial_openssl_normal(&mut t, 0., std_dev);

fn rng_normal(mean: f64, std_dev: f64) -> u32[src]

Returns a Torus element with normal random

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::rng_normal(0., std_dev);

fn openssl_normal(mean: f64, std_dev: f64) -> u32[src]

Returns a Torus element with normal random using a CSPRNG and Box-Muller algorithm

Warning

  • This function discards 1/2 of the sample

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::openssl_normal(0., std_dev);

fn openssl_normal_couple(mean: f64, std_dev: f64) -> (u32, u32)[src]

Returns a Torus element with normal random using a CSPRNG and Box-Muller algorithm

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u32;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::openssl_normal(0., std_dev);

impl Random for u64[src]

fn rng_uniform_n_msb(t: &mut [u64], n: usize)[src]

Fills a Torus tensor with uniform random in [0,2**n[ on the MSB

Arguments

  • t - a Torus tensor (output)
  • n - number of bit to fill with random

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random in the MSB (5 bits)
Random::rng_uniform_n_msb(&mut t, 5);

fn rng_uniform_n_lsb(k: &mut [u64], n: usize)[src]

Fills a Torus tensor with uniform random in [0,2**n[ on the LSB

Arguments

  • k - a Torus tensor (output)
  • n - number of bit to fill with random

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random in the LSB (5 bits)
Random::rng_uniform_n_lsb(&mut t, 5);

fn rng_uniform(k: &mut [u64])[src]

Fills a Torus tensor with uniform random

Arguments

  • k - a Torus tensor (output)

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random
Random::rng_uniform(&mut t);

fn openssl_uniform(k: &mut [u64])[src]

Fills a Torus tensor with uniform random using openssl CSPTRNG

Arguments

  • k - a Torus tensor (output)

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random
Random::openssl_uniform(&mut t);

fn rng_uniform_with_some_zeros(k: &mut [u64], probability: u64)[src]

Either fills elements of k with uniform random or with a zero according to probability if probability is set to 0.2 (0.2 * 2**TORUS_BIT), then there will be approximately 1/5 random elements and the rest will be set to zero

Arguments

  • k - Torus slice (output)
  • probability - the probability for an element to be uniformly random

Example

use concrete_lib::operators::math::Random;
type Torus = u64;
use concrete_lib::Types;

// allocation of a torus
let mut t: Vec<Torus> = vec![0; 100];

// fill with uniform random 20 percents of the time
Random::rng_uniform_with_some_zeros(
    &mut t,
    (0.2 * f64::powi(2., <Torus as Types>::TORUS_BIT as i32)) as Torus,
);

fn vectorial_rng_normal(k: &mut [u64], mean: f64, std_dev: f64)[src]

Fills a Torus tensor with normal random

Arguments

  • k - a Torus tensor (output)
  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// allocation of a tensor
let mut t: Vec<Torus> = vec![0; k];

// fill with random
Random::vectorial_rng_normal(&mut t, 0., std_dev);

fn vectorial_openssl_normal(k: &mut [u64], mean: f64, std_dev: f64)[src]

Fills a Torus tensor with normal random using a CSPRNG and Box-Muller algorithm

Arguments

  • k - a Torus tensor (output)
  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// allocation of a tensor
let mut t: Vec<Torus> = vec![0; k];

// fill with random
Random::vectorial_openssl_normal(&mut t, 0., std_dev);

fn rng_normal(mean: f64, std_dev: f64) -> u64[src]

Returns a Torus element with normal random

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::rng_normal(0., std_dev);

fn openssl_normal(mean: f64, std_dev: f64) -> u64[src]

Returns a Torus element with normal random using a CSPRNG and Box-Muller algorithm

Warning

  • This function discards 1/2 of the sample

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::openssl_normal(0., std_dev);

fn openssl_normal_couple(mean: f64, std_dev: f64) -> (u64, u64)[src]

Returns a Torus element with normal random using a CSPRNG and Box-Muller algorithm

Arguments

  • mean - mean of the normal distribution
  • std_dev - standard deviation of the normal distribution

Output

  • returns the Torus element sampled from the desired distribution

Example

use concrete_lib::operators::math::Random;
type Torus = u64;

// settings
let std_dev: f64 = f64::powi(2., -20);
let k = 100;

// get a random element
let elt: Torus = Random::openssl_normal(0., std_dev);
Loading content...

Implementors

Loading content...