Package libai.nn.unsupervised
Class Kohonen
- java.lang.Object
-
- libai.nn.NeuralNetwork
-
- libai.nn.unsupervised.UnsupervisedLearning
-
- libai.nn.unsupervised.Kohonen
-
- All Implemented Interfaces:
java.io.Serializable
public class Kohonen extends UnsupervisedLearning
Kohonen's Self-organizative Maps or SOM or Kohonen. This maps are one of the most important unsupervised neural networks of the history. The most important feature of the kohonen's maps is the possibility of transform any multidimensional space into a R^2 space, providing a highly precise clustering method. One of the most famous examples for the kohonen's maps is the transform the RGB color cube into a plane where the reds, greens, blues, etc are clustered in a very similar way of the any color picker utility.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class libai.nn.NeuralNetwork
plotter, progress, random
-
-
Constructor Summary
Constructors Constructor Description Kohonen(int[] nperlayer, double neighborhood)
Constructor.Kohonen(int[] nperlayer, double neighborhood, int[] neighboursX, int[] neighboursY)
Constructor.Kohonen(int[] nperlayer, double neighborhood, int[] neighboursX, int[] neighboursY, java.util.Random rand)
Constructor.Kohonen(int[] nperlayer, double neighborhood, java.util.Random random)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
expandMap(Column[] patterns, Column[] answers, int offset, int length)
Label the output for the patterns and expand the results through the neighbors until the map is completely fill.int[][]
getMap()
Column
getPrototypeAt(int i, int j)
Column
simulate(Column pattern)
Calculates the output for thepattern
.void
simulate(Column pattern, Column result)
Calculates the output for thepattern
and left the result inresult
.void
train(Column[] patterns, double alpha, int epochs, int offset, int length)
Train the map.-
Methods inherited from class libai.nn.NeuralNetwork
error, error, euclideanDistance2, euclideanDistance2, gaussian, getDefaultRandomGenerator, getPlotter, getProgressBar, initializeProgressBar, open, open, open, save, setPlotter, setProgressBar, train, train
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from class libai.nn.unsupervised.UnsupervisedLearning
train, validatePreconditions
-
-
-
-
Constructor Detail
-
Kohonen
public Kohonen(int[] nperlayer, double neighborhood, int[] neighboursX, int[] neighboursY)
Constructor. Creates a kohonen's map with nperlayer[0] inputs, nperlayer[1] rows and nperlayer[2] columns. Additional set the initial size of the neighborhood and the way in the neighbors are connected.- Parameters:
nperlayer
- Number of neurons (input, rows and columns)neighborhood
- Initial size of the neighborhoodneighboursX
- neighbors along the X-axisneighboursY
- neighbors along the Y-axis
-
Kohonen
public Kohonen(int[] nperlayer, double neighborhood, int[] neighboursX, int[] neighboursY, java.util.Random rand)
Constructor. Creates a kohonen's map with nperlayer[0] inputs, nperlayer[1] rows and nperlayer[2] columns. Additional set the initial size of the neighborhood and the way in the neighbors are connected.- Parameters:
nperlayer
- Number of neurons (input, rows and columns)neighborhood
- Initial size of the neighborhoodneighboursX
- neighbors along the X-axis as deltas from origin eg. +1, 0, -1, 2neighboursY
- neighbors along the Y-axis as deltas from origin eg. +1, 0, -1, 2rand
- Random generator used for creating matrices
-
Kohonen
public Kohonen(int[] nperlayer, double neighborhood)
Constructor. Creates a kohonen's map using the standard neighborhood (up, down, left, right). Alias of Kohonen(nperlayer, _neighborhood, new int[]{0,0,1,-1}, new int[]{-1,1,0,0});- Parameters:
nperlayer
- Number of neurons (input, rows and columns)neighborhood
- Initial size of the neighborhood
-
Kohonen
public Kohonen(int[] nperlayer, double neighborhood, java.util.Random random)
Constructor. Creates a kohonen's map using the standard neighborhood (up, down, left, right). Alias of Kohonen(nperlayer, _neighborhood, new int[]{0,0,1,-1}, new int[]{-1,1,0,0});- Parameters:
nperlayer
- Number of neurons (input, rows and columns)neighborhood
- Initial size of the neighborhoodrandom
- Random generator used for creating matrices
-
-
Method Detail
-
train
public void train(Column[] patterns, double alpha, int epochs, int offset, int length)
Train the map. The answers are omitted for the training process but are necessary for the labeling of the map.- Specified by:
train
in classUnsupervisedLearning
- Parameters:
patterns
- The patterns to be learned.alpha
- The learning rate.epochs
- The maximum number of iterationsoffset
- The first pattern positionlength
- How many patterns will be used.
-
simulate
public Column simulate(Column pattern)
Description copied from class:NeuralNetwork
Calculates the output for thepattern
.- Specified by:
simulate
in classNeuralNetwork
- Parameters:
pattern
- Pattern to use as input.- Returns:
- The output for the neural network.
-
simulate
public void simulate(Column pattern, Column result)
Description copied from class:NeuralNetwork
Calculates the output for thepattern
and left the result inresult
.- Specified by:
simulate
in classNeuralNetwork
- Parameters:
pattern
- Pattern to use as input.result
- The output for the input.
-
getPrototypeAt
public Column getPrototypeAt(int i, int j)
-
getMap
public int[][] getMap()
- Returns:
- The label map.
-
expandMap
public void expandMap(Column[] patterns, Column[] answers, int offset, int length)
Label the output for the patterns and expand the results through the neighbors until the map is completely fill. NOTE: The expansion isn't an standard process but is very helpful to avoid unknown answers.- Parameters:
patterns
- The patterns to labelanswers
- The expected answer for the patternsoffset
- The initial pattern positionlength
- How many patterns to label.
-
-