Encog.Neural.SOM.Training.Neighborhood.BasicTrainSOM.Iteration C# (CSharp) Method

Iteration() public final method

Perform one training iteration.
public final Iteration ( ) : void
return void
        public override sealed void Iteration()
        {
            EncogLogging.Log(EncogLogging.LevelInfo,
                             "Performing SOM Training iteration.");

            PreIteration();

            // Reset the BMU and begin this iteration.
            _bmuUtil.Reset();
            var won = new int[_outputNeuronCount];
            double leastRepresentedActivation = Double.MaxValue;
            IMLData leastRepresented = null;

            // Reset the correction matrix for this synapse and iteration.
            _correctionMatrix.Clear();


            // Determine the BMU foreach each training element.
            foreach (IMLDataPair pair  in  Training)
            {
                IMLData input = pair.Input;

                int bmu = _bmuUtil.CalculateBMU(input);

                // If we are to force a winner each time, then track how many
                // times each output neuron becomes the BMU (winner).
                if (_forceWinner)
                {
                    won[bmu]++;

                    // Get the "output" from the network for this pattern. This
                    // gets the activation level of the BMU.
                    IMLData output = _network.Compute(pair.Input);

                    // Track which training entry produces the least BMU. This
                    // pattern is the least represented by the network.
                    if (output[bmu] < leastRepresentedActivation)
                    {
                        leastRepresentedActivation = output[bmu];
                        leastRepresented = pair.Input;
                    }
                }

                Train(bmu, _network.Weights, input);

                if (_forceWinner)
                {
                    // force any non-winning neurons to share the burden somewhat\
                    if (!ForceWinners(_network.Weights, won,
                                      leastRepresented))
                    {
                        ApplyCorrection();
                    }
                }
                else
                {
                    ApplyCorrection();
                }
            }

            // update the error
            Error = _bmuUtil.WorstDistance/100.0d;

            PostIteration();
        }

Usage Example

        public void TestSOM()
        {
            // create the training set
            IMLDataSet training = new BasicMLDataSet(
                SOMInput, null);

            // Create the neural network.
            var network = new SOMNetwork(4, 2) {Weights = new Matrix(MatrixArray)};

            var train = new BasicTrainSOM(network, 0.4,
                                          training, new NeighborhoodSingle()) {ForceWinner = true};
            int iteration = 0;

            for (iteration = 0; iteration <= 100; iteration++)
            {
                train.Iteration();
            }

            IMLData data1 = new BasicMLData(
                SOMInput[0]);
            IMLData data2 = new BasicMLData(
                SOMInput[1]);

            int result1 = network.Classify(data1);
            int result2 = network.Classify(data2);

            Assert.IsTrue(result1 != result2);
        }
All Usage Examples Of Encog.Neural.SOM.Training.Neighborhood.BasicTrainSOM::Iteration