pub struct GmmSpec {
pub components: usize,
pub covariance: CovarianceType,
pub regularization: f64,
pub singular_policy: SingularComponentPolicy,
}Expand description
Component count, covariance family, regularization, and singular policy.
Fields§
§components: usizeNumber of Gaussian components.
covariance: CovarianceTypeCovariance representation shared by all components.
regularization: f64Positive value added to every fitted covariance diagonal.
singular_policy: SingularComponentPolicyExplicit behavior for empty or numerically singular components.
Implementations§
Source§impl GmmSpec
impl GmmSpec
Sourcepub fn new(
components: usize,
covariance: CovarianceType,
regularization: f64,
singular_policy: SingularComponentPolicy,
) -> Result<Self, ClusteringError>
pub fn new( components: usize, covariance: CovarianceType, regularization: f64, singular_policy: SingularComponentPolicy, ) -> Result<Self, ClusteringError>
Builds a checked regularized mixture specification.
Examples found in repository?
examples/clustering_evidence.rs (lines 34-39)
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§
impl Copy for GmmSpec
impl StructuralPartialEq for GmmSpec
Auto Trait Implementations§
impl Freeze for GmmSpec
impl RefUnwindSafe for GmmSpec
impl Send for GmmSpec
impl Sync for GmmSpec
impl Unpin for GmmSpec
impl UnsafeUnpin for GmmSpec
impl UnwindSafe for GmmSpec
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