Skip to content

Commit

Permalink
fix(rarity): use right amount of values for mean calculation (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMoesl committed Mar 9, 2021
1 parent 883821b commit c365767
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/engine/rarity_simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,16 @@ fn select_rarest(
fn score_with_mean(states: &[&State], mean: MeanType) -> (Vec<f64>, Ordering) {
match mean {
MeanType::Harmonic => {
let scores = compute_scores(states, |n, cs| {
(n as f64) / cs.iter().map(|c| 1_f64 / (*c as f64)).sum::<f64>()
let scores = compute_scores(states, |cs| {
(cs.len() as f64) / cs.iter().map(|c| 1_f64 / (*c as f64)).sum::<f64>()
});

(scores, Ordering::Greater)
}
MeanType::Arithmetic => {
let scores = compute_scores(states, |n, cs| cs.iter().sum::<u64>() as f64 / (n as f64));
let scores = compute_scores(states, |cs| {
cs.iter().sum::<u64>() as f64 / (cs.len() as f64)
});

(scores, Ordering::Less)
}
Expand Down Expand Up @@ -1145,7 +1147,7 @@ impl fmt::Display for RarityBugInfo {
/// * score: A function taking the amount of states and relevant statistical counter values and returning a score
fn compute_scores<F>(states: &[&State], score: F) -> Vec<f64>
where
F: Fn(usize, &[Counter]) -> f64,
F: Fn(&[Counter]) -> f64,
{
let counter_addresses: Vec<Vec<Address>> = states
.iter()
Expand All @@ -1161,8 +1163,6 @@ where
.for_each(|address| count_address(&mut overall_counts, *address));

// create counters per state based on overall counts
let n = states.len();

counter_addresses
.iter()
.map(|addresses| {
Expand All @@ -1175,7 +1175,7 @@ where
})
.collect_vec()
})
.map(|addresses| score(n, &addresses[..]))
.map(|addresses| score(&addresses[..]))
.collect()
}

Expand Down

0 comments on commit c365767

Please sign in to comment.