Struct peroxide::statistics::dist::WeightedUniform
source · pub struct WeightedUniform<T: PartialOrd + SampleUniform + Copy + Into<f64>> { /* private fields */ }
Implementations§
source§impl WeightedUniform<f64>
impl WeightedUniform<f64>
sourcepub fn new(weights: Vec<f64>, intervals: Vec<f64>) -> Result<Self>
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(())
}
sourcepub fn from_max_pool_1d<F>(
f: F,
(a, b): (f64, f64),
n: usize,
eps: f64,
) -> Result<Self>
pub fn from_max_pool_1d<F>( f: F, (a, b): (f64, f64), n: usize, eps: f64, ) -> Result<Self>
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
}
}
pub fn weights(&self) -> &Vec<f64>
pub fn intervals(&self) -> &Vec<(f64, f64)>
pub fn domain_linspace(&self, n: usize) -> Vec<f64>
pub fn domain_seq(&self, step: f64) -> Vec<f64>
pub fn sum(&self) -> f64
pub fn update_weights(&mut self, weights: Vec<f64>)
pub fn update_intervals(&mut self, intervals: Vec<f64>)
pub fn weight_at(&self, x: f64) -> f64
pub fn interval_at(&self, x: f64) -> (f64, f64)
Trait Implementations§
source§impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> ParametricDist for WeightedUniform<T>
impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> ParametricDist for WeightedUniform<T>
source§impl RNG for WeightedUniform<f64>
impl RNG for WeightedUniform<f64>
source§fn sample_with_rng<R: Rng + Clone>(&self, rng: &mut R, n: usize) -> Vec<f64>
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
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
fn cdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64
Cumulative Distribution Function Read more
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more