mirror of
https://github.com/muesli/kmeans.git
synced 2025-09-27 03:56:17 +08:00
Export Clusters.Nearest
This commit is contained in:
@@ -33,8 +33,8 @@ func (c Clusters) reset() {
|
||||
}
|
||||
}
|
||||
|
||||
// nearestCluster returns the index of the cluster nearest to point
|
||||
func (c Clusters) nearestCluster(point Point) int {
|
||||
// Nearest returns the index of the cluster nearest to point
|
||||
func (c Clusters) Nearest(point Point) int {
|
||||
var dist float64
|
||||
var ci int
|
||||
|
||||
|
@@ -74,7 +74,7 @@ func (m Kmeans) Partition(dataset Points, k int) (Clusters, error) {
|
||||
clusters.reset()
|
||||
|
||||
for p, point := range dataset {
|
||||
ci := clusters.nearestCluster(point)
|
||||
ci := clusters.Nearest(point)
|
||||
clusters[ci].Points = append(clusters[ci].Points, point)
|
||||
if points[p] != ci {
|
||||
points[p] = ci
|
||||
@@ -103,7 +103,6 @@ func (m Kmeans) Partition(dataset Points, k int) (Clusters, error) {
|
||||
if m.debug {
|
||||
draw(clusters, i)
|
||||
}
|
||||
|
||||
if changes < int(float64(len(dataset))*m.deltaThreshold) {
|
||||
// fmt.Println("Aborting:", changes, int(float64(len(dataset))*m.TerminationThreshold))
|
||||
break
|
||||
|
Reference in New Issue
Block a user