Struct peroxide::statistics::dist::WeightedUniform

source ·
pub struct WeightedUniform<T: PartialOrd + SampleUniform + Copy + Into<f64>> { /* private fields */ }

Implementations§

source§

impl WeightedUniform<f64>

source

pub fn new(weights: Vec<f64>, intervals: Vec<f64>) -> Result<Self>

Create a new weighted uniform distribution

§Examples
use peroxide::fuga::*;
 
fn main() -> Result<(), Box<dyn Error>> {
    let weights = vec![1f64, 3f64, 0f64, 2f64];
    let intervals = vec![0f64, 1f64, 2f64, 4f64, 5f64];
    let w = WeightedUniform::new(weights, intervals)?;
    assert_eq!(w.weights(), &vec![1f64, 3f64, 2f64]);
    assert_eq!(w.intervals(), &vec![(0f64, 1f64), (1f64, 2f64), (4f64, 5f64)]);

    Ok(())
}
source

pub fn from_max_pool_1d<F>( f: F, (a, b): (f64, f64), n: usize, eps: f64, ) -> Result<Self>
where F: Fn(f64) -> f64 + Copy,

Create WeightedUniform from max pooling

§Examples
use peroxide::fuga::*;
 
fn main() -> Result<(), Box<dyn Error>> {
    let w = WeightedUniform::from_max_pool_1d(f, (-2f64, 3f64), 10, 1e-3)?;
    w.weights().print();

    Ok(())
}
 
fn f(x: f64) -> f64 {
    if x.abs() < 1f64 {
        1f64 - x.abs()
    } else {
       0f64
    }
}
source

pub fn weights(&self) -> &Vec<f64>

source

pub fn intervals(&self) -> &Vec<(f64, f64)>

source

pub fn domain_linspace(&self, n: usize) -> Vec<f64>

source

pub fn domain_seq(&self, step: f64) -> Vec<f64>

source

pub fn sum(&self) -> f64

source

pub fn update_weights(&mut self, weights: Vec<f64>)

source

pub fn update_intervals(&mut self, intervals: Vec<f64>)

source

pub fn weight_at(&self, x: f64) -> f64

source

pub fn interval_at(&self, x: f64) -> (f64, f64)

Trait Implementations§

source§

impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> ParametricDist for WeightedUniform<T>

§

type Parameter = (Vec<f64>, Vec<(f64, f64)>)

source§

fn params(&self) -> Self::Parameter

source§

impl RNG for WeightedUniform<f64>

source§

fn sample_with_rng<R: Rng + Clone>(&self, rng: &mut R, n: usize) -> Vec<f64>

Extract samples of distributions with rng
source§

fn pdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64

Probability Distribution Function Read more
source§

fn cdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64

Cumulative Distribution Function Read more
source§

fn sample(&self, n: usize) -> Vec<f64>

Extract samples of distributions
source§

impl Statistics for WeightedUniform<f64>

§

type Array = Vec<f64>

§

type Value = f64

source§

fn mean(&self) -> Self::Value

source§

fn var(&self) -> Self::Value

source§

fn sd(&self) -> Self::Value

source§

fn cov(&self) -> Self::Array

source§

fn cor(&self) -> Self::Array

Auto Trait Implementations§

§

impl<T> Freeze for WeightedUniform<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for WeightedUniform<T>
where T: RefUnwindSafe,

§

impl<T> Send for WeightedUniform<T>
where T: Send,

§

impl<T> Sync for WeightedUniform<T>
where T: Sync,

§

impl<T> Unpin for WeightedUniform<T>
where T: Unpin,

§

impl<T> UnwindSafe for WeightedUniform<T>
where T: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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