From fa2ced8062514f1e53b227989667e298cd8795af Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Sat, 22 Oct 2022 20:19:27 +0200 Subject: let lsb inform index block allocation between hands --- srchr/src/config.rs | 6 +++--- srchr/src/layout.rs | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'srchr') diff --git a/srchr/src/config.rs b/srchr/src/config.rs index 60cd80c..f89aa18 100644 --- a/srchr/src/config.rs +++ b/srchr/src/config.rs @@ -16,13 +16,13 @@ U V W X Y Z . , / ' // Tournament parameters pub const NUM_CONTESTANTS: usize = 256; pub const NUM_PERSIST: usize = 8; -pub const MAX_NUM_TRANSPOSITIONS: usize = 15; +pub const MAX_NUM_TRANSPOSITIONS: usize = 6; // Fitness parameters pub const STANDARD_DSFB_WEIGHT: f32 = 1.0 / 3.0; pub const INDEX_DSFB_WEIGHT: f32 = 1.0 / 3.0; -pub const MIN_INDEX_USAGE_PERCENT: f32 = 0.10; +pub const MIN_INDEX_USAGE_PERCENT: f32 = 0.12; pub fn index_usage_fitness(index_perc: f32) -> f32 { if index_perc < MIN_INDEX_USAGE_PERCENT { MIN_INDEX_USAGE_PERCENT - index_perc @@ -31,7 +31,7 @@ pub fn index_usage_fitness(index_perc: f32) -> f32 { } } -pub const MAX_PINKY_USAGE_PERCENT: f32 = 0.085; +pub const MAX_PINKY_USAGE_PERCENT: f32 = 0.092; pub fn pinky_col_penalty(lesser_perc: f32, greater_perc: f32) -> f32 { if greater_perc > MAX_PINKY_USAGE_PERCENT { if lesser_perc > MAX_PINKY_USAGE_PERCENT { diff --git a/srchr/src/layout.rs b/srchr/src/layout.rs index 8f8b03a..e6ac862 100644 --- a/srchr/src/layout.rs +++ b/srchr/src/layout.rs @@ -167,7 +167,31 @@ impl Layout { } let w_index_columns = weight_function(&pl.index_columns, corpus); - let (left_ind, right_ind) = if balance >= 0.0 { (0, 1) } else { (1, 0) }; + // Choose index order to minimise LSB (middle-index only) even though we + // don't directly optimise for this parameter + let mut lsbs = [0.0; 2]; + for option in [0, 1] { + for left in [true, false] { + let mind = if left { 2 } else { 7 }; + let side = if left { option } else { 1 - option }; + let m1 = keys[mind + 10 * 0] as u8; + let m2 = keys[mind + 10 * 1] as u8; + let m3 = keys[mind + 10 * 2] as u8; + let i1 = w_index_columns[side].0[3]; + let i2 = w_index_columns[side].0[4]; + let i3 = w_index_columns[side].0[5]; + lsbs[option] += corpus.get_bigram_perc(m1, i1) + + corpus.get_bigram_perc(m1, i2) + + corpus.get_bigram_perc(m1, i3) + + corpus.get_bigram_perc(m2, i1) + + corpus.get_bigram_perc(m2, i2) + + corpus.get_bigram_perc(m2, i3) + + corpus.get_bigram_perc(m3, i1) + + corpus.get_bigram_perc(m3, i2) + + corpus.get_bigram_perc(m3, i3); + } + } + let (left_ind, right_ind) = if lsbs[0] < lsbs[1] { (0, 1) } else { (1, 0) }; for j in 0..3 { keys[3 + j * ROW_LENGTH] = w_index_columns[left_ind].0[j] as char; keys[6 + j * ROW_LENGTH] = w_index_columns[right_ind].0[j] as char; -- cgit v1.3.1