Implement cosine similarity and cosinepair (#327)

* Implement cosine similarity and cosinepair
This commit is contained in:
Lorenzo
2025-09-27 11:08:57 +01:00
committed by GitHub
parent 4841791b7e
commit 09be4681cf
9 changed files with 1018 additions and 12 deletions
+11 -6
View File
@@ -674,15 +674,20 @@ impl<TX: Number + PartialOrd, TY: Number + Ord, X: Array2<TX>, Y: Array1<TY>>
) -> bool {
let (n_rows, n_attr) = visitor.x.shape();
let mut label = Option::None;
let mut label = None;
let mut is_pure = true;
for i in 0..n_rows {
if visitor.samples[i] > 0 {
if label.is_none() {
label = Option::Some(visitor.y[i]);
} else if visitor.y[i] != label.unwrap() {
is_pure = false;
break;
match label {
None => {
label = Some(visitor.y[i]);
}
Some(current_label) => {
if visitor.y[i] != current_label {
is_pure = false;
break;
}
}
}
}
}