[][src]Crate kddbscan

A k -Deviation Density Based Clustering Algorithm (kDDBSCAN)

Research Paper

Due to the adoption of global parameters, DBSCAN fails to identify clusters with different and varied densities. To solve the problem, this paper extends DBSCAN by exploiting a new density definition and proposes a novel algorithm called k -deviation density based DBSCAN (kDDBSCAN). Various datasets containing clusters with arbitrary shapes and different or varied densities are used to demonstrate the performance and investigate the feasibility and practicality of kDDBSCAN. The results show that kDDBSCAN performs better than DBSCAN.


Add the following to your Cargo.toml file:

kddbscan = "0.1.0"


use kddbscan::{cluster, IntoPoint};

pub struct Coordinate {
    pub x: f64,
    pub y: f64,

// Implement IntoPoint trait to your data structur
impl IntoPoint for Coordinate {
    fn get_distance(&self, neighbor: &Coordinate) -> f64 {
        ((self.x - neighbor.x).powi(2) + (self.y - neighbor.y).powi(2)).powf(0.5)

fn main() {
    // Create a vector with your data
    let mut coordinates: Vec<Coordinate> = vec![];    
    coordinates.push(Coordinate { x: 11.0, y: 12.0 });
    coordinates.push(Coordinate { x: 0.0, y: 0.0 });
    coordinates.push(Coordinate { x: 12.0, y: 11.0 });
    coordinates.push(Coordinate { x: 11.0, y: 11.0 });
    coordinates.push(Coordinate { x: 1.0, y: 2.0 });
    coordinates.push(Coordinate { x: 3.0, y: 1.0 });

    // Call cluster function
    let clustered =  cluster(coordinates, 2, None, None);
    let first_cluster_id = clustered.get(0).unwrap().get_cluster_id();
    let second_cluster_id = clustered.get(1).unwrap().get_cluster_id();
    assert_eq!(first_cluster_id, clustered.get(2).unwrap().get_cluster_id());
    assert_eq!(first_cluster_id, clustered.get(3).unwrap().get_cluster_id());
    assert_eq!(second_cluster_id, clustered.get(4).unwrap().get_cluster_id());
    assert_eq!(second_cluster_id, clustered.get(5).unwrap().get_cluster_id());



This struct is using to store temporary values for points such as cluster_id and index of the point



Cluster id types



You should implement IntoPoint for all points



Clustering a vec of structs