stat calculation updates

This commit is contained in:
2024-06-17 21:54:13 +02:00
parent a98eaeb30e
commit 5e6a6c62bf
4 changed files with 40 additions and 19 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ fn main() {
};
for mutator in mutators {
let mutated = mutator.mutate(&img);
let filename = "mut".to_string() + &mutator.tag() + &"jpg".to_string();
let filename = "mut".to_string() + &mutator.tag() + &"png".to_string();
println!("Saving to {}", filename);
mutated.save(filename).expect("Saving image failed");
if cfg.show_images {
+19 -7
View File
@@ -76,10 +76,10 @@ fn main() {
}
// Create PR-curve graphs from stores
let max_threshold = 8;
for store in &stores {
println!("Store for {}: ", store.descriptor.info());
//store.print_stats();
let stats = store.get_stats(16);
println!("Stats for {}", store.descriptor.info());
let stats = store.get_stats(max_threshold);
let filename = format!("{}-pr.png", store.descriptor.info());
let root = BitMapBackend::new(&filename, (1024, 768)).into_drawing_area();
root.fill(&WHITE).unwrap();
@@ -104,17 +104,29 @@ fn main() {
let mut i = 0;
for mutator_stats in stats {
// And we can draw something in the drawing area
let pr_curve = mutator_stats.pr_curve();
let pr_curve = mutator_stats.pr_curve(max_threshold);
println!("{}:", mutator_stats.name);
for (x, y) in pr_curve.clone() {
println!("{}, {}", x, y);
}
let color = colors[i % n];
chart.draw_series(LineSeries::new(
pr_curve,
color,
)).unwrap()
color.filled(),
).point_size(2)).unwrap()
.label(mutator_stats.name)
.legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], color));
i += 1;
}
chart.configure_series_labels().border_style(BLACK).draw().unwrap();
//chart.configure_series_labels().border_style(BLACK).draw().unwrap();
chart.configure_series_labels()
.position(SeriesLabelPosition::MiddleLeft)
//.legend_area_size(5)
.border_style(BLACK)
//.background_style(BLUE.mix(0.1))
//.label_font(("Calibri", 20))
.draw()
.unwrap();
//println!("{}", store);
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ impl Mutator for Sharp {
".sharp.".to_string()
}
fn mutate(&self, img: &image::DynamicImage) -> image::DynamicImage {
img.unsharpen(1.2, 50)
img.unsharpen(1.5, 20)
}
}
+19 -10
View File
@@ -59,9 +59,9 @@ impl PRStats {
let r = tpos / (tpos + fneg);
(r, p)
}
pub fn pr_curve(&self) -> Vec<(f64, f64)> {
pub fn pr_curve(&self, threshold: usize) -> Vec<(f64, f64)> {
let mut curve = Vec::new();
for i in 0..64 {
for i in 0..threshold {
curve.push(self.pr(i));
}
curve
@@ -340,6 +340,7 @@ impl DescriptorStore {
);
}
// Seen should only contain a list of base images
let set = self.seen.clone().unwrap();
for image in set.iter() {
let phash = self.get(image).unwrap();
@@ -349,25 +350,33 @@ impl DescriptorStore {
//Assume miss, therefore a false negative
//Undo the miss when there is a true positive
for mutator in &mut mutator_stats {
mutator.false_negatives[threshold as usize] += 1;
mutator.false_negatives[threshold] += 1;
}
for found in self.nn_flat_results(phash, threshold) {
if found.eq(image) || found.ends_with(&format!(".{}", image)) { // True positive
if found.ends_with(&format!(".{}", image)) { // True positive
for mutator in &mut mutator_stats {
if found.starts_with(&mutator.tag) {
debug!("{} is hit for {}", found, mutator.name);
mutator.true_positives[threshold as usize] += 1;
mutator.false_negatives[threshold as usize] -= 1;
mutator.true_positives[threshold] += 1;
mutator.false_negatives[threshold] -= 1;
}
}
} else if found.eq(image) {
continue;
} else { // False positive!
// Mutated misses only count for the mutator
// Unmutated misses count for everyone
for mutator in &mut mutator_stats {
if found.starts_with(&mutator.tag) || !found.starts_with("mut") {
debug!("{} is false positive for {}", found, mutator.name);
mutator.false_positives[threshold as usize] += 1;
if found.starts_with("mut") {
for mutator in &mut mutator_stats {
if found.starts_with(&mutator.tag) {
debug!("{} is false positive for {}", found, mutator.name);
mutator.false_positives[threshold] += 1;
}
}
} else {
for mutator in &mut mutator_stats {
mutator.false_positives[threshold] += 1;
}
}
}