Struct cogset::KmeansBuilder [-] [+] [src]

pub struct KmeansBuilder {
    // some fields omitted
}

A builder for k-means to provide control over parameters for the algorithm.

This allows one to tweak settings like the tolerance and the number of iterations.

Examples

use cogset::{Euclid, KmeansBuilder};

let data = [Euclid([0.0, 0.0]),
            Euclid([1.0, 0.5]),
            Euclid([0.2, 0.2]),
            Euclid([0.3, 0.8]),
            Euclid([0.0, 1.0])];

let k = 3;

// we want the means extra precise.
let tol = 1e-12;
let kmeans = KmeansBuilder::new().tolerance(tol).kmeans(&data, k);

println!("{:?}", kmeans.clusters());

Methods

impl KmeansBuilder

fn new() -> KmeansBuilder

Create a default KmeansBuilder

fn tolerance(self, tol: f64) -> KmeansBuilder

Set the tolerance used to decide if the iteration has converged to tol.

fn max_iter(self, max_iter: usize) -> KmeansBuilder

Set the maximum number of iterations to run before aborting to max_iter.

fn kmeans<T>(self, data: &[Euclid<T>], k: usize) -> Kmeans<T> where Euclid<T>: Point + Euclidean + Clone

Run k-means with the given settings.

This is functionally identical to Kmeans::new, other than the internal parameters differing.