Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
danaugrs authored Mar 6, 2022
1 parent 7822ad4 commit 2250969
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ A Go implementation of [t-Distributed Stochastic Neighbor Embedding (t-SNE)](htt
### Usage
Import this library:
```Go
import "github.com/danaugrs/go-tsne/tsne"
import "github.com/danaugrs/go-tsne/tsne"
```
Create the TSNE object:
```Go
t := tsne.NewTSNE(2, 300, 100, 300, true)
t := tsne.NewTSNE(2, 300, 100, 300, true)
```
The parameters are
* Number of output dimensions
Expand All @@ -25,20 +25,20 @@ The parameters are

There are two ways to start the t-SNE embedding optimization. The regular way is to provide an `n` by `d` matrix where each row is a datapoint and each column is a dimension:
```Go
Y := t.EmbedData(X, nil)
Y := t.EmbedData(X, nil)
```
The alternative is to provide a distance matrix directly:
```Go
Y := t.EmbedDistances(D, nil)
Y := t.EmbedDistances(D, nil)
```
In either case, the returned matrix `Y` will contain the final embedding.

For more fine-grained control, a step function can be provided in either case:
```Go
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
})
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
})
```
The step function has access to the iteration, the current divergence, and the embedding optimized so far.
You can return `true` to halt the optimization.
Expand All @@ -47,9 +47,9 @@ You can return `true` to halt the optimization.
Two examples are provided - `mnist2d` and `mnist3d`. They both use the same data - a subset of [MNIST](http://yann.lecun.com/exdb/mnist/) with 2500 handwritten digits. `mnist2d` generates plots throughout the optimization process, and `mnist3d` shows the optimization happening in real-time, in 3D. `mnist3d` depends on [G3N](https://github.com/g3n/engine).
To run an example, `cd` to the example's directory, build it, and execute it, e.g:
```
cd examples/mnist2d
go build
./mnist2d
cd examples/mnist2d
go build
./mnist2d
```

### Support
Expand Down

0 comments on commit 2250969

Please sign in to comment.