pub fn kmeans_equally_space_centroids_1_d(data: Vec<f64>, k: usize, max_error: f64, max_iters: usize) -> (Vec<usize>, f64) {
    // Sanity check.
    if data.len() <= 1 {
        let tags = vec![0, 0];
        return (tags, 0.0);
    }

    let mut centroids = vec![0.0; k];

    // Select the k data points that are farthest apart from each other.
    let min = statistics::min_f64(&data);
    let max = statistics::max_f64(&data);
    let increment = (max - min) / (k - 1) as f64;
    centroids[0] = min;
    centroids[k - 1] = max;
    for i in 0..k {
        centroids[i] = min + (increment * i as f64);
    }

    // Perform K Means clustering.
    let tags_and_error = kmeans_1_d(data, k, max_error, max_iters, &mut centroids);
    tags_and_error
}
/// Calculates evenly spaced initial centroids and then calls kmeans.
Calculates evenly spaced initial centroids and then calls kmeans.
Calculates evenly spaced initial centroids and then calls kmeans .
pub fn kmeans_equally_space_centroids_1_d(data: Vec<f64>, k: usize, max_error: f64, max_iters: usize) -> (Vec<usize>, f64) {
    // Sanity check.
    if data.len() <= 1 {
        let tags = vec![0, 0];
        return (tags, 0.0);
    }
    let mut centroids = vec![0.0; k];
    // Select the k data points that are farthest apart from each other.
    let min = statistics::min_f64(&data);
    let max = statistics::max_f64(&data);
    let increment = (max - min) / (k - 1) as f64;
    centroids[0] = min;
    centroids[k - 1] = max;
    for i in 0..k {
        centroids[i] = min + (increment * i as f64);
    }
    // Perform K Means clustering.
    let tags_and_error = kmeans_1_d(data, k, max_error, max_iters, &mut centroids);
    tags_and_error
}
pub fn kmeans_equally_space_centroids_1_d ( data : Vec < f64 > , k : usize , max_error : f64 , max_iters : usize ) -> ( Vec < usize > , f64 ) { // Sanity check. if data . len ( ) <= 1 { let tags = vec ! [ 0 0 ] ; return ( tags , 0.0 ) ; } let mut centroids = vec ! [ 0.0 k ] ; // Select the k data points that are farthest apart from each other. let min = statistics :: min_f64 ( & data ) ; let max = statistics :: max_f64 ( & data ) ; let increment = ( max - min ) / ( k - 1 ) as f64 ; centroids [ 0 ] = min ; centroids [ k - 1 ] = max ; for i in 0 .. k { centroids [ i ] = min + ( increment * i as f64 ) ; } // Perform K Means clustering. let tags_and_error = kmeans_1_d ( data , k , max_error , max_iters , & mut centroids ) ; tags_and_error }
Calculates evenly spaced initial centroids and then calls kmeans.
Calculates evenly spaced initial centroids and then calls kmeans .
data
Vec<f64>
k
usize
max_error
f64
max_iters
usize