Skip to content

Commit

Permalink
feat: implement Mode for multinomial
Browse files Browse the repository at this point in the history
lint: remove unused imports
  • Loading branch information
YeungOnion committed Sep 24, 2024
1 parent d03805c commit e6d5f6a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/distribution/multinomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ where
res
}

impl<D> Mode<OVector<u64, D>> for Multinomial<D>
where
D: Dim,
nalgebra::DefaultAllocator: nalgebra::allocator::Allocator<u64, D>,
nalgebra::DefaultAllocator: nalgebra::allocator::Allocator<f64, D>,
{
fn mode(&self) -> OVector<u64, D> {
let n = self.n() as f64;
let (nr, nc) = self.p.shape_generic();
OVector::<u64, D>::from_iterator_generic(
nr,
nc,
self.p.iter().map(|&p| ((n + 1.0) * p).floor() as u64),
)
}
}

impl<D> MeanN<DVector<f64>> for Multinomial<D>
where
D: Dim,
Expand Down

0 comments on commit e6d5f6a

Please sign in to comment.