org.yccheok
Class SOM2D

java.lang.Object
  extended by org.yccheok.SOM2D

public class SOM2D
extends java.lang.Object

A class for 2-Dimension Self-Organizing Map.


Constructor Summary
SOM2D(int numOfInput, int width, int height)
          Creates a new instance of SOM2D
 
Method Summary
 java.awt.Point getBestMatchingUnit(SOMInput somInput)
          Get the location of BMU for current SOM input.
 int getCurrentIteration()
          Get the number of current iteration during the training.
 int getHeight()
          Get the height of this SOM.
 double getLearningRate()
          Get the learing rate which will be used in training.
 double getMapRadius()
          Get the map radius based on the following equation : mapRadius = (double)(Math.max(width, height)) / 2.0
 int getNumOfInput()
          Get the number of input per neuron (weight).
 int getNumOfIteration()
          Get the number of iteration which will be used in training.
 double getTimeConstant()
          Get the time constant based on the following equation : timeConstant = (double)numOfIteration / Math.log(mapRadius)
 double getWeightValue(int x, int y, int index)
          Get the value of index th weight at specified (x, y) location.
 int getWidth()
          Get the width of this SOM.
 void init(int numOfIteration, double learningRate, double weightLowerBound, double weightUpperBound)
          Initialize the SOM before learning.
 void setLearningRate(double learningRate)
          Set the learning rate which will be used in training.
 void setNumOfIteration(int numOfIteration)
          Set the number of iteration which will be used in training.
 boolean train(SOMInput somInput)
          Train the SOM to learn.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SOM2D

public SOM2D(int numOfInput,
             int width,
             int height)
Creates a new instance of SOM2D

Parameters:
numOfInput - Number of input per neuron (weight).
width - Width of this SOM.
height - Height of this SOM.
Method Detail

setLearningRate

public void setLearningRate(double learningRate)
Set the learning rate which will be used in training.


getLearningRate

public double getLearningRate()
Get the learing rate which will be used in training.

Returns:
The learning rate which will be used in training.

setNumOfIteration

public void setNumOfIteration(int numOfIteration)
Set the number of iteration which will be used in training.


getNumOfIteration

public int getNumOfIteration()
Get the number of iteration which will be used in training.

Returns:
The number of iteration which will be used in training.

getCurrentIteration

public int getCurrentIteration()
Get the number of current iteration during the training.

Returns:
The number of current iteration during the training.

getTimeConstant

public double getTimeConstant()
Get the time constant based on the following equation : timeConstant = (double)numOfIteration / Math.log(mapRadius)

Returns:
The time constant, which is the function of number of iteration and map radius.

getMapRadius

public double getMapRadius()
Get the map radius based on the following equation : mapRadius = (double)(Math.max(width, height)) / 2.0

Returns:
Get the map radius, which is the function of SOM size.

getWidth

public int getWidth()
Get the width of this SOM.

Returns:
Width of this SOM.

getHeight

public int getHeight()
Get the height of this SOM.

Returns:
Height of this SOM.

getNumOfInput

public int getNumOfInput()
Get the number of input per neuron (weight).

Returns:
The number of input per neuron (weight).

getWeightValue

public double getWeightValue(int x,
                             int y,
                             int index)
Get the value of index th weight at specified (x, y) location.

Parameters:
x - X coordinate location.
y - Y coordinate location.
index - index th of the weight.
Returns:
The value of index th weight at specified (x, y) location.

init

public void init(int numOfIteration,
                 double learningRate,
                 double weightLowerBound,
                 double weightUpperBound)
Initialize the SOM before learning.

Parameters:
numOfIteration - Number of iteration which will be used in training.
learningRate - Learning rate.
weightLowerBound - A random value will be assigned to all the weights. This is the lower bound of the random value (inclusive).
weightUpperBound - A random value will be assigned to all the weights. This is the upper bound of the random value (exclusive).

train

public boolean train(SOMInput somInput)
Train the SOM to learn.

Parameters:
somInput - An input to be pumped into SOM for learning purpose.
Returns:
false if the SOM is not finished its learning. true if the SOM has learned successfully.

getBestMatchingUnit

public java.awt.Point getBestMatchingUnit(SOMInput somInput)
Get the location of BMU for current SOM input. The following equation is used : BMU = location of weight with minimum euclidean distance with SOM input's value.

Parameters:
somInput - The input for SOM.
Returns:
The location of BMU for current SOM input.