GithubHelp home page GithubHelp logo

seracio / kohonen Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 5.0 4.16 MB

A basic implementation of a Kohonen map in JavaScript

License: MIT License

JavaScript 1.76% TypeScript 98.24%
kohonen som open-source

kohonen's Introduction

kohonen Build Status

A basic implementation of a Kohonen map in JavaScript

Disclaimer: this is a toy implementation of the SOM algorithm, you should probably consider using a more solid library in R or Python.

Usage

Import lib

npm i d3-array d3-scale d3-random lodash ml-pca @seracio/kohonen --save

Then, in your JS script :

import { Kohonen, generateGrid } from '@seracio/kohonen';

API

Kohonen

The Kohonen class is the main class.

Constructor
param name definition type mandatory default
neurons grid of neurons Array yes
data dataset Array of Array yes
maxStep step max to clamp Number no 1000
maxLearningCoef Number no .4
minLearningCoef Number no .1
maxNeighborhood Number no 1
minNeighborhood Number no .3
// instanciate your Kohonen map
const k = new Kohonen({ data, neurons });

// you can use the grid helper to generate a grid with 10x10 hexagons
const k = new Kohonen({ data, neurons: generateGrid(10, 10) });

neurons parameter should be a flat array of { pos: [x,y] }. pos array being the coordinate on the grid.

data parameter is an array of the vectors you want to display. There is no need to standardize your data, that will be done internally by scaling each feature to the [0,1] range.

Basically the constructor do :

  • standardize the given data set
  • initialize random weights for neurons using PCA's largests eigenvectors
training method
param name definition type mandatory default
log func called after each step of learning process Function no (neurons, step)=>{}
k.training();

training method iterates on random vectors picked on normalized data. If a log function is provided as a parameter, it will receive instance neurons and step as params.

mapping method

mapping method returns grid position for each data provided on the constructor.

const myPositions = k.mapping();
umatrix method

umatrix method returns the U-Matrix of the grid (currently only with standardized vectors).

const umatrix = k.umatrix();
errors

There are some heavy calculations in those 2 methods ; if you use them in the training callback (log), it's better not to use it on every step.

k.topographicError();
k.quantizationError();

k.training((neurons, step) => {
    if (step % 20 === 0) {
        k.topographicError();
        k.quantizationError();
    }
});

Example

We've developed a full example on a dedicated repository

capture

(Re)sources

kohonen's People

Contributors

cbanbury avatar dependabot[bot] avatar nmondon avatar quernest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kohonen's Issues

Training step

Iterate over the given datas will be more efficient than attempting to generate close data

Convergence on single neuron with large vectors

I've been playing with this a bit more and it works well for the canonical example of mapping colours. However, when I feed data with more variables (~40) into the SOM, all of the inputs tend to converge on a single neuron.

You seem to have had this issue before with: #17, I'm wondering if it is again related to normalisation?

Should probably have:

  • options for normalisation and re evaluate normalisation strategy
  • more extensive tests for data with larger vectors

Performance with large arrays

Hi,

Are you still actively working on this? I've been playing with this package using spectral data and seems to hang with very large arrays (3000).

How far would you reasonably expect this to scale?

API redesign

The API should be more modular, basically, I think that every process step should be overridable thanks to a sub class

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.