[lab2] Minor fixes in algo

This commit is contained in:
Andrew Golovashevich 2026-01-30 02:54:27 +03:00
parent 50e2fa9a64
commit c5a5faf996
2 changed files with 6 additions and 5 deletions

View File

@ -8,13 +8,12 @@ pub fn adaptiveResonanceTheoryImpl(
attentiveness: f64,
) -> Box<[usize]> {
let mut prototypes = Vec::<BitVector>::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());
}

View File

@ -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;
}