Kohonen Self Organizing Map (SOM) learning algorithm.

This class implements Kohonen's SOM learning algorithm and is widely used in clusterization tasks. The class allows to train Distance Networks.

Sample usage (clustering RGB colors):

// set range for randomization neurons' weights Neuron.RandRange = new Range( 0, 255 ); // create network DistanceNetwork network = new DistanceNetwork( 3, // thress inputs in the network 100 * 100 ); // 10000 neurons // create learning algorithm SOMLearning trainer = new SOMLearning( network ); // network's input double[] input = new double[3]; // loop while ( !needToStop ) { input[0] = rand.Next( 256 ); input[1] = rand.Next( 256 ); input[2] = rand.Next( 256 ); trainer.Run( input ); // ... // update learning rate and radius continuously, // so networks may come steady state }
Inheritance: IUnsupervisedLearning
Exemple #1
0
        // Worker thread
        void SearchSolution()
        {
            // create network
            DistanceNetwork network = new DistanceNetwork(2, networkSize * networkSize);

            // set random generators range
            foreach (var layer in network.Layers)
                foreach (var neuron in layer.Neurons)
                    neuron.RandGenerator = new UniformContinuousDistribution(
                        new Range(0, Math.Max(pointsPanel.ClientRectangle.Width, pointsPanel.ClientRectangle.Height)));

            // create learning algorithm
            SOMLearning trainer = new SOMLearning(network, networkSize, networkSize);

            // create map
            map = new int[networkSize, networkSize, 3];

            double fixedLearningRate = learningRate / 10;
            double driftingLearningRate = fixedLearningRate * 9;

            // iterations
            int i = 0;

            // loop
            while (!needToStop)
            {
                trainer.LearningRate = driftingLearningRate * (iterations - i) / iterations + fixedLearningRate;
                trainer.LearningRadius = (double)learningRadius * (iterations - i) / iterations;

                // run training epoch
                trainer.RunEpoch(trainingSet);

                // update map
                UpdateMap(network);

                // increase current iteration
                i++;

                // set current iteration's info
                SetText(currentIterationBox, i.ToString());

                // stop ?
                if (i >= iterations)
                    break;
            }

            // enable settings controls
            EnableControls(true);
        }
Exemple #2
0
        // Worker thread
        void SearchSolution()
        {
            // create learning algorithm
            SOMLearning trainer = new SOMLearning(network);

            // input
            double[] input = new double[3];

            double fixedLearningRate = learningRate / 10;
            double driftingLearningRate = fixedLearningRate * 9;

            // iterations
            int i = 0;

            // loop
            while (!needToStop)
            {
                trainer.LearningRate = driftingLearningRate * (iterations - i) / iterations + fixedLearningRate;
                trainer.LearningRadius = (double)radius * (iterations - i) / iterations;

                input[0] = rand.Next(256);
                input[1] = rand.Next(256);
                input[2] = rand.Next(256);

                trainer.Run(input);

                // update map once per 50 iterations
                if ((i % 10) == 9)
                {
                    UpdateMap();
                }

                // increase current iteration
                i++;

                // set current iteration's info
                SetText(currentIterationBox, i.ToString());

                // stop ?
                if (i >= iterations)
                    break;
            }

            // enable settings controls
            EnableControls(true);
        }