pub struct DBStream { /* private fields */ }Expand description
Density-based streaming clustering.
Maintains a set of weighted micro-clusters and a shared-density graph.
Points that fall within radius of an existing micro-cluster are merged
into it; otherwise a new micro-cluster is created. Shared density between
pairs of micro-clusters accumulates when a single point is within range
of both. Macro-clusters are formed by finding connected components in the
shared-density graph.
§Example
use irithyll::clustering::dbstream::{DBStreamConfig, DBStream};
let config = DBStreamConfig::builder(1.0).build().unwrap();
let mut db = DBStream::new(config);
db.train_one(&[0.0, 0.0]);
db.train_one(&[0.1, 0.1]);
db.train_one(&[10.0, 10.0]);
assert_eq!(db.n_micro_clusters(), 2);Implementations§
Source§impl DBStream
impl DBStream
Sourcepub fn new(config: DBStreamConfig) -> Self
pub fn new(config: DBStreamConfig) -> Self
Create a new DBStream instance from the given configuration.
Sourcepub fn train_one(&mut self, features: &[f64])
pub fn train_one(&mut self, features: &[f64])
Process a single sample, updating micro-clusters and shared density.
This is the core DBSTREAM algorithm:
- Find all micro-clusters within
radiusof the point. - If at least one is in range, merge into the nearest and update shared density for all in-range pairs.
- Otherwise, create a new micro-cluster at the point’s location.
- Apply exponential decay to all weights and shared densities.
- Periodically clean up micro-clusters below
min_weight.
Sourcepub fn predict(&self, features: &[f64]) -> usize
pub fn predict(&self, features: &[f64]) -> usize
Assign the given point to the nearest micro-cluster.
Returns the index into micro_clusters().
§Panics
Panics if there are no micro-clusters.
Sourcepub fn predict_or_noise(
&self,
features: &[f64],
noise_radius: f64,
) -> Option<usize>
pub fn predict_or_noise( &self, features: &[f64], noise_radius: f64, ) -> Option<usize>
Assign the given point to the nearest micro-cluster, or return None
if the point is further than noise_radius from all micro-clusters.
Sourcepub fn micro_clusters(&self) -> &[MicroCluster]
pub fn micro_clusters(&self) -> &[MicroCluster]
Return a reference to the current micro-clusters.
Sourcepub fn n_micro_clusters(&self) -> usize
pub fn n_micro_clusters(&self) -> usize
Number of active micro-clusters.
Sourcepub fn macro_clusters(&self) -> Vec<Vec<usize>>
pub fn macro_clusters(&self) -> Vec<Vec<usize>>
Group micro-clusters into macro-clusters via connected components in the shared-density graph.
Two micro-clusters i and j are connected if their shared density
exceeds shared_density_threshold * (weight_i + weight_j). Returns
a Vec of groups, where each group is a Vec<usize> of micro-cluster
indices.
Sourcepub fn n_clusters(&self) -> usize
pub fn n_clusters(&self) -> usize
Number of macro-clusters (connected components in the shared-density graph).
Sourcepub fn n_samples_seen(&self) -> u64
pub fn n_samples_seen(&self) -> u64
Total number of samples processed so far.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DBStream
impl RefUnwindSafe for DBStream
impl Send for DBStream
impl Sync for DBStream
impl Unpin for DBStream
impl UnsafeUnpin for DBStream
impl UnwindSafe for DBStream
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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