Skip to main content

GmmControl

Struct GmmControl 

Source
pub struct GmmControl {
    pub seed: u64,
    pub max_iterations: usize,
    pub tolerance: f64,
    pub max_work: u64,
}
Expand description

Deterministic convergence and work policy for Gaussian-mixture EM.

Fields§

§seed: u64

Seed used by k-means++ mean initialization.

§max_iterations: usize

Maximum number of accepted EM updates.

§tolerance: f64

Relative log-likelihood convergence tolerance.

§max_work: u64

Hard bound on initialization, responsibility, and parameter-update work.

Implementations§

Source§

impl GmmControl

Source

pub fn new( seed: u64, max_iterations: usize, tolerance: f64, max_work: u64, ) -> Result<Self, ClusteringError>

Builds checked EM control.

Examples found in repository?
examples/clustering_evidence.rs (line 41)
6fn main() {
7    let points = vec![
8        vec![-3.1, -3.0],
9        vec![-3.0, -2.9],
10        vec![-2.9, -3.1],
11        vec![4.9, 5.0],
12        vec![5.0, 5.1],
13        vec![5.1, 4.9],
14    ];
15    let kmeans = fit_kmeans(
16        &points,
17        2,
18        KMeansControl::new(4, 50, 1.0e-10, 20_000, 4).expect("control"),
19    )
20    .expect("bounded k-means");
21    let selected = &kmeans.restarts[kmeans.selected_restart];
22    println!(
23        "kmeans centroids={:?} inertia={:.6} selected={} restarts={} converged={} work={}",
24        kmeans.model.centroids,
25        selected.inertia,
26        kmeans.selected_restart,
27        kmeans.restarts.len(),
28        selected.converged,
29        kmeans.work
30    );
31
32    let gmm = fit_gmm(
33        &points,
34        GmmSpec::new(
35            2,
36            CovarianceType::Diagonal,
37            1.0e-6,
38            SingularComponentPolicy::default(),
39        )
40        .expect("spec"),
41        GmmControl::new(4, 50, 1.0e-9, 100_000).expect("control"),
42    )
43    .expect("regularized GMM");
44    println!(
45        "gmm means={:?} likelihood={:.6} iterations={} converged={} repairs={} aic={:.6} bic={:.6} work={}",
46        gmm.model.means,
47        gmm.evidence.log_likelihood,
48        gmm.evidence.iterations,
49        gmm.evidence.converged,
50        gmm.evidence.singular_component_repairs,
51        gmm.evidence.model_selection.aic,
52        gmm.evidence.model_selection.bic,
53        gmm.evidence.work
54    );
55}

Trait Implementations§

Source§

impl Clone for GmmControl

Source§

fn clone(&self) -> GmmControl

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GmmControl

Source§

impl Debug for GmmControl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GmmControl

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for GmmControl

Source§

fn eq(&self, other: &GmmControl) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GmmControl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.