Skip to main content

Tree

Struct Tree 

Source
pub struct Tree<I: Instance, U: Number, D: Dataset<I, U>, C: Cluster<U>> { /* private fields */ }
Expand description

A Tree represents a hierarchy of Clusters, i.e. “similar” instances from a metric-Space.

The Tree has other implementation blocks spread across the crate. These are used for specific functionality for the concrete Cluster types we provide.

§Type Parameters

  • T: The type of the instances in the Tree.
  • U: The type of the distance values between instances.
  • D: The type of the Dataset from which the Tree is built.

Implementations§

Source§

impl<I: Instance, U: Number, D: Dataset<I, U>> Tree<I, U, D, Vertex<U>>

Source

pub fn normalize_ratios(self) -> Self

Sets the Vertex ratios for anomaly detection and related applications.

This should only be called on the root Cluster after calling partition.

§Arguments
  • normalized: Whether to apply Gaussian error normalization to the ratios.
Source§

impl<I: Instance, U: Number, D: Dataset<I, U>, C: Cluster<U>> Tree<I, U, D, C>

Source

pub fn new(data: D, seed: Option<u64>) -> Self

Constructs a new Tree for a given dataset. Importantly, this does not partition the tree.

§Arguments

dataset: The dataset from which the tree will be built

Source

pub fn partition<P: PartitionCriterion<U>>( self, criteria: &P, seed: Option<u64>, ) -> Self

Recursively partitions the root Cluster using the given criteria.

§Arguments
  • criteria: the criteria used to decide when to partition a Cluster.
§Returns

The Tree after partitioning.

Source

pub fn get_cluster(&self, offset: usize, cardinality: usize) -> Option<&C>

Returns the Cluster with the given offset and cardinality.

§Arguments
  • offset: The offset of the Cluster to return.
  • cardinality: The cardinality of the Cluster to return.
§Returns

The Cluster with the given offset and cardinality if it exists. Otherwise, None.

Source

pub const fn data(&self) -> &D

Returns a reference to the data used to build the Tree.

Source

pub fn cardinality(&self) -> usize

The cardinality of the Tree, i.e. the number of instances in the data.

Source

pub fn radius(&self) -> U

The radius of the root of the Tree.

Source

pub const fn root(&self) -> &C

The root Cluster of the Tree.

Source

pub const fn depth(&self) -> usize

The depth of the Tree.

Source

pub fn save(&self, path: &Path) -> Result<(), String>

Saves a tree to a given location

The path given will point to a newly created folder which will store all necessary data for tree reconstruction.

The directory structure looks like the following:

/user/given/path/
   |- dataset      <-- The serialized dataset.
   |- clusters     <-- Clusters are serialized to a single file.
§Arguments
  • path - The path to save the tree to.
§Errors
  • If path does not exist.
  • If path cannot be written to.
  • If there are any serialization errors with the dataset.
Source

pub fn load( path: &Path, metric: fn(&I, &I) -> U, is_expensive: bool, ) -> Result<Self, String>

Reconstructs a Tree from a directory path with associated metric metric. Returns the reconstructed tree.

§Arguments
  • path - The path to load the tree from.
  • metric - The metric to use for the tree.
  • is_expensive - Whether or not the metric is expensive to compute.
§Returns

The reconstructed tree.

§Errors
  • If path does not exist.
  • If path does not contain a valid tree. See save for more information on the directory structure.
  • If the path cannot be read from.
  • If there are any deserialization errors with the dataset.
  • If there are any deserialization errors with the clusters.

Trait Implementations§

Source§

impl<I: Debug + Instance, U: Debug + Number, D: Debug + Dataset<I, U>, C: Debug + Cluster<U>> Debug for Tree<I, U, D, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I, U, D, C> Freeze for Tree<I, U, D, C>

§

impl<I, U, D, C> RefUnwindSafe for Tree<I, U, D, C>

§

impl<I, U, D, C> Send for Tree<I, U, D, C>

§

impl<I, U, D, C> Sync for Tree<I, U, D, C>

§

impl<I, U, D, C> Unpin for Tree<I, U, D, C>
where D: Unpin, C: Unpin, PhantomData<I>: Unpin, PhantomData<U>: Unpin,

§

impl<I, U, D, C> UnsafeUnpin for Tree<I, U, D, C>

§

impl<I, U, D, C> UnwindSafe for Tree<I, U, D, C>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V