pub struct DistanceGraph { /* private fields */ }
Implementations§
Source§impl DistanceGraph
impl DistanceGraph
Sourcepub fn build<'a, V, F>(data: &'a [V], distfunc: F) -> DistanceGraph
pub fn build<'a, V, F>(data: &'a [V], distfunc: F) -> DistanceGraph
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}
Sourcepub fn neighbors(&self, id: usize) -> impl Iterator<Item = (usize, f64)> + '_
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.
Sourcepub fn find_supporting_objects(
&self,
knn: usize,
thd: f64,
) -> ClusterSupportingObjects
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§
Auto Trait Implementations§
impl Freeze for DistanceGraph
impl RefUnwindSafe for DistanceGraph
impl Send for DistanceGraph
impl Sync for DistanceGraph
impl Unpin for DistanceGraph
impl UnwindSafe for DistanceGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more