Struct DistanceGraph

Source
pub struct DistanceGraph { /* private fields */ }

Implementations§

Source§

impl DistanceGraph

Source

pub fn build<'a, V, F>(data: &'a [V], distfunc: F) -> DistanceGraph
where F: Fn(&V, &V) -> f64,

Start a new instance of the FLAME clustering algortim, given a set of objects and a distance function.

Examples found in repository?
examples/sample.rs (line 62)
55fn main() -> io::Result<()> {
56    let filename = env::args().nth(1);
57    if filename.is_none() {
58        eprintln!("No input file");
59        exit(1);
60    }
61    let data = read_data(io::BufReader::new(File::open(filename.unwrap())?))?;
62    let flame = DistanceGraph::build(&data, distance::euclidean);
63
64    print!("Detecting Cluster Supporting Objects ...");
65    io::stdout().flush()?;
66    let supports = flame.find_supporting_objects(10, -2.0);
67    println!("done, found {}", supports.count());
68
69    print!("Propagating fuzzy memberships ... ");
70    io::stdout().flush()?;
71    let fuzzyships = supports
72        .approximate_fuzzy_memberships(500, 1e-6)
73        .assign_outliers();
74    println!("done");
75
76    print!("Defining clusters from fuzzy memberships ... ");
77    io::stdout().flush()?;
78    let (clusters, outliers) = fuzzyships.make_clusters(-1.0);
79    println!("done");
80
81    for (i, cluster) in clusters.iter().enumerate() {
82        print!("\nCluster {:3}, with {:6} members:\n", i + 1, cluster.len());
83        print_cluster(cluster);
84    }
85    print!("\nCluster outliers, with {:6} members:\n", outliers.len());
86    print_cluster(&outliers);
87
88    Ok(())
89}
Source

pub fn neighbors(&self, id: usize) -> impl Iterator<Item = (usize, f64)> + '_

Returns the neighbors of an object, represented as (id, distance) tuples, sorted in order from closest to furthest away.

Source

pub fn find_supporting_objects( &self, knn: usize, thd: f64, ) -> ClusterSupportingObjects

Define knn-nearest neighbors for each object and the Cluster Supporting Objects (CSO).

The actual number of nearest neighbors could be larger than knn, if an object has neighbors of the same distances.

Based on the distances of the neighbors, a density can be computed for each object. Objects with local maximum density are defined as CSOs. The initial outliers are defined as objects with local minimum density which is less than mean( density ) + thd * stdev( density );

Examples found in repository?
examples/sample.rs (line 66)
55fn main() -> io::Result<()> {
56    let filename = env::args().nth(1);
57    if filename.is_none() {
58        eprintln!("No input file");
59        exit(1);
60    }
61    let data = read_data(io::BufReader::new(File::open(filename.unwrap())?))?;
62    let flame = DistanceGraph::build(&data, distance::euclidean);
63
64    print!("Detecting Cluster Supporting Objects ...");
65    io::stdout().flush()?;
66    let supports = flame.find_supporting_objects(10, -2.0);
67    println!("done, found {}", supports.count());
68
69    print!("Propagating fuzzy memberships ... ");
70    io::stdout().flush()?;
71    let fuzzyships = supports
72        .approximate_fuzzy_memberships(500, 1e-6)
73        .assign_outliers();
74    println!("done");
75
76    print!("Defining clusters from fuzzy memberships ... ");
77    io::stdout().flush()?;
78    let (clusters, outliers) = fuzzyships.make_clusters(-1.0);
79    println!("done");
80
81    for (i, cluster) in clusters.iter().enumerate() {
82        print!("\nCluster {:3}, with {:6} members:\n", i + 1, cluster.len());
83        print_cluster(cluster);
84    }
85    print!("\nCluster outliers, with {:6} members:\n", outliers.len());
86    print_cluster(&outliers);
87
88    Ok(())
89}

Trait Implementations§

Source§

impl Debug for DistanceGraph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.