Welvet examples
52. stub/clustering
Part: VIII Β· Stubs
Package: github.com/openfluke/welvet/stub/clustering
Status: partial β π§
When
Scaffold / experimental stub stub/clustering (may be partial).
Where
import "github.com/openfluke/welvet/stub/clustering"
cd 52-stub-clustering && source ../env.sh && go run .
Why
Offline clustering helpers on tensors without inventing a second math stack.
What
KMeansCluster, HierarchicalGroup, distance/silhouette helpers.
Sample output (captured)
2 [0 1]
Live capture from go run ./cmd/runall on local ../../welvet (exit 0).
Source
Copied from the Welvet feature book examples (openfluke.github.io/welvet/examples/52-stub-clustering).
main.go
Download source βpackage main
import (
"fmt"
"github.com/openfluke/welvet/core"
"github.com/openfluke/welvet/stub/clustering"
)
func main() {
pts := []*core.Tensor[float32]{
core.NewTensor[float32](2),
core.NewTensor[float32](2),
}
pts[0].Data[0], pts[0].Data[1] = 0, 0
pts[1].Data[0], pts[1].Data[1] = 1, 1
cent, assign := clustering.KMeansCluster(pts, 2, 10, false)
fmt.Println(len(cent), assign)
}