Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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;
};