Struct dbscan::Model

source ·
pub struct Model<T>where
    T: Copy,
    f64: From<T>,{
    pub eps: f64,
    pub mpt: usize,
    /* private fields */
}
Expand description

DBSCAN parameters

Fields§

§eps: f64

Epsilon value - maximum distance between points in a cluster

§mpt: usize

Minimum number of points in a cluster

Implementations§

source§

impl<T> Model<T>where T: Copy, f64: From<T>,

source

pub fn new(eps: f64, min_points: usize) -> Model<T>

Create a new Model with a set of parameters

Arguments
  • eps - maximum distance between datapoints within a cluster
  • min_points - minimum number of datapoints to make a cluster
source

pub fn set_distance_fn<F>(self, func: fn(_: &[T], _: &[T]) -> f64) -> Model<T>

Change the function used to calculate distance between points. Euclidean distance is the default measurement used.

source

pub fn run(self, population: &Vec<Vec<T>>) -> Vec<Classification>

Run the DBSCAN algorithm on a given population of datapoints.

A vector of Classification enums is returned, where each element corresponds to a row in the input matrix.

Arguments
  • population - a matrix of datapoints, organized by rows
Example
use dbscan::Classification::*;
use dbscan::Model;

let model = Model::new(1.0, 3);
let inputs = vec![
    vec![1.5, 2.2],
    vec![1.0, 1.1],
    vec![1.2, 1.4],
    vec![0.8, 1.0],
    vec![3.7, 4.0],
    vec![3.9, 3.9],
    vec![3.6, 4.1],
    vec![10.0, 10.0],
];
let output = model.run(&inputs);
assert_eq!(
    output,
    vec![
        Edge(0),
        Core(0),
        Core(0),
        Core(0),
        Core(1),
        Core(1),
        Core(1),
        Noise
    ]
);

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Model<T>

§

impl<T> Send for Model<T>

§

impl<T> Sync for Model<T>

§

impl<T> Unpin for Model<T>

§

impl<T> UnwindSafe for Model<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.