diff options
| author | tslil clingman <tslil@posteo.de> | 2022-10-22 22:50:55 +0200 |
|---|---|---|
| committer | tslil clingman <tslil@posteo.de> | 2022-10-22 22:50:55 +0200 |
| commit | 677bba1a9043d6f8a728c26d4c3126ac1b6ab9b7 (patch) | |
| tree | 153e224582d90cc6dd4c0818728a936914288ea1 /srchr/src/layout.rs | |
| parent | fa2ced8062514f1e53b227989667e298cd8795af (diff) | |
knob for lsb vs balance
Diffstat (limited to 'srchr/src/layout.rs')
| -rw-r--r-- | srchr/src/layout.rs | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/srchr/src/layout.rs b/srchr/src/layout.rs index e6ac862..2b8cf05 100644 --- a/srchr/src/layout.rs +++ b/srchr/src/layout.rs @@ -167,31 +167,38 @@ impl Layout { } let w_index_columns = weight_function(&pl.index_columns, corpus); - // 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 MINIMISE_LSB_INSTEAD_OF_OPTIMISING_BALANCE { + // 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); + } } + (left_ind, right_ind) = if lsbs[0] < lsbs[1] { (0, 1) } else { (1, 0) } + } else { + (left_ind, right_ind) = if balance >= 0.0 { (0, 1) } else { (1, 0) } } - 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; |
