Skip to main content

Cover

Struct Cover 

Source
pub struct Cover {
    pub num_attributes: usize,
    pub num_labels: usize,
    pub num_samples: usize,
    /* private fields */
}
Expand description

A binary dataset and the set of instances reaching the current node.

Features and classes are stored as bitsets over the instances. Branching on an item intersects the current set with a feature’s bitset (or its complement), and backtracking restores the previous set in constant time thanks to a reversible sparse bitset.

An item encodes a feature and a branch: 2 * feature is the branch where the feature is 0 (left) and 2 * feature + 1 the branch where it is 1 (right). See crate::globals.

Fields§

§num_attributes: usize

Number of binary features.

§num_labels: usize

Number of classes.

§num_samples: usize

Number of instances in the dataset.

Implementations§

Source§

impl Cover

Source

pub fn new( attributes: Vec<Bitset>, labels: Vec<Bitset>, num_samples: usize, ) -> Self

A cover over all instances, from one bitset per feature (instances where it is 1) and one per class.

Source

pub fn count(&self) -> usize

Number of instances in the current node.

Source

pub fn labels_count(&self) -> Vec<usize>

Number of instances of each class in the current node.

Source

pub fn labels_count_with_buffer(&self, buffer: &mut Vec<usize>)

Self::labels_count writing into buffer.

Source

pub fn branch_on(&mut self, item: usize) -> usize

Moves to the child reached by item and returns its number of instances.

Source

pub fn count_if_branch_on(&self, item: usize) -> usize

Number of instances the child reached by item would have.

Source

pub fn backtrack(&mut self)

Returns to the parent of the current node.

§Panics

At the root.

Source

pub fn to_vec(&self) -> Vec<usize>

Ids of the instances in the current node.

Source

pub fn shallow_cover(&self) -> ShallowBitset

A plain copy of the current set of instances.

Source

pub fn sparse(&self) -> &SparseBitset

The reversible set of instances.

Source

pub fn path(&self) -> &[usize]

Items branched on from the root to the current node.

Auto Trait Implementations§

§

impl Freeze for Cover

§

impl RefUnwindSafe for Cover

§

impl Send for Cover

§

impl Sync for Cover

§

impl Unpin for Cover

§

impl UnsafeUnpin for Cover

§

impl UnwindSafe for Cover

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.