Struct peroxide::statistics::dist::WeightedUniform
source · [−]pub struct WeightedUniform<T: PartialOrd + SampleUniform + Copy + Into<f64>> { /* private fields */ }
Implementations
sourceimpl WeightedUniform<f64>
impl WeightedUniform<f64>
sourcepub fn new(weights: Vec<f64>, intervals: Vec<f64>) -> Self
pub fn new(weights: Vec<f64>, intervals: Vec<f64>) -> Self
Create a new weighted uniform distribution
Examples
extern crate peroxide;
use peroxide::fuga::*;
fn main() {
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)]);
}
sourcepub fn from_max_pool_1d<F>(f: F, (a, b): (f64, f64), n: usize, eps: f64) -> Self where
F: Fn(f64) -> f64 + Copy,
pub fn from_max_pool_1d<F>(f: F, (a, b): (f64, f64), n: usize, eps: f64) -> Self where
F: Fn(f64) -> f64 + Copy,
Create WeightedUniform from max pooling
Examples
extern crate peroxide;
use peroxide::fuga::*;
fn main() {
let w = WeightedUniform::from_max_pool_1d(f, (-2f64, 3f64), 10, 1e-3);
w.weights().print();
}
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
sourceimpl<T: PartialOrd + SampleUniform + Copy + Into<f64>> ParametricDist for WeightedUniform<T>
impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> ParametricDist for WeightedUniform<T>
sourceimpl RNG for WeightedUniform<f64>
impl RNG for WeightedUniform<f64>
sourcefn 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
sourcefn 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> 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more