Struct rv::data::Partition [−][src]
Fields
z: Vec<usize>
The assignment of the n items to partitions 0, ..., k-1
counts: Vec<usize>
The number of items assigned to each partition
Methods
impl Partition
[src]
impl Partition
pub fn new() -> Partition
[src]
pub fn new() -> Partition
Empty partition
pub fn from_z(z: Vec<usize>) -> Result<Self>
[src]
pub fn from_z(z: Vec<usize>) -> Result<Self>
Create a Partition
with a given assignment, z
Examples
let z1 = vec![0, 1, 2, 3, 1, 2]; let part = Partition::from_z(z1).unwrap(); assert_eq!(part.z, vec![0, 1, 2, 3, 1, 2]); assert_eq!(part.counts, vec![1, 2, 2, 1]); // Invalid z because k=4 is empty. All partitions must be occupied. let z2 = vec![0, 1, 2, 3, 1, 5]; assert!(Partition::from_z(z2).is_err());
pub fn remove(&mut self, ix: usize) -> Result<()>
[src]
pub fn remove(&mut self, ix: usize) -> Result<()>
Remove the item at index ix
Example
let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap(); part.remove(1).expect("Could not remove"); assert_eq!(part.z, vec![0, 0, 1]); assert_eq!(part.counts, vec![2, 1]);
pub fn append(&mut self, zi: usize) -> Result<()>
[src]
pub fn append(&mut self, zi: usize) -> Result<()>
Append a new item assigned to partition zi
Example
let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap(); part.append(3).expect("Could not append"); assert_eq!(part.z, vec![0, 1, 0, 2, 3]); assert_eq!(part.counts, vec![2, 1, 1, 1]);
pub fn k(&self) -> usize
[src]
pub fn k(&self) -> usize
Returns the number of partitions, k.
Example
let part = Partition::from_z(vec![0, 1, 0, 2]).unwrap(); assert_eq!(part.k(), 3); assert_eq!(part.counts, vec![2, 1, 1]);
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number items
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
pub fn weights(&self) -> Vec<f64>
[src]
pub fn weights(&self) -> Vec<f64>
Return the partition weights (normalized counts)
Example
let part = Partition::from_z(vec![0, 1, 0, 2]).unwrap(); let weights = part.weights(); assert_eq!(weights, vec![0.5, 0.25, 0.25]);
Trait Implementations
impl Debug for Partition
[src]
impl Debug for Partition
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for Partition
[src]
impl Clone for Partition
fn clone(&self) -> Partition
[src]
fn clone(&self) -> Partition
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl Default for Partition
[src]
impl Default for Partition
impl Rv<Partition> for Crp
[src]
impl Rv<Partition> for Crp
fn ln_f(&self, x: &Partition) -> f64
[src]
fn ln_f(&self, x: &Partition) -> f64
Probability function Read more
fn draw<R: Rng>(&self, rng: &mut R) -> Partition
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Partition
Single draw from the Rv
Read more
fn f(&self, x: &X) -> f64
[src]
fn f(&self, x: &X) -> f64
Probability function Read more
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
Multiple draws of the Rv
Read more
impl Support<Partition> for Crp
[src]
impl Support<Partition> for Crp