|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package object
-
- import (
- "fmt"
-
- "github.com/danaugrs/go-tsne/tsne"
- "gonum.org/v1/gonum/mat"
- )
-
- func testTsne() {
- b := mat.NewDense(5, 3, []float64{
- 0.1, 0.1, 0.1,
- 0.7, 0.7, 0.7,
- 0.1, 0.7, 0.5,
- 0.7, 0.1, 0.2,
- 0.1, 0.7, 0.5,
- })
-
- t := tsne.NewTSNE(2, 300, 100, 300, true)
-
- Y := t.EmbedData(b, func(iter int, divergence float64, embedding mat.Matrix) bool {
- fmt.Printf("Iteration %d: divergence is %v\n", iter, divergence)
- return false
- })
-
- println(Y)
- }
-
- func (vectorset *Vectorset) DoTsne(dimension int) {
- floatArray := []float64{}
- for _, vector := range vectorset.Vectors {
- floatArray = append(floatArray, vector.Data...)
- }
-
- X := mat.NewDense(len(vectorset.Vectors), vectorset.Dimension, floatArray)
-
- t := tsne.NewTSNE(dimension, 300, 100, 300, true)
-
- Y := t.EmbedData(X, func(iter int, divergence float64, embedding mat.Matrix) bool {
- fmt.Printf("Iteration %d: divergence is %v\n", iter, divergence)
- return false
- })
-
- rowCount, columnCount := Y.Dims()
- if rowCount != len(vectorset.Vectors) {
- panic("rowCount != len(vectorset.Vectors)")
- }
- if columnCount != dimension {
- panic("columnCount != dimension")
- }
-
- for i, vector := range vectorset.Vectors {
- arr := []float64{}
- for j := 0; j < dimension; j++ {
- arr = append(arr, Y.At(i, j))
- }
- vector.Data = arr
- }
- }
|