Skip to main content

Dbscan

Struct Dbscan 

Source
pub struct Dbscan<D: DistanceMetric = Euclidean> { /* private fields */ }
Expand description

DBSCAN clustering algorithm, generic over a distance metric.

The default metric is Euclidean (L2), matching the original behavior where epsilon is compared against Euclidean distance.

use clump::{Dbscan, Clustering, NOISE};

let data = vec![
    vec![0.0f32, 0.0], vec![0.1, 0.0], vec![0.0, 0.1], // cluster
    vec![100.0, 100.0], // outlier
];

let labels = Dbscan::new(0.5, 2).fit_predict(&data).unwrap();
assert_eq!(labels[0], labels[1]); // same cluster
assert_eq!(labels[3], NOISE);     // outlier is noise

Implementations§

Source§

impl Dbscan<Euclidean>

Source

pub fn new(epsilon: f32, min_pts: usize) -> Self

Create a new DBSCAN clusterer with the default Euclidean distance.

§Arguments
  • epsilon - Maximum distance between two points to be neighbors.
  • min_pts - Minimum number of points to form a dense region.
§Typical Values
  • epsilon: Often determined by k-distance plot (k = min_pts - 1).
  • min_pts: 2 * dimension is a common heuristic. Minimum is 3.
Source§

impl<D: DistanceMetric> Dbscan<D>

Source

pub fn with_metric(epsilon: f32, min_pts: usize, metric: D) -> Self

Create a new DBSCAN clusterer with a custom distance metric.

Source

pub fn with_epsilon(self, epsilon: f32) -> Self

Set epsilon (neighborhood radius).

Source

pub fn with_min_pts(self, min_pts: usize) -> Self

Set minimum points for core classification.

Source

pub fn fit_predict_with_noise( &self, data: &[Vec<f32>], ) -> Result<Vec<Option<usize>>>

Fit and predict, returning labels where noise is marked as None.

This is a convenience wrapper so callers don’t need to import DbscanExt.

Source

pub fn is_noise(label: usize) -> bool

Check whether a label is the DBSCAN noise sentinel.

Trait Implementations§

Source§

impl<D: Clone + DistanceMetric> Clone for Dbscan<D>

Source§

fn clone(&self) -> Dbscan<D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: DistanceMetric> Clustering for Dbscan<D>

Source§

fn n_clusters(&self) -> usize

DBSCAN discovers clusters dynamically, so this returns 0.

To get the actual number of clusters, examine the labels after fit_predict.

Source§

fn fit_predict(&self, data: &[Vec<f32>]) -> Result<Vec<usize>>

Fit the model (if needed) and return one cluster label per input point.
Source§

impl<D: DistanceMetric> DbscanExt for Dbscan<D>

Source§

fn fit_predict_with_noise( &self, data: &[Vec<f32>], ) -> Result<Vec<Option<usize>>>

Fit and predict, returning labels where noise is marked as None.
Source§

fn is_noise(label: usize) -> bool

Check if a label represents noise.
Source§

impl<D: Debug + DistanceMetric> Debug for Dbscan<D>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Dbscan<Euclidean>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D> Freeze for Dbscan<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Dbscan<D>
where D: RefUnwindSafe,

§

impl<D> Send for Dbscan<D>

§

impl<D> Sync for Dbscan<D>

§

impl<D> Unpin for Dbscan<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Dbscan<D>
where D: UnsafeUnpin,

§

impl<D> UnwindSafe for Dbscan<D>
where D: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V