/*
 This is a proprietary part of DataMelt package.
 License: the Creative Commons Attribution-Share Alike License; either version 3.0 of the License, 
 or any later version.
 http://creativecommons.org/licenses/by-sa/3.0/
 

Redistributions of the source code, or parts of the source codes, must retain the copyright notice, this list of conditions and the following disclaimer (all at the top of each source code) and requires the written permission from DataMelt.

Redistribution in binary form of all or parts of a class must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution and requires the written permission of ScaVis

Details about license agreement or commercial use are: http://jwork.org/scavis/ */ package jhpro.nnet; /** * KohonenFeatureMap. Also called Selforganizing Map (SOM). * * A feedforward / feedback type neural net. Built of an input layer thats * neurons are connected with each neuron of another layer, called * "feature map". The feature map can be one- or two-dimensional and each of its * neurons is connected to all other neurons on the map. Mainly used for * classification. *

* It is probably the most useful neural net type, if the learning process of * the human brain shall be simulated. The "heart" of this type is the feature * map, a neuron layer where neurons are organizing themselves according to * certain input values. The type of this neural net is both feedforward (input * layer to feature map) and feedback (feature map). *

* *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Number of neuron layers1 input layer, 1 feature map
Input dimensionminimum: 1, maximum: 3
Number of neurons in feature mapminimum: 1*1, maximum: N*M
Number of input valuesminimum: 1, maximum: N
Weight matricesAutomatically created and initialized. One matrix * connects input layer and feature map. The other matrix is not of the * WeightMatrix type and connects the neurons of the feature map among * themselves.
BiasesNot used
One learning step includesSelection of a random input value, finding the most * activated map neuron, changing of the weights
* * * @author Jochen Fröhlich and S.Chekanov * */ public class KohonenFeatureMap extends NeuralNet { /** * Declares the object kfm to be of type KohonenFeatureMap. */ public KohonenFeatureMap() { super.learningCycle = 0; super.maxLearningCycles = -1; initLearningRate = 0.59999999999999998D; super.learningRate = initLearningRate; initActivationArea = xSize < ySize ? ySize / 2 : xSize / 2; activationArea = initActivationArea; stopArea = initActivationArea / 10D; super.stopLearning = false; resetTime(); } /** * Creates the net's feature map with xSize*ySize map neurons. * * @param i */ public void createMapLayer(int i) { if (mapLayer != null) mapLayer = null; mapLayer = new NeuronMatrix(i); xSize = i; ySize = 0; } /** * Creates the net's feature map with xSize*ySize map neurons. * * @param i * @param j */ public void createMapLayer(int i, int j) { if (mapLayer != null) mapLayer = null; mapLayer = new NeuronMatrix(i, j); xSize = i; ySize = j; } /** * Connects each input neuron (automatically created, depending on the * dimension of the input matrix im) with each neuron of the feature map. * Besides, all map neurons are connected among themselves. All weight * matrices are created and initialized with random values, taken from the * input matrix im. * * @param inputmatrix */ public void connectLayers(InputMatrix inputmatrix) { inputMatrix = inputmatrix; if (inputLayer != null) inputLayer = null; inputLayer = new NeuronLayer(inputmatrix.getDimension()); int i = mapLayer.size(); if (weightMatrix != null) weightMatrix = null; weightMatrix = new WeightMatrix(inputLayer.size(), i, false); if (iv != null) iv = null; iv = new InputValue[i]; for (int j = 0; j < iv.length; j++) iv[j] = inputmatrix.getRandomInput(); weightMatrix.init(iv, inputmatrix.getDimension()); mapLayer.init(iv); } /** * Set initial learning rate. Sets the net's initial learning rate to x. The * default value is 0.6. * * @param d */ public void setInitLearningRate(double d) { initLearningRate = d; super.learningRate = d; } /** * Returns the initial learning rate of the net. * * @return */ public double getInitLearningRate() { return initLearningRate; } /** * Sets the net's initial activation area to x. The default value is the * greater of both map sizes divided by 2. * * @param d */ public void setInitActivationArea(double d) { initActivationArea = d; activationArea = d; } /** * Returns the initial activation area of the feature map. * * @return */ public double getInitActivationArea() { return initActivationArea; } public void setActivationArea(double d) { activationArea = d; } /** * Sets the net's final activation area to x. The default value is * initActivationArea divided by 10. * * @param d */ public void setStopArea(double d) { stopArea = d; } /** * Returns the final activation area of the feature map. * * @return */ public double getStopArea() { return stopArea; } public double getActivationArea() { return activationArea; } /** * Returns the size of the feature map in x-dimension. * * @return */ public int getMapSizeX() { return xSize; } /** * Returns the size of the feature map in y-dimension. * * @return */ public int getMapSizeY() { return ySize; } /** * Returns the number of weights in the weight matrix that connects the * input neurons with the neurons of the feature map. * * @return */ public int getNumberOfWeights() { return weightMatrix.size(); } /** * Returns all weight values of the weight matrix that connects the input * neurons with the neurons of the feature map. * * @return */ public float[][] getWeightValues() { return weightMatrix.getWeights(); } public MapNeuron[] getMapNeurons() { return mapLayer.getMapNeurons(); } public InputValue[] getInputValues() { return inputMatrix.getInputValues(); } public void decreaseActivationArea() { double d = (double) super.learningCycle * 0.00020000000000000001D; setLearningRate(initLearningRate * Math.exp(-2D * d)); setActivationArea(initActivationArea * Math.exp(-5D * d)); } /** * Performs one learning cycle. This method is usually called within a loop, * which exits, if the finishedLearning() method returns true. */ public void learn() { if (activationArea > stopArea && (super.learningCycle < super.maxLearningCycles || super.maxLearningCycles == -1)) { super.learningCycle++; inputLayer.setInput(inputMatrix.getRandomInput()); MapNeuron mapneuron = mapLayer.computeActivationCenter(inputLayer, weightMatrix); weightMatrix.changeWeightsKFM(inputLayer.getOutput(), mapLayer.getFeedback(mapneuron, activationArea), super.learningRate); decreaseActivationArea(); return; } else { super.stopLearning = true; return; } } NeuronMatrix mapLayer; NeuronLayer inputLayer; WeightMatrix weightMatrix; InputMatrix inputMatrix; InputValue iv[]; int xSize; int ySize; double activationArea; double stopArea; double initActivationArea; double initLearningRate; }

Ads help maintain this website.