ran go mod vendor on the whole project
This commit is contained in:
parent
26f96f361f
commit
28d10d9d39
346 changed files with 12917 additions and 66931 deletions
54
vendor/github.com/mash/gokmeans/gokmeans.go
generated
vendored
54
vendor/github.com/mash/gokmeans/gokmeans.go
generated
vendored
|
@ -1,41 +1,3 @@
|
|||
/*
|
||||
Gokmeans is a simple k-means clusterer that determines centroids with the Train function,
|
||||
and then classifies additional observations with the Nearest function.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mdesenfants/gokmeans"
|
||||
)
|
||||
|
||||
var observations []gokmeans.Node = []gokmeans.Node {
|
||||
gokmeans.Node{20.0, 20.0, 20.0, 20.0},
|
||||
gokmeans.Node{21.0, 21.0, 21.0, 21.0},
|
||||
gokmeans.Node{100.5, 100.5, 100.5, 100.5},
|
||||
gokmeans.Node{50.1, 50.1, 50.1, 50.1},
|
||||
gokmeans.Node{64.2, 64.2, 64.2, 64.2},
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Get a list of centroids and output the values
|
||||
if success, centroids := gokmeans.Train(observations, 2, 50); success {
|
||||
// Show the centroids
|
||||
fmt.Println("The centroids are")
|
||||
for _, centroid := range centroids {
|
||||
fmt.Println(centroid)
|
||||
}
|
||||
|
||||
// Output the clusters
|
||||
fmt.Println("...")
|
||||
for _, observation := range observations {
|
||||
index := gokmeans.Nearest(observation, centroids)
|
||||
fmt.Println(observation, "belongs in cluster", index+1, ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
package gokmeans
|
||||
|
||||
import (
|
||||
|
@ -43,12 +5,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Node represents an observation of floating point values
|
||||
type Node []float64
|
||||
|
||||
// Train takes an array of Nodes (observations), and produces as many centroids as specified by
|
||||
// clusterCount. It will stop adjusting centroids after maxRounds is reached. If there are less
|
||||
// observations than the number of centroids requested, then Train will return (false, nil).
|
||||
func Train(Nodes []Node, clusterCount int, maxRounds int) (bool, []Node) {
|
||||
if int(len(Nodes)) < clusterCount {
|
||||
return false, nil
|
||||
|
@ -78,11 +36,6 @@ func Train(Nodes []Node, clusterCount int, maxRounds int) (bool, []Node) {
|
|||
copy(centroids[i], Nodes[r.Intn(len(Nodes))])
|
||||
}
|
||||
|
||||
return Train2(Nodes, clusterCount, maxRounds, centroids)
|
||||
}
|
||||
|
||||
// Provide initial centroids
|
||||
func Train2(Nodes []Node, clusterCount int, maxRounds int, centroids []Node) (bool, []Node) {
|
||||
// Train centroids
|
||||
movement := true
|
||||
for i := 0; i < maxRounds && movement; i++ {
|
||||
|
@ -108,7 +61,6 @@ func Train2(Nodes []Node, clusterCount int, maxRounds int, centroids []Node) (bo
|
|||
return true, centroids
|
||||
}
|
||||
|
||||
// equal determines if two nodes have the same values.
|
||||
func equal(node1, node2 Node) bool {
|
||||
if len(node1) != len(node2) {
|
||||
return false
|
||||
|
@ -123,7 +75,6 @@ func equal(node1, node2 Node) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// Nearest return the index of the closest centroid from nodes
|
||||
func Nearest(in Node, nodes []Node) int {
|
||||
count := len(nodes)
|
||||
|
||||
|
@ -151,7 +102,6 @@ func Nearest(in Node, nodes []Node) int {
|
|||
return mindex
|
||||
}
|
||||
|
||||
// Distance determines the square Euclidean distance between two nodes
|
||||
func distance(node1 Node, node2 Node) float64 {
|
||||
length := len(node1)
|
||||
squares := make(Node, length, length)
|
||||
|
@ -176,8 +126,6 @@ func distance(node1 Node, node2 Node) float64 {
|
|||
return sum
|
||||
}
|
||||
|
||||
// meanNode takes an array of Nodes and returns a node which represents the average
|
||||
// value for the provided nodes. This is used to center the centroids within their cluster.
|
||||
func meanNode(values []Node) Node {
|
||||
newNode := make(Node, len(values[0]))
|
||||
|
||||
|
@ -194,8 +142,6 @@ func meanNode(values []Node) Node {
|
|||
return newNode
|
||||
}
|
||||
|
||||
// wait stops a function from continuing until the provided channel has processed as
|
||||
// many items as there are dimensions in the provided Node.
|
||||
func wait(c chan int, values Node) {
|
||||
count := len(values)
|
||||
|
||||
|
|
Reference in a new issue