[−][src]Struct rv::data::Partition
Methods
impl Partition
[src]
pub fn new() -> Partition
[src]
Empty partition
pub fn new_unchecked(z: Vec<usize>, counts: Vec<usize>) -> Self
[src]
pub fn z(&self) -> &Vec<usize>
[src]
pub fn z_mut(&mut self) -> &mut Vec<usize>
[src]
pub fn counts(&self) -> &Vec<usize>
[src]
pub fn counts_mut(&mut self) -> &mut Vec<usize>
[src]
pub fn from_z(z: Vec<usize>) -> Result<Self, PartitionError>
[src]
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<(), PartitionError>
[src]
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<(), PartitionError>
[src]
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]
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]
Returns the number items
pub fn is_empty(&self) -> bool
[src]
pub fn weights(&self) -> Vec<f64>
[src]
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 Clone for Partition
[src]
impl Debug for Partition
[src]
impl Default for Partition
[src]
impl Display for Partition
[src]
impl Eq for Partition
[src]
impl<'_> From<&'_ Partition> for String
[src]
impl PartialEq<Partition> for Partition
[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]
impl StructuralEq for Partition
[src]
impl StructuralPartialEq for Partition
[src]
impl Support<Partition> for Crp
[src]
Auto Trait Implementations
impl RefUnwindSafe for Partition
impl Send for Partition
impl Sync for Partition
impl Unpin for Partition
impl UnwindSafe for Partition
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<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<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>,