pub struct KMeansControl {
pub seed: u64,
pub max_iterations: usize,
pub tolerance: f64,
pub max_work: u64,
pub restarts: usize,
}Expand description
Deterministic initialization, convergence, restart, and work policy for k-means.
Fields§
§seed: u64Root seed from which bounded restart seeds are derived.
max_iterations: usizeMaximum number of complete Lloyd updates per restart.
tolerance: f64Maximum centroid displacement accepted as convergence.
max_work: u64Hard bound on point-to-centroid distance evaluations across all restarts.
restarts: usizeMaximum number of independently seeded candidate results.
Implementations§
Source§impl KMeansControl
impl KMeansControl
Sourcepub fn new(
seed: u64,
max_iterations: usize,
tolerance: f64,
max_work: u64,
restarts: usize,
) -> Result<Self, ClusteringError>
pub fn new( seed: u64, max_iterations: usize, tolerance: f64, max_work: u64, restarts: usize, ) -> Result<Self, ClusteringError>
Builds checked k-means control.
Examples found in repository?
examples/clustering_evidence.rs (line 18)
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 KMeansControl
impl Clone for KMeansControl
Source§fn clone(&self) -> KMeansControl
fn clone(&self) -> KMeansControl
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 moreimpl Copy for KMeansControl
Source§impl Debug for KMeansControl
impl Debug for KMeansControl
Source§impl Default for KMeansControl
impl Default for KMeansControl
Source§impl PartialEq for KMeansControl
impl PartialEq for KMeansControl
impl StructuralPartialEq for KMeansControl
Auto Trait Implementations§
impl Freeze for KMeansControl
impl RefUnwindSafe for KMeansControl
impl Send for KMeansControl
impl Sync for KMeansControl
impl Unpin for KMeansControl
impl UnsafeUnpin for KMeansControl
impl UnwindSafe for KMeansControl
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