de.htwdd.rosenkoenig.neuro.net
Class KohonenNet

java.lang.Object
  extended by de.htwdd.rosenkoenig.neuro.net.NeuralNet
      extended by de.htwdd.rosenkoenig.neuro.net.KohonenNet

public class KohonenNet
extends NeuralNet

KohonenNet is an implementation of a self organizing map. Use KohonenTrainer to "unfold" the map.

A self organizing map is useful for e.g. image recognition. The map is able to divide a huge number of inputs into different groups. Each group is represented by a "region" on the map. Whenever an input vector is propagated, the self organizing map calculates a "winning neuron" by determining the neuron whose weight vector has the lowest euclidic distance to the input vector. The winning neuron is marked with an activation of 1.0. Depending on neighbourhood function (e.g. Cone) and neighbourhood radius, some neurons in the surrounding of the winning neuron are also activated.
More information on self organizing maps can be found here.


Field Summary
private  double[] input
          The input vector of the current run.
private  int inputLayerSize
          The number of inputs provided to the map.
private  double[][] map
          The output map of the current run.
private  NeighbourhoodFunction neighbourhoodFunction
           
private  double[] output
          The output map of the current run as a one dimensional array.
private  int outputHeight
          The "height" of the Kohonen map.
private  int outputWidth
          The "width" of the Kohonen map.
private  double[][][] weights
          The weights of the Kohonen map.
private  int winnerX
          The x-coordinate of the winning neuron.
private  int winnerY
          The y-coordinate of the winnin neuron.
 
Constructor Summary
KohonenNet()
          Creates a new uninitialized KohonenNet.
KohonenNet(int inputSize, int outputWidth, int outputHeight, java.lang.Class neighbourhoodFunction)
          Creates and initializes a KohonenNet of the specified size.
 
Method Summary
 org.jdom.Element createXml()
          Creates an XML representation of the Kohonen map and its weights.
 void extractNet(org.jdom.Element xmlNet)
          Extracts a Kohonen map from an XML element.
 double[] getInput()
          Getter of the property input
 int getInputLayerSize()
          Getter of the property inputLayerSize
 double[][] getMap()
          Getter of the property map
 NeighbourhoodFunction getNeighbourhoodFunction()
          Getter of the property neighbourhoodFunction
 double getNeighbourhoodRadius()
           
 double[] getOutput()
          Getter of the property output
 int getOutputHeight()
          Getter of the property outputHeight
 int getOutputWidth()
          Getter of the property outputWidth
 double[][][] getWeights()
          Getter of the property weights
 int getWinnerX()
          Getter of the property winnerX
 int getWinnerY()
          Getter of the property winnerY
private  void initialize(java.lang.Class neighbourhoodFunction)
          Initializes input vector, output vector and the map itself.
 void propagate(double[] pattern)
          Calculates the winning neuron for the provided pattern.
 void setNeighbourhoodFunction(NeighbourhoodFunction neighbourhoodFunction)
          Setter of the property neighbourhoodFunction
 void setNeighbourhoodRadius(double neighbourhoodRadius)
          Sets the neighbourhood radius of the net's neighbourhood function.
 
Methods inherited from class de.htwdd.rosenkoenig.neuro.net.NeuralNet
loadFromFile, saveToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputLayerSize

private int inputLayerSize
The number of inputs provided to the map.


outputWidth

private int outputWidth
The "width" of the Kohonen map. Number of outputs = width*height


outputHeight

private int outputHeight
The "height" of the Kohonen map. Number of outputs = width*height


winnerX

private int winnerX
The x-coordinate of the winning neuron.


winnerY

private int winnerY
The y-coordinate of the winnin neuron.


input

private double[] input
The input vector of the current run.


output

private double[] output
The output map of the current run as a one dimensional array.


map

private double[][] map
The output map of the current run.


weights

private double[][][] weights
The weights of the Kohonen map. Each neuron has a vector (containing the weights) of the same size as the map's input vector.


neighbourhoodFunction

private NeighbourhoodFunction neighbourhoodFunction
Constructor Detail

KohonenNet

public KohonenNet()
Creates a new uninitialized KohonenNet. This constructor is only needed to configure a net that was stored as an XML element.


KohonenNet

public KohonenNet(int inputSize,
                  int outputWidth,
                  int outputHeight,
                  java.lang.Class neighbourhoodFunction)
Creates and initializes a KohonenNet of the specified size. The initial weights are set to a random value.

Parameters:
inputSize - number of inputs
outputWidth - width of the map
outputHeight - height of the map
neighbourhoodFunction - the neighbourhood function used for training and propagation
Method Detail

initialize

private void initialize(java.lang.Class neighbourhoodFunction)
Initializes input vector, output vector and the map itself.

Parameters:
neighbourhoodFunction -

getOutput

public double[] getOutput()
Getter of the property output

Specified by:
getOutput in class NeuralNet
Returns:
Returns the output.

propagate

public void propagate(double[] pattern)
Calculates the winning neuron for the provided pattern. Neurons next to the winning neuron are also activated depending on the neighbourhood function and the neighbourhood radius.

Specified by:
propagate in class NeuralNet
Parameters:
pattern - the pattern to propagate

extractNet

public void extractNet(org.jdom.Element xmlNet)
Extracts a Kohonen map from an XML element.

Specified by:
extractNet in class NeuralNet
Parameters:
xmlNet - XML representation of the Kohonen map

createXml

public org.jdom.Element createXml()
Creates an XML representation of the Kohonen map and its weights.

Specified by:
createXml in class NeuralNet
Returns:
XML representation

getNeighbourhoodRadius

public double getNeighbourhoodRadius()
Returns:
the neighbourhood radius of the net's neighbourhood function

setNeighbourhoodRadius

public void setNeighbourhoodRadius(double neighbourhoodRadius)
Sets the neighbourhood radius of the net's neighbourhood function.

Parameters:
neighbourhoodRadius -

getNeighbourhoodFunction

public NeighbourhoodFunction getNeighbourhoodFunction()
Getter of the property neighbourhoodFunction

Returns:
Returns the neighbourhoodFunction.

setNeighbourhoodFunction

public void setNeighbourhoodFunction(NeighbourhoodFunction neighbourhoodFunction)
Setter of the property neighbourhoodFunction

Parameters:
neighbourhoodFunction - The neighbourhoodFunction to set.

getMap

public double[][] getMap()
Getter of the property map

Returns:
Returns the map.

getWeights

public double[][][] getWeights()
Getter of the property weights

Returns:
Returns the weights.

getWinnerX

public int getWinnerX()
Getter of the property winnerX

Returns:
Returns the winnerX.

getWinnerY

public int getWinnerY()
Getter of the property winnerY

Returns:
Returns the winnerY.

getInputLayerSize

public int getInputLayerSize()
Getter of the property inputLayerSize

Returns:
Returns the inputLayerSize.

getOutputWidth

public int getOutputWidth()
Getter of the property outputWidth

Returns:
Returns the outputWidth.

getOutputHeight

public int getOutputHeight()
Getter of the property outputHeight

Returns:
Returns the outputHeight.

getInput

public double[] getInput()
Getter of the property input

Returns:
Returns the input.