GithubHelp home page GithubHelp logo

muratkanc / ofxselforganizingmap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from genekogan/ofxselforganizingmap

0.0 0.0 0.0 588 KB

openFrameworks addon implementing a self-organizing map

Makefile 37.24% C++ 62.76%

ofxselforganizingmap's Introduction

ofxSelfOrganizingMap

ofxSelfOrganizingMap an addon for openFrameworks which implements a self-organizing map (SOM) or Kohonen map, an unsupervised machine learning algorithm for mapping high-dimensional data onto a low-dimensional feature space. SOMs have many applications in data clustering, compression, and pattern recognition.

For more information about SOMs, see:

An example application: Mining different words/phrases with Google Images and visualizing the color distributions via SOM.

Usage

To instantiate a self-organizing map (SOM), construct an ofxSelfOrganizingMap object. The SOM is initialized with its default properties: the size of the map (output nodes) is set to 256 x 256 x 1. The SOM takes two parameters, the initial learning rate, and the number of iterations, which are defaulted to 0.1 and 3000, respectively. They may be changed with the following methods.

// instantiate SOM 
ofxSelfOrganizingMap som;
som.setMapSize(300,300);		// map is 2D
som.setMapSize(300,300,300);	// this makes the map 3D
som.setInitialLearningRate(0.2);
som.setNumIterations(5000);

Before using the SOM, you must tell it the size of the input feature vectors and their min and max values, so it can normalize to avoid some features dominating the computation.

// tell the SOM to expect 5-dimensional feature vectors bounded by minInstance and maxInstance
double minInstance[5] = { 0, 0, 0, 0, 0 };
double maxInstance[5] = { 255, 255, 255, 1, 1 };
som.setFeaturesRange(5, minInstance, maxInstance);

Finally, call setup() to allocate space for the SOM. Don't forget to do this! Calling it again returns the SOM to the same initial state and can be called as many times as you want.

som.setup();

To train the SOM, you must give it as many sample feature vectors as specified by the numInstances parameter. Generally, you should train the SOM by randomly sampling from the feature space. The SOM will ignore instances sent to it past the first numIterations.

// do this som.numIterations times!
double instance[5] = { 127, 50, 200, 0.3, 0.9 };	// random sample from your training set
som.updateMap(instance);

Ideally, a well-trained map has the useful property that different regions of it contain very similar feature vectors in roughly the same proportions as found in the initial training set. This makes it useful for clustering data points, and visualizing feature distributions.

Finally, to use the now-trained SOM, you can get the weight vector at any point in the map, or find the point on the map to which a given instance is most similar.

// w is an array holding the value of the map at the point queried
double *w = som.getMapAt(150, 120, 30);	

// to get nearest point for some instance
double instance[5] = { 127, 50, 200, 0.3, 0.9 };
ofPoint nearestPt = findBestMatchingCell(instance);

Tips

Usually, the default parameters for the SOM are fine for most use cases. If you find that the resulting map is not smooth in some regions, or too noisy/grainy, then you can try training it more aggressively by either increasing the the initial learning rate or the number of iterations.

Using a high learning rate may cause the map to converge on less optimal results, but can be trained in fewer iterations, which can be useful if you need it to run faster.

Examples

The colors of the seasons, visualized using an SOM over google image search colors

http://www.genekogan.com/experiments/color-of-words.html

Countries clustered via UN poverty statistics (via AI-junkie)

w

ofxselforganizingmap's People

Contributors

genekogan 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.