GithubHelp home page GithubHelp logo

cgorman / tensorflow-som Goto Github PK

View Code? Open in Web Editor NEW
77.0 9.0 34.0 102 KB

A multi-gpu implementation of the self-organizing map in TensorFlow

License: MIT License

Python 100.00%
tensorflow neural-networks self-organizing-map unsupervised-learning

tensorflow-som's Introduction

NOTE: This package is no longer maintained and trained SOMs may have issues with stability. I will refrain from archiving this repository for the time being because I may end up releasing an updated version for PyTorch which I will link to before archiving. Like everything else, use this code at your own risk and please do some sanity checks. Thanks!

TensorFlow Self-Organizing Map

An implementation of the Kohonen self-organizing map1 for TensorFlow 1.5 and Python 3.6. A Tensorflow V2 version has been contributed by Dragan Avramovski and is in the tfv2 branch. (Thanks Dragan!) This was initially based off of Sachin Joglekar's code but has a few key modifications:

  • Uses TensorFlow broadcasting semantics instead of tf.pack and for loops.
  • Input data is expected from a Tensor rather than a tf.placeholder, allowing for use with faster and more complex input data pipelines.
  • Training uses the batch algorithm rather than the online one, providing a major speed boost if you have the GPU RAM. Also, as a result of that, I added...
  • Multi-GPU support (for single machines with multiple GPUs, it doesn't have multi-node training).
  • Some summary operations for Tensorboard visualization

example.py contains a simple example of its usage by training a SOM on a 3 cluster toy dataset. The resulting u-matrix should look something like this:

Example U-Matrix

Note that the example requires scikit-learn to be installed.

I was going to write a blog post about this but I ended up just repeating everything I wrote in the comments, so please read them if you'd like to understand the code. For reference, the batch formula for SOMs is

SOM batch formula

where theta is the neighborhood function and x is the input vector.

The activity function turns the distance between each of the weights and an input vector into a value between 0 and 1, i.e. similar weights elicit a higher activity. The activity function is parameterized with the output_sensitivity variable. When this value is close to zero the range of distances that elicit high activity is wider, and vice versa. Here is an example of a few different values of the output sensitivity (-c here):

Effect of Output Sensitivity Parameter

Note about the learning rate

There was a really dumb bug in commits before 2a0ee25 where the learning rate (alpha) was set extremely incorrectly. Instead of shrinking from n to 0, it grew from n to 1. If you had bad luck with this module previously, this may fix it. Sorry for the goof!

1http://ieeexplore.ieee.org/document/58325/

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.