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 theTree.U: The type of the distance values between instances.D: The type of theDatasetfrom which theTreeis built.
Implementations§
Source§impl<I: Instance, U: Number, D: Dataset<I, U>> Tree<I, U, D, Vertex<U>>
impl<I: Instance, U: Number, D: Dataset<I, U>> Tree<I, U, D, Vertex<U>>
Sourcepub fn normalize_ratios(self) -> Self
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>
impl<I: Instance, U: Number, D: Dataset<I, U>, C: Cluster<U>> Tree<I, U, D, C>
Sourcepub fn new(data: D, seed: Option<u64>) -> Self
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
Sourcepub fn cardinality(&self) -> usize
pub fn cardinality(&self) -> usize
The cardinality of the Tree, i.e. the number of instances in the data.
Sourcepub fn save(&self, path: &Path) -> Result<(), String>
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
pathdoes not exist. - If
pathcannot be written to. - If there are any serialization errors with the dataset.
Sourcepub fn load(
path: &Path,
metric: fn(&I, &I) -> U,
is_expensive: bool,
) -> Result<Self, String>
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
pathdoes not exist. - If
pathdoes not contain a valid tree. Seesavefor more information on the directory structure. - If the
pathcannot be read from. - If there are any deserialization errors with the dataset.
- If there are any deserialization errors with the clusters.
Trait Implementations§
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>where
D: RefUnwindSafe,
C: RefUnwindSafe,
PhantomData<I>: RefUnwindSafe,
PhantomData<U>: RefUnwindSafe,
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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