private bool Assign() { var numClusters = _clusters.Count; var isChanged = false; var distances = new double[numClusters]; foreach (var t in _items) { for (var k = 0; k < numClusters; k++) { distances[k] = _metric.Distance(t, _clusters[k].Centroid); } var newClusterId = _metric.MinIndex(distances); if (newClusterId == t.ClusterId) { continue; } isChanged = true; t.SetCluster(newClusterId); } return(isChanged); }