Skip to content

Commit 5e81f77

Browse files
committed
Implement online learning for k-means
1 parent dee95e5 commit 5e81f77

4 files changed

Lines changed: 179 additions & 80 deletions

File tree

clusters.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ type Clusterer interface {
2020
}
2121

2222
type HardClusterer interface {
23-
Clusters() ([]HardCluster, error)
23+
Guesses() []HardCluster
2424

2525
Predict(observation []float64) (HardCluster, error)
2626

27-
Online(observations chan []float64, done chan bool) chan []HardCluster
27+
Online(observations chan []float64, done chan struct{}) chan []HardCluster
2828

2929
Clusterer
3030
}
3131

3232
type SoftClusterer interface {
33-
Clusters() ([]*SoftCluster, error)
33+
Guesses() []*SoftCluster
3434

3535
Predict(observation []float64) (*SoftCluster, error)
3636

37-
Online(observations chan []float64, done chan bool) chan []*SoftCluster
37+
Online(observations chan []float64, done chan struct{}) chan []*SoftCluster
3838

3939
Clusterer
4040
}

errors.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package clusters
33
import "errors"
44

55
var (
6-
ErrDimensionMismatch = errors.New("Vectors have different dimension")
7-
ErrEmptySet = errors.New("Empty training set")
8-
ErrEmptyClusters = errors.New("Empty clusters")
9-
ErrZeroIterations = errors.New("Number of iterations cannot be less than 1")
10-
ErrZeroClusters = errors.New("Number of clusters cannot be less than 1")
6+
ErrEmptySet = errors.New("Empty training set")
7+
ErrNotTrained = errors.New("You need to train the algorithm first")
8+
ErrZeroIterations = errors.New("Number of iterations cannot be less than 1")
9+
ErrZeroClusters = errors.New("Number of clusters cannot be less than 1")
1110
)

0 commit comments

Comments
 (0)