func (this *KMeans) AssignClusters(data [][]float64) int { swaps := 0 newClusters := [][]int{} for j := 0; j < this.k; j++ { newClusterList := []int{} newClusters = append(newClusters, newClusterList) } for clusterid := 0; clusterid < this.k; clusterid++ { for _, member := range this.clusters[clusterid] { nearest := utils.FindNearestDistance(data[member], this.means) newClusters[nearest] = append(newClusters[nearest], member) if nearest != clusterid { swaps++ } } } this.clusters = newClusters return swaps }
func (this *KMeans) AssignClusters(data [][]float64) int { swaps := 0; newClusters := [][]int{}; for j := 0; j < this.k; j++ { newClusterList := []int{}; append(newClusters, newClusterList); } for clusterid := 0; clusterid < this.k; clusterid++ { for _, member := this.clusters[clusterid] { nearest := utils.FindNearestDistance(data[member], this.means); append(newClusters[nearest], member); if nearest != clusterid { swaps++; } } } this.clusters = newClusters; return swaps; };