[−][src]Struct rv::dist::Crp
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]
fn ln_f(&self, x: &Partition) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Partition
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
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]
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<Fx, X> Rv<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
fn ln_f(&Self, &X) -> f64
[src]
fn f(&Self, &X) -> f64
[src]
fn draw<R>(&Self, &mut R) -> X where
R: Rng,
[src]
R: Rng,
fn sample<R>(&Self, usize, &mut R) -> Vec<X> where
R: Rng,
[src]
R: Rng,
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<Fx, X> Support<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,