kmeans

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2025 License: MIT Imports: 6 Imported by: 1

README

kmeans

kmeans package is a Go implementation of k-means clustering algorithm with both BLAS and naive implementations.

Documentation

Index

Constants

View Source
const (
	INIT_NONE = iota
	INIT_KMEANS_PLUS_PLUS
	INIT_RANDOM
)

Variables

View Source
var (
	ErrInvalidInitMethod     = errors.New("invalid init method")
	ErrInvalidDataLength     = errors.New("data length must be divisible by the number of features")
	ErrInvalidNumClusters    = errors.New("number of clusters must be greater than 0")
	ErrInvalidNumFeatures    = errors.New("number of features must be greater than 0")
	ErrEmptyData             = errors.New("data is empty")
	ErrFewerClustersThanData = errors.New("number of clusters must be less than the number of data points")
	ErrInvalidMaxIterations  = errors.New("max iterations must be greater than 0")
	ErrInvalidTolerance      = errors.New("tolerance must be greater than 0")
	ErrInvalidConcurrency    = errors.New("concurrency must be greater than 0")
)

Functions

This section is empty.

Types

type KMeans

type KMeans struct {
	// contains filtered or unexported fields
}

func LoadKMeans added in v0.0.3

func LoadKMeans(dec *gob.Decoder) (*KMeans, error)

func NewKMeans added in v0.0.3

func NewKMeans(numClusters, numFeatures int, opts ...NewOption) (*KMeans, error)

func (*KMeans) Centroids

func (km *KMeans) Centroids() [][]float32

func (*KMeans) Decode added in v0.0.2

func (km *KMeans) Decode(dec *gob.Decoder) error

func (*KMeans) Encode added in v0.0.2

func (km *KMeans) Encode(enc *gob.Encoder) error

func (*KMeans) Predict

func (km *KMeans) Predict(data []float32, fn func(row, minCol int, minVal float32) error) error

func (*KMeans) Train

func (km *KMeans) Train(data []float32, opts ...TrainOption) (int, float32, error)

type KMeansState added in v0.0.3

type KMeansState struct {
	InitMethod  int
	NumClusters int
	NumFeatures int
	Centroids   [][]float32
}

type NewOption added in v0.0.3

type NewOption func(*KMeansState) error

func WithInitMethod added in v0.0.3

func WithInitMethod(method int) NewOption

type TrainOption added in v0.0.3

type TrainOption func(*trainConfig) error

func WithConcurrency added in v0.0.3

func WithConcurrency(concurrency int) TrainOption

func WithMaxIterations added in v0.0.3

func WithMaxIterations(iter int) TrainOption

func WithTolerance added in v0.0.3

func WithTolerance(tol float32) TrainOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL