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>,
impl<T> Model<T>where T: Copy, f64: From<T>,
sourcepub fn new(eps: f64, min_points: usize) -> Model<T>
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 clustermin_points
- minimum number of datapoints to make a cluster
sourcepub fn set_distance_fn<F>(self, func: fn(_: &[T], _: &[T]) -> f64) -> Model<T>
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.
sourcepub fn run(self, population: &Vec<Vec<T>>) -> Vec<Classification>
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
]
);