pub struct ExpectationMaximization {
pub n_components: usize,
pub components: Vec<GmmComponent>,
pub ll_history: Vec<f64>,
pub tol: f64,
}Expand description
Expectation-Maximization for Gaussian Mixture Models.
Supports k-means initialization, BIC criterion for model selection, and full EM convergence.
Fields§
§n_components: usizeNumber of components.
components: Vec<GmmComponent>Mixture components.
ll_history: Vec<f64>Log-likelihood history.
tol: f64Convergence tolerance.
Implementations§
Source§impl ExpectationMaximization
impl ExpectationMaximization
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Creates a new ExpectationMaximization with k-means seeding.
Sourcepub fn kmeans_init(&mut self, data: &[f64])
pub fn kmeans_init(&mut self, data: &[f64])
Initializes component means via k-means (one pass, sorted data).
Sourcepub fn log_likelihood(&self, data: &[f64]) -> f64
pub fn log_likelihood(&self, data: &[f64]) -> f64
Computes log-likelihood of data under current model.
Sourcepub fn bic(&self, data: &[f64]) -> f64
pub fn bic(&self, data: &[f64]) -> f64
Computes the Bayesian Information Criterion.
BIC = k ln(n) - 2 ln(L̂)
Sourcepub fn fit(&mut self, data: &[f64], max_iter: usize) -> f64
pub fn fit(&mut self, data: &[f64], max_iter: usize) -> f64
Runs the EM algorithm.
Returns the final log-likelihood.
Sourcepub fn predict(&self, x: f64) -> usize
pub fn predict(&self, x: f64) -> usize
Predicts cluster assignment (most likely component) for a data point.
Sourcepub fn normalized_weights(&self) -> Vec<f64>
pub fn normalized_weights(&self) -> Vec<f64>
Returns component weights normalized to sum to 1.
Trait Implementations§
Source§impl Clone for ExpectationMaximization
impl Clone for ExpectationMaximization
Source§fn clone(&self) -> ExpectationMaximization
fn clone(&self) -> ExpectationMaximization
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ExpectationMaximization
impl RefUnwindSafe for ExpectationMaximization
impl Send for ExpectationMaximization
impl Sync for ExpectationMaximization
impl Unpin for ExpectationMaximization
impl UnsafeUnpin for ExpectationMaximization
impl UnwindSafe for ExpectationMaximization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.