SergioFierens/ai4r — pull request #16 by coberlin (2013-07-30 19:36:19+00:00)
Title: Consolidate empty k-means clusters

For certain input data sets, initial centroid assignments, and valid distance metrics, k-means clustering was crashing on empty cluster assignments. For example, the k-means clustering failed on the data given in the unit test 'test_build_and_consolidate_clusters'. Also, the clusterer distance metric is not valid because it returns 0 if one of its arguments is nil. This patch adds a centroid_indices parameter to set the initial centroid assignment, uses the Ai4r::Data::Proximity.squared_euclidean_distance metric (rather than the clusterer distance metric) as the default distance, and adds cluster consolidation when empty clusters arise during k-means clustering.