From 889f8ce34e1d0e96aa99c9772e5f617fdbdd8e21 Mon Sep 17 00:00:00 2001 From: hkctkuy Date: Mon, 26 Feb 2024 14:28:38 +0300 Subject: [PATCH] Fixes --- casr/src/bin/casr-cluster.rs | 2 +- libcasr/src/cluster.rs | 16 +++++++++------- libcasr/src/stacktrace.rs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/casr/src/bin/casr-cluster.rs b/casr/src/bin/casr-cluster.rs index 573c5df6..83971af2 100644 --- a/casr/src/bin/casr-cluster.rs +++ b/casr/src/bin/casr-cluster.rs @@ -479,7 +479,7 @@ fn hierarchical_accumulation( // New clusters let mut news: HashMap = HashMap::new(); let mut new_num = max; - for &num in res.iter().skip(clusters.len()).take(deviants.len()) { + for &num in res.iter().skip(clusters.len()) { if numbers.contains_key(&num) { continue; } diff --git a/libcasr/src/cluster.rs b/libcasr/src/cluster.rs index 69bb2c35..d0e45663 100644 --- a/libcasr/src/cluster.rs +++ b/libcasr/src/cluster.rs @@ -197,15 +197,17 @@ impl Cluster { /// Get complete distance between cluster and report /// NOTE: Result also can be interpreted as diameter of cluster merge result pub fn dist_rep(cluster: &Cluster, report: &ReportInfo) -> f64 { - let mut max = 0f64; let (_, (trace, _)) = report; - for stacktrace in cluster.stacktraces() { - let dist = 1.0 - similarity(stacktrace, trace); - if dist > max { - max = dist; - } + if let Some(max) = cluster + .stacktraces() + .iter() + .map(|s| 1.0 - similarity(s, trace)) + .max_by(|a, b| a.total_cmp(b)) + { + max + } else { + 0f64 } - max } } diff --git a/libcasr/src/stacktrace.rs b/libcasr/src/stacktrace.rs index af5175af..f68c2959 100644 --- a/libcasr/src/stacktrace.rs +++ b/libcasr/src/stacktrace.rs @@ -195,7 +195,7 @@ pub fn dedup_stacktraces(stacktraces: &[Stacktrace]) -> Vec { /// /// * `matrix` - condensed dissimilarity matrix /// -/// * `len` - matrix length +/// * `len` - number of observations that are being clustered /// /// # Return value ///