Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: impl MeanN over generic dimension #312

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/distribution/multinomial.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::distribution::Discrete;
use crate::function::factorial;
use crate::statistics::*;
use nalgebra::{DVector, Dim, Dyn, OMatrix, OVector};
use nalgebra::{Dim, Dyn, OMatrix, OVector};

/// Implements the
/// [Multinomial](https://en.wikipedia.org/wiki/Multinomial_distribution)
Expand Down Expand Up @@ -203,7 +203,7 @@ where
res
}

impl<D> MeanN<DVector<f64>> for Multinomial<D>
impl<D> MeanN<OVector<f64, D>> for Multinomial<D>
where
D: Dim,
nalgebra::DefaultAllocator: nalgebra::allocator::Allocator<D>,
Expand All @@ -218,10 +218,8 @@ where
///
/// where `n` is the number of trials, `p_i` is the `i`th probability,
/// and `k` is the total number of probabilities
fn mean(&self) -> Option<DVector<f64>> {
Some(DVector::from_vec(
self.p.iter().map(|x| x * self.n as f64).collect(),
))
fn mean(&self) -> Option<OVector<f64, D>> {
Some(self.p.map(|x| x * self.n as f64))
}
}

Expand Down
Loading