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
|
// Nearest returns the index of the cluster nearest to point
|
||||||
func (c Clusters) nearestCluster(point Point) int {
|
func (c Clusters) Nearest(point Point) int {
|
||||||
var dist float64
|
var dist float64
|
||||||
var ci int
|
var ci int
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ func (m Kmeans) Partition(dataset Points, k int) (Clusters, error) {
|
|||||||
clusters.reset()
|
clusters.reset()
|
||||||
|
|
||||||
for p, point := range dataset {
|
for p, point := range dataset {
|
||||||
ci := clusters.nearestCluster(point)
|
ci := clusters.Nearest(point)
|
||||||
clusters[ci].Points = append(clusters[ci].Points, point)
|
clusters[ci].Points = append(clusters[ci].Points, point)
|
||||||
if points[p] != ci {
|
if points[p] != ci {
|
||||||
points[p] = ci
|
points[p] = ci
|
||||||
@@ -103,7 +103,6 @@ func (m Kmeans) Partition(dataset Points, k int) (Clusters, error) {
|
|||||||
if m.debug {
|
if m.debug {
|
||||||
draw(clusters, i)
|
draw(clusters, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
if changes < int(float64(len(dataset))*m.deltaThreshold) {
|
if changes < int(float64(len(dataset))*m.deltaThreshold) {
|
||||||
// fmt.Println("Aborting:", changes, int(float64(len(dataset))*m.TerminationThreshold))
|
// fmt.Println("Aborting:", changes, int(float64(len(dataset))*m.TerminationThreshold))
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user