Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsk committed Oct 12, 2023
1 parent 336d4b1 commit f40ad55
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Go Kmeans

[![Go Reference](https://pkg.go.dev/badge/github.com/arjunsk/kmeans/kmeans.svg)](https://pkg.go.dev/github.com/arjunsk/kmeans)
[![Go Report Card](https://goreportcard.com/badge/github.com/arjunsk/kmeans)](https://goreportcard.com/report/github.com/arjunsk/kmeans)

This is a simple implementation of the [Elkan's Kmeans](https://cdn.aaai.org/ICML/2003/ICML03-022.pdf)
Expand Down
4 changes: 2 additions & 2 deletions clusterer/elkan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type KmeansElkan struct {

assignments []int // maps vector index to cluster index
lowerBounds [][]float64 // distances for vector and all clusters centroids
upperBounds []float64 // distance between each point and its assigned cluster centroid
upperBounds []float64 // distance between each point and its assigned cluster centroid ie d(x, c(x))
r []bool // indicates that upper bound needs to be recalculated

// local state
Expand Down Expand Up @@ -99,7 +99,7 @@ func (el *KmeansElkan) kmeansElkan(clusters containers.Clusters) error {
// step 4
// For each center c, let m(c) be the mean of the points assigned to c.
// step 7
// Replace each center $c$ by $m(c)$.
// Replace each center c by m(c).
moveDistances, err := clusters.RecenterWithDeltaDistance(el.distFn)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var (
DefaultDeltaThreshold = 0.01
DefaultIterationThreshold = 500
defaultDeltaThreshold = 0.01
defaultIterationThreshold = 500
)

type ClustererType int
Expand Down Expand Up @@ -38,10 +38,10 @@ func (o *options) fillDefaults() {
o.distanceFn = containers.EuclideanDistance
}
if o.deltaThreshold == nil {
o.deltaThreshold = &DefaultDeltaThreshold
o.deltaThreshold = &defaultDeltaThreshold
}
if o.iterationThreshold == nil {
o.iterationThreshold = &DefaultIterationThreshold
o.iterationThreshold = &defaultIterationThreshold
}

}
Expand Down

0 comments on commit f40ad55

Please sign in to comment.