diff --git a/lab2/src/algo/impl.rs b/lab2/src/algo/impl.rs index cc506f9..8eadb8d 100644 --- a/lab2/src/algo/impl.rs +++ b/lab2/src/algo/impl.rs @@ -8,13 +8,12 @@ pub fn adaptiveResonanceTheoryImpl( attentiveness: f64, ) -> Box<[usize]> { let mut prototypes = Vec::::new(); - let mut groups = vec![0usize, data.len()].into_boxed_slice(); + let mut groups = vec![0usize; data.len()].into_boxed_slice(); match data.get(0) { None => return groups, Some(p) => prototypes.push(p.clone()), } - prototypes.push(data[0].clone()); 'elements: for i in 1..data.len() { for j in 0..prototypes.len() { @@ -28,6 +27,7 @@ pub fn adaptiveResonanceTheoryImpl( continue 'elements; } + groups[i] = prototypes.len(); prototypes.push(data[i].clone()); } diff --git a/lab2/src/algo/operations.rs b/lab2/src/algo/operations.rs index 57ad7a6..02455ea 100644 --- a/lab2/src/algo/operations.rs +++ b/lab2/src/algo/operations.rs @@ -2,9 +2,10 @@ use super::BitVector; use eframe::emath::Numeric; pub(super) fn similarityCheck(prototype: &BitVector, vector: &BitVector, beta: usize) -> bool { - return ((prototype & vector).count1() / (beta + prototype.count1())) - > (vector.count1() / (beta + vector.len())); + let l = (prototype & vector).count1().to_f64() / (beta + prototype.count1()).to_f64(); + let r = vector.count1().to_f64() / (beta + vector.len()).to_f64(); + return l > r; } pub(super) fn attentivenessTest(prototype: &BitVector, vector: &BitVector, p: f64) -> bool { - return ((prototype & vector).count1() / (vector.count1())).to_f64() < p; + return ((prototype & vector).count1().to_f64() / vector.count1().to_f64()) >= p; }