[][src]Struct rv::dist::Crp

pub struct Crp { /* fields omitted */ }

Chinese Restaurant Process, a distribution over partitions.

Example

use::rv::prelude::*;

let mut rng = rand::thread_rng();

let crp = Crp::new(1.0, 10).expect("Invalid parameters");
let partition = crp.draw(&mut rng);

assert_eq!(partition.len(), 10);

Implementations

impl Crp[src]

pub fn new(alpha: f64, n: usize) -> Result<Self, CrpError>[src]

Create an empty Crp with parameter alpha

Arguments

  • alpha: Discount parameter in (0, Infinity)
  • n: the number of items in the partition

pub fn new_unchecked(alpha: f64, n: usize) -> Self[src]

Create a new Crp without checking whether the parametes are valid.

pub fn alpha(&self) -> f64[src]

Get the discount parameter, alpha.

Example

let crp = Crp::new(1.0, 12).unwrap();
assert_eq!(crp.alpha(), 1.0);

pub fn set_alpha(&mut self, alpha: f64) -> Result<(), CrpError>[src]

Set the value of alpha

Example

let mut crp = Crp::new(1.1, 20).unwrap();
assert_eq!(crp.alpha(), 1.1);

crp.set_alpha(2.3).unwrap();
assert_eq!(crp.alpha(), 2.3);

Will error for invalid parameters

assert!(crp.set_alpha(0.5).is_ok());
assert!(crp.set_alpha(0.0).is_err());
assert!(crp.set_alpha(-1.0).is_err());
assert!(crp.set_alpha(std::f64::INFINITY).is_err());
assert!(crp.set_alpha(std::f64::NEG_INFINITY).is_err());
assert!(crp.set_alpha(std::f64::NAN).is_err());

pub fn set_alpha_unchecked(&mut self, alpha: f64)[src]

Set the value of alpha without input validation

pub fn n(&self) -> usize[src]

Get the number of entries in the partition, n.

Example

let crp = Crp::new(1.0, 12).unwrap();
assert_eq!(crp.n(), 12);

pub fn set_n(&mut self, n: usize) -> Result<(), CrpError>[src]

Set the value of n

Example

let mut crp = Crp::new(1.1, 20).unwrap();
assert_eq!(crp.n(), 20);

crp.set_n(11).unwrap();
assert_eq!(crp.n(), 11);

Will error for invalid parameters

assert!(crp.set_n(5).is_ok());
assert!(crp.set_n(1).is_ok());
assert!(crp.set_n(0).is_err());

pub fn set_n_unchecked(&mut self, n: usize)[src]

Set the value of alpha without input validation

Trait Implementations

impl Clone for Crp[src]

impl Debug for Crp[src]

impl Display for Crp[src]

impl<'_> From<&'_ Crp> for String[src]

impl PartialEq<Crp> for Crp[src]

impl Rv<Partition> for Crp[src]

impl StructuralPartialEq for Crp[src]

impl Support<Partition> for Crp[src]

Auto Trait Implementations

impl RefUnwindSafe for Crp

impl Send for Crp

impl Sync for Crp

impl Unpin for Crp

impl UnwindSafe for Crp

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Fx, X> Rv<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Rv<X>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<Fx, X> Support<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Support<X>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,