Code Monkey home page Code Monkey logo

go-tsne's Introduction

go-tsne

A Go implementation of t-Distributed Stochastic Neighbor Embedding (t-SNE), a prize-winning technique for dimensionality reduction particularly well suited for visualizing high-dimensional datasets.

mnist2d mnist3d

Usage

Import this library:

    import "github.com/danaugrs/go-tsne/tsne"

Create the TSNE object:

    t := tsne.NewTSNE(2, 300, 300, true)

The parameters are

  • Number of output dimensions
  • Perplexity
  • Max number of iterations
  • Verbosity

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:

    Y := t.EmbedData(X, nil)

The alternative is to provide a distance matrix directly:

    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:

    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.

Examples

Two examples are provided - mnist2d and mnist3d. They both use the same data - a subset of 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. To run an example, cd to the example's directory and go run it, e.g:

    cd examples/mnist2d
    go run mnist2d

Support

I hope you enjoy using and learning from go-tsne as much as I enjoyed writing it.

If you come across any issues, please report them.

go-tsne's People

Contributors

danaugrs avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.