Struct Dbscan

Source
pub struct Dbscan<A, M> {
    pub eps: A,
    pub min_samples: usize,
    pub metric: M,
}
Expand description

DBSCAN (density-based spatial clustering of applications with noise) clustering algorithm.

§Examples

use ndarray::array;
use petal_neighbors::distance::Euclidean;
use petal_clustering::{Dbscan, Fit};

let points = array![[1., 2.], [2., 2.], [2., 2.3], [8., 7.], [8., 8.], [25., 80.]];
let clustering = Dbscan::new(3., 2, Euclidean::default()).fit(&points, None);

assert_eq!(clustering.0.len(), 2);        // two clusters found
assert_eq!(clustering.0[&0], [0, 1, 2]);  // the first three points in Cluster 0
assert_eq!(clustering.0[&1], [3, 4]);     // [8., 7.] and [8., 8.] in Cluster 1
assert_eq!(clustering.1, [5]);            // [25., 80.] doesn't belong to any cluster

Fields§

§eps: A

The radius of a neighborhood.

§min_samples: usize

The minimum number of points required to form a dense region.

§metric: M

Implementations§

Source§

impl<A, M> Dbscan<A, M>

Source

pub fn new(eps: A, min_samples: usize, metric: M) -> Self

Trait Implementations§

Source§

impl<A: Debug, M: Debug> Debug for Dbscan<A, M>

Source§

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

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

impl<A> Default for Dbscan<A, Euclidean>
where A: FloatCore,

Source§

fn default() -> Self

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

impl<'de, A, M> Deserialize<'de> for Dbscan<A, M>
where A: Deserialize<'de>, M: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<S, A, M> Fit<ArrayBase<S, Dim<[usize; 2]>>, HashMap<usize, Vec<usize>>, (HashMap<usize, Vec<usize>>, Vec<usize>)> for Dbscan<A, M>
where A: AddAssign + DivAssign + FloatCore + FromPrimitive + Sync, S: Data<Elem = A>, M: Metric<A> + Clone + Sync,

Fits the DBSCAN clustering algorithm to the given input data.

§Parameters

  • input: A 2D array representing the dataset to cluster. Each row corresponds to a data point.
  • _params: An optional parameter for prelabelled data. Not used in this implementation, but required for consistency.

§Returns

A tuple containing:

  • HashMap<usize, Vec<usize>>: A mapping of cluster IDs to the indices of points in each cluster.
  • Vec<usize>: A vector of indices representing the noise points that do not belong to any cluster.
Source§

fn fit( &mut self, input: &ArrayBase<S, Ix2>, _params: Option<&HashMap<usize, Vec<usize>>>, ) -> (HashMap<usize, Vec<usize>>, Vec<usize>)

Source§

impl<A, M> Serialize for Dbscan<A, M>
where A: Serialize, M: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<A, M> Freeze for Dbscan<A, M>
where A: Freeze, M: Freeze,

§

impl<A, M> RefUnwindSafe for Dbscan<A, M>

§

impl<A, M> Send for Dbscan<A, M>
where A: Send, M: Send,

§

impl<A, M> Sync for Dbscan<A, M>
where A: Sync, M: Sync,

§

impl<A, M> Unpin for Dbscan<A, M>
where A: Unpin, M: Unpin,

§

impl<A, M> UnwindSafe for Dbscan<A, M>
where A: UnwindSafe, M: 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> 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, 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,