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

pub struct Partition { /* fields omitted */ }

Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Probability function Read more

Single draw from the Rv Read more

Probability function Read more

Multiple draws of the Rv Read more

Create a never-ending iterator of samples Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.