mirror of
https://github.com/muesli/kmeans.git
synced 2025-09-26 19:51:27 +08:00
Remove flawed Point.Equal function
This commit is contained in:
12
cluster.go
12
cluster.go
@@ -26,18 +26,6 @@ func (c Clusters) Nearest(point Point) int {
|
||||
return ci
|
||||
}
|
||||
|
||||
// removePoint removes a point's assignment to this cluster
|
||||
func (c *Cluster) removePoint(p Point) {
|
||||
var pp Points
|
||||
for _, v := range c.Points {
|
||||
if !v.Equal(p) {
|
||||
pp = append(pp, p)
|
||||
}
|
||||
}
|
||||
|
||||
c.Points = pp
|
||||
}
|
||||
|
||||
// recenter recenters a cluster
|
||||
func (c *Cluster) recenter() {
|
||||
center, err := c.Points.Mean()
|
||||
|
11
point.go
11
point.go
@@ -20,17 +20,6 @@ func (p Point) Distance(p2 Point) float64 {
|
||||
return r
|
||||
}
|
||||
|
||||
// Equal returns true if the two points have equal values
|
||||
func (p Point) Equal(p2 Point) bool {
|
||||
for i := range p {
|
||||
if p[i] != p2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Mean returns the mean point of p
|
||||
func (p Points) Mean() (Point, error) {
|
||||
var l = len(p)
|
||||
|
Reference in New Issue
Block a user