Skip to content

Commit

Permalink
Fix typical sampling.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed May 24, 2024
1 parent 3391f3f commit 39fd373
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/ai00-core/src/sampler/typical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ impl Sampler for TypicalSampler {
fn sample(&mut self, probs: &[f32]) -> u16 {
let TypicalSampler { params, state } = self;

let entropy = -probs.iter().map(|x| x * x.ln()).sum::<f32>();
let probs = probs.iter().map(|&x| (x, x.ln())).collect_vec();
let entropy = -probs.iter().map(|(x, y)| x * y).sum::<f32>();
let sorted = probs
.iter()
.map(|&x| (x, (x - entropy).abs()))
.into_iter()
.map(|(x, y)| (x, (-y - entropy).abs()))
.enumerate()
.sorted_unstable_by(|(_, (_, x)), (_, (_, y))| x.total_cmp(y))
.map(|(id, (x, _))| (id, x))
Expand Down

0 comments on commit 39fd373

Please sign in to comment.