aboutsummaryrefslogtreecommitdiff
path: root/srchr/src/evaluation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'srchr/src/evaluation.rs')
-rw-r--r--srchr/src/evaluation.rs139
1 files changed, 78 insertions, 61 deletions
diff --git a/srchr/src/evaluation.rs b/srchr/src/evaluation.rs
index aba3501..a855d89 100644
--- a/srchr/src/evaluation.rs
+++ b/srchr/src/evaluation.rs
@@ -5,8 +5,8 @@ use crate::output::*;
use std::fmt;
-pub fn prelayout_fitness(corpus: &Corpus, layout: &Prelayout) -> u32 {
- let mut score: u32 = 0;
+pub fn prelayout_fitness(corpus: &Corpus, layout: &Prelayout) -> f32 {
+ let mut score: f32 = 0.0;
for i in 0..6 {
let keys = layout.get_standard_column(i);
@@ -14,9 +14,14 @@ pub fn prelayout_fitness(corpus: &Corpus, layout: &Prelayout) -> u32 {
let k2 = keys[1];
let k3 = keys[2];
- score += corpus.get_bigram_count(k1, k2)
- + corpus.get_bigram_count(k1, k3)
- + corpus.get_bigram_count(k2, k3);
+ score += corpus.get_bigram_perc(k1, k2)
+ + corpus.get_bigram_perc(k1, k3)
+ + corpus.get_bigram_perc(k2, k3);
+
+ score += (corpus.get_skipgram_perc(k1, k2)
+ + corpus.get_skipgram_perc(k1, k3)
+ + corpus.get_skipgram_perc(k2, k3))
+ * STANDARD_DSFB_WEIGHT;
}
for i in 0..2 {
@@ -28,41 +33,42 @@ pub fn prelayout_fitness(corpus: &Corpus, layout: &Prelayout) -> u32 {
let k5 = keys[4];
let k6 = keys[5];
- // We want index usage!
- let index_count: u32 = keys.iter().map(|&k| corpus.get_character_count(k)).sum();
- score += index_usage_fitness(corpus.get_index_threshold(), index_count);
+ let index_percs = keys.iter().map(|&k| corpus.get_character_count(k)).sum();
+ score += index_usage_fitness(corpus.get_total_count(), index_percs);
- score += corpus.get_bigram_count(k1, k2)
- + corpus.get_bigram_count(k1, k3)
- + corpus.get_bigram_count(k2, k3)
- + corpus.get_bigram_count(k4, k5)
- + corpus.get_bigram_count(k4, k6)
- + corpus.get_bigram_count(k5, k6)
- + corpus.get_bigram_count(k1, k4)
- + corpus.get_bigram_count(k1, k5)
- + corpus.get_bigram_count(k1, k6)
- + corpus.get_bigram_count(k2, k4)
- + corpus.get_bigram_count(k2, k5)
- + corpus.get_bigram_count(k2, k6)
- + corpus.get_bigram_count(k3, k4)
- + corpus.get_bigram_count(k3, k5)
- + corpus.get_bigram_count(k3, k6);
+ score += corpus.get_bigram_perc(k1, k2)
+ + corpus.get_bigram_perc(k1, k3)
+ + corpus.get_bigram_perc(k2, k3)
+ + corpus.get_bigram_perc(k4, k5)
+ + corpus.get_bigram_perc(k4, k6)
+ + corpus.get_bigram_perc(k5, k6)
+ + corpus.get_bigram_perc(k1, k4)
+ + corpus.get_bigram_perc(k1, k5)
+ + corpus.get_bigram_perc(k1, k6)
+ + corpus.get_bigram_perc(k2, k4)
+ + corpus.get_bigram_perc(k2, k5)
+ + corpus.get_bigram_perc(k2, k6)
+ + corpus.get_bigram_perc(k3, k4)
+ + corpus.get_bigram_perc(k3, k5)
+ + corpus.get_bigram_perc(k3, k6);
}
score
}
-#[derive(Copy, Clone)]
pub struct Evaluation {
keypress: [u32; NUM_KEYS],
total_keypress: u32,
- sfb: [u32; 8],
+ total_bigrams: u32,
+ sfb: [f32; 8],
+ dsfb: [f32; 8],
}
impl Evaluation {
pub fn evaluate_layout(corpus: &Corpus, layout: &Layout) -> Evaluation {
let mut keypress: [u32; NUM_KEYS] = [0; NUM_KEYS];
- let mut sfb: [u32; 8] = [0; 8];
+ let mut sfb: [f32; 8] = [0.0; 8];
+ let mut dsfb: [f32; 8] = [0.0; 8];
for (i, &c) in layout.get_keys().iter().enumerate() {
keypress[i] = corpus.get_character_count(c as u8);
@@ -75,55 +81,63 @@ impl Evaluation {
let k2 = layout.get_key(ind + 10 * 1);
let k3 = layout.get_key(ind + 10 * 2);
- sfb[i] = corpus.get_bigram_count(k1, k2)
- + corpus.get_bigram_count(k1, k3)
- + corpus.get_bigram_count(k2, k3);
+ sfb[i] = corpus.get_bigram_perc(k1, k2)
+ + corpus.get_bigram_perc(k1, k3)
+ + corpus.get_bigram_perc(k2, k3);
+
+ dsfb[i] = corpus.get_skipgram_perc(k1, k2)
+ + corpus.get_skipgram_perc(k1, k3)
+ + corpus.get_skipgram_perc(k2, k3);
if i == 3 {
let k4 = layout.get_key(4 + 10 * 0);
let k5 = layout.get_key(4 + 10 * 1);
let k6 = layout.get_key(4 + 10 * 2);
- sfb[i] += corpus.get_bigram_count(k4, k5)
- + corpus.get_bigram_count(k4, k6)
- + corpus.get_bigram_count(k5, k6)
- + corpus.get_bigram_count(k1, k4)
- + corpus.get_bigram_count(k1, k5)
- + corpus.get_bigram_count(k1, k6)
- + corpus.get_bigram_count(k2, k4)
- + corpus.get_bigram_count(k2, k5)
- + corpus.get_bigram_count(k2, k6)
- + corpus.get_bigram_count(k3, k4)
- + corpus.get_bigram_count(k3, k5)
- + corpus.get_bigram_count(k3, k6);
+ sfb[i] += corpus.get_bigram_perc(k4, k5)
+ + corpus.get_bigram_perc(k4, k6)
+ + corpus.get_bigram_perc(k5, k6)
+ + corpus.get_bigram_perc(k1, k4)
+ + corpus.get_bigram_perc(k1, k5)
+ + corpus.get_bigram_perc(k1, k6)
+ + corpus.get_bigram_perc(k2, k4)
+ + corpus.get_bigram_perc(k2, k5)
+ + corpus.get_bigram_perc(k2, k6)
+ + corpus.get_bigram_perc(k3, k4)
+ + corpus.get_bigram_perc(k3, k5)
+ + corpus.get_bigram_perc(k3, k6);
} else if i == 4 {
let k4 = layout.get_key(5 + 10 * 0);
let k5 = layout.get_key(5 + 10 * 1);
let k6 = layout.get_key(5 + 10 * 2);
- sfb[i] += corpus.get_bigram_count(k4, k5)
- + corpus.get_bigram_count(k5, k6)
- + corpus.get_bigram_count(k4, k6)
- + corpus.get_bigram_count(k1, k4)
- + corpus.get_bigram_count(k1, k5)
- + corpus.get_bigram_count(k1, k6)
- + corpus.get_bigram_count(k2, k4)
- + corpus.get_bigram_count(k2, k5)
- + corpus.get_bigram_count(k2, k6)
- + corpus.get_bigram_count(k3, k4)
- + corpus.get_bigram_count(k3, k5)
- + corpus.get_bigram_count(k3, k6);
+ sfb[i] += corpus.get_bigram_perc(k4, k5)
+ + corpus.get_bigram_perc(k5, k6)
+ + corpus.get_bigram_perc(k4, k6)
+ + corpus.get_bigram_perc(k1, k4)
+ + corpus.get_bigram_perc(k1, k5)
+ + corpus.get_bigram_perc(k1, k6)
+ + corpus.get_bigram_perc(k2, k4)
+ + corpus.get_bigram_perc(k2, k5)
+ + corpus.get_bigram_perc(k2, k6)
+ + corpus.get_bigram_perc(k3, k4)
+ + corpus.get_bigram_perc(k3, k5)
+ + corpus.get_bigram_perc(k3, k6);
}
}
return Evaluation {
keypress,
total_keypress: corpus.get_total_count(),
+ total_bigrams: corpus.get_total_bigrams(),
sfb,
+ dsfb,
};
}
fn output_eval(&self) -> String {
let mut result = String::new();
let tot = self.total_keypress as f32;
+ let big = self.total_bigrams as f32;
+ let tig = self.total_bigrams as f32;
result += &"Percent per key:\n";
result += &format_block_output(self.keypress.into_iter().map(|k| 100.0 * k as f32 / tot));
@@ -148,17 +162,20 @@ impl Evaluation {
result += &format!("\nHand usage: {:.2}% vs {:.2}%", lh, rh);
- result += "\nSame finger bigrams: ";
+ result += "\nSFB distribution : ";
for (i, &u) in self.sfb.iter().enumerate() {
- result += &format!(
- "{:>6.3}%{}",
- u as f32 / tot * 100.0,
- if i < 7 { ", " } else { "" }
- );
+ result += &format!("{:>6.3}%{}", u * 100.0, if i < 7 { ", " } else { "" });
+ }
+
+ result += "\nDSFB distribution: ";
+ for (i, &u) in self.dsfb.iter().enumerate() {
+ result += &format!("{:>6.3}%{}", u * 100.0, if i < 7 { ", " } else { "" });
}
- let sfb = self.sfb.iter().sum::<u32>();
- result += &format!("\nTotal sfb: {:.2}% ({})", sfb as f32 / tot * 100.0, sfb);
+ let sfb = self.sfb.iter().sum::<f32>();
+ let dsfb = self.dsfb.iter().sum::<f32>();
+ result += &format!("\nTotal sfb: {:.3}% ({:.0})", sfb * 100.0, sfb * big);
+ result += &format!("\nTotal dsfb: {:.3}% ({:.0})", dsfb * 100.0, dsfb * tig);
return result;
}