Struct rv::data::Partition[][src]

pub struct Partition {
    pub z: Vec<usize>,
    pub counts: Vec<usize>,
}

Fields

The assignment of the n items to partitions 0, ..., k-1

The number of items assigned to each partition

Methods

impl Partition
[src]

Empty partition

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());

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]);

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]);

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]);

Returns the number items

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]

Formats the value using the given formatter. Read more

impl Clone for Partition
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for Partition
[src]

Returns the "default value" for a type. Read more

impl Rv<Partition> for Crp
[src]

Probability function Read more

Single draw from the Rv Read more

Probability function Read more

Multiple draws of the Rv Read more

impl Support<Partition> for Crp
[src]

Returns true if x is in the support of the Rv Read more

Auto Trait Implementations

impl Send for Partition

impl Sync for Partition