[−][src]Struct rstat::UnitSimplex
Utility for sampling from a unit \(K\)-simplex.
Methods
impl UnitSimplex
[src]
pub fn new(n: usize) -> UnitSimplex
[src]
Construct a \(K = n + 1\) probability simplex.
pub fn centre(&self) -> SimplexVector
[src]
Compute the central point of the simplex \(x_i = 1 / K\).
Examples
use rstat::UnitSimplex; let s = UnitSimplex::new(2).centre(); for i in 0..3 { assert_eq!(s[i], 1.0 / 3.0); }
pub fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SimplexVector
[src]
Draws a uniformly random point on the simplex.
This algorithm works as follows:
- Draw \(K\) independent points, \(x_i \in [0, 1]\), uniformly at random.
- Apply the transformation \(z_i = -\ln{x_i}\).
- Compute the sum \(s = \sum_i x_i\).
- Return the vector of values \(z_i / s\).
Examples
use rand::thread_rng; use rstat::UnitSimplex; let s = UnitSimplex::new(2).sample(&mut thread_rng()); assert!((s.iter().sum::<f64>() - 1.0).abs() < 1e-7);
Trait Implementations
impl Clone for UnitSimplex
[src]
fn clone(&self) -> UnitSimplex
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for UnitSimplex
[src]
impl Debug for UnitSimplex
[src]
Auto Trait Implementations
impl RefUnwindSafe for UnitSimplex
impl Send for UnitSimplex
impl Sync for UnitSimplex
impl Unpin for UnitSimplex
impl UnwindSafe for UnitSimplex
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,