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

    let num_data_points = data_len / num_dimensions;
    let mut centroids = vec![0.0; k * num_dimensions];
    for dim_index in 0..num_dimensions {

        // Find the max and min values for this dimension.
        let mut min = 0.0;
        let mut max = 0.0;
        for point_index in 0..num_data_points {
            let data_index = dim_index + (point_index * num_dimensions);

            if point_index == 0 {
                min = data[data_index];
                max = min;
            }
            else if data[data_index] < min {
                min = data[data_index];
            }
            else if data[data_index] > max {
                max = data[data_index];
            }
        }

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

    // Perform K Means clustering.
    let tags_and_error = kmeans(data, num_dimensions, 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(data: Vec<f64>, num_dimensions: usize, k: usize, max_error: f64, max_iters: usize) -> (Vec<usize>, f64) {
    // Sanity check.
    let data_len = data.len();
    if data_len <= 1 {
        let tags = vec![0, 0];
        return (tags, 0.0);
    }
    let num_data_points = data_len / num_dimensions;
    let mut centroids = vec![0.0; k * num_dimensions];
    for dim_index in 0..num_dimensions {
        // Find the max and min values for this dimension.
        let mut min = 0.0;
        let mut max = 0.0;
        for point_index in 0..num_data_points {
            let data_index = dim_index + (point_index * num_dimensions);
            if point_index == 0 {
                min = data[data_index];
                max = min;
            }
            else if data[data_index] < min {
                min = data[data_index];
            }
            else if data[data_index] > max {
                max = data[data_index];
            }
        }
        // Select the k data points that are farthest apart from each other in this dimension.
        let increment = (max - min) / (k - 1) as f64;
        for i in 0..k {
            centroids[dim_index + (i * num_dimensions)] = min + (increment * i as f64);
        }
    }
    // Perform K Means clustering.
    let tags_and_error = kmeans(data, num_dimensions, k, max_error, max_iters, &mut centroids);
    tags_and_error
}
pub fn kmeans_equally_space_centroids ( data : Vec < f64 > , num_dimensions : usize , k : usize , max_error : f64 , max_iters : usize ) -> ( Vec < usize > , f64 ) { // Sanity check. let data_len = data . len ( ) ; if data_len <= 1 { let tags = vec ! [ 0 0 ] ; return ( tags , 0.0 ) ; } let num_data_points = data_len / num_dimensions ; let mut centroids = vec ! [ 0.0 k num_dimensions ] ; for dim_index in 0 .. num_dimensions { // Find the max and min values for this dimension. let mut min = 0.0 ; let mut max = 0.0 ; for point_index in 0 .. num_data_points { let data_index = dim_index + ( point_index * num_dimensions ) ; if point_index == 0 { min = data [ data_index ] ; max = min ; } else if data [ data_index ] < min { min = data [ data_index ] ; } else if data [ data_index ] > max { max = data [ data_index ] ; } } // Select the k data points that are farthest apart from each other in this dimension. let increment = ( max - min ) / ( k - 1 ) as f64 ; for i in 0 .. k { centroids [ dim_index + ( i * num_dimensions ) ] = min + ( increment * i as f64 ) ; } } // Perform K Means clustering. let tags_and_error = kmeans ( data , num_dimensions , 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>
num_dimensions
usize
k
usize
max_error
f64
max_iters
usize