Introduction:This tutorial contains information how to create and use Java Kohonen Neural Network Library. We will try to creat simple network and use "WTA Algorithm" to learn the networkCreating network:
Before we create network first we have to define topology of the network. Now, in the library we can find only two types of topology "matrix topology" and "hexagonal topology".
So, if we want to create "matrics topology with 5 rows and 10 colums:
MatrixTopology topology = new MatrixTopology(5,10);
The same with "hexagonal topology":
HexagonalTopology topology = new HexagonalTopology(5,10);
After we created topology we can create network. In our network all neurons will have only 2 inputs, with random value. For that reason first we will define maximal value of neurons weigths
double[] maxWeight = {200,100};
Now we can create network with specified topology, 2 inputs for each neuron and maximal value for neurons weights
DefaultNetworkModel network = new DefaultNetworkModel(2,maxWeight,topology);
Of courese, if we want to use earlier prepared network with specified neurons weighs we can read data from file:
DefaultNetworkModel network = new DefaultNetworkModel("c:/network.txt",topology);
Learning:
When we have necessary network we can decided which learnig algorithm we want to use WTA  "Winner Take All (only the winner's neuron weights are changed, or WTM  Winner Take Most (winner's and neurons' in neighboorhood weights are changed.
First of all we have to define "function factor"  function which will be used to change neurons weights. In this tutorial we will use "Constant Function Factor" with constant parameters set to 0.8.
ConstantFunctionalFactor constantFactor = new ConstantFunctionalFactor(0.8);
To learn network we must have learnig data. The best way to get them is to read from file:
LearningData fileData = new LearningData("c:/trainning_data.txt");
At the end we can create "WTA algorith" with maximal number of iteration set to 20, andEuclides Metric Function;
WTALearningFunction learning = new WTALearningFunction(network,20,new EuclidesMetric(),fileData,constantFactor);
Let's start learning process:
learning.learn();
At the en we can write to the screen our leaned network (neurons weights)
System.out.println(network);
or write to the file to use later in other learning process.
network.networkToFile("c:/network_after.txt");
