Encog.Neural.Networks.Training.Competitive.CompetitiveTraining.Iteration C# (CSharp) Method

Iteration() public method

Perform one training iteration.
public Iteration ( ) : void
return void
        public override void Iteration()
        {
#if logging
            if (logger.IsInfoEnabled)
            {
                logger.Info("Performing Competitive Training iteration.");
            }
#endif

            PreIteration();

            // Reset the BMU and begin this iteration.
            this.bmuUtil.Reset();
            int[] won = new int[this.outputNeuronCount];
            double leastRepresentedActivation = Double.MaxValue;
            INeuralData leastRepresented = null;

            // The synapses are processed parallel to each other.
            foreach (ISynapse synapse in this.synapses)
            {

                // Reset the correction matrix for this synapse and iteration.
                Matrix correction = this.correctionMatrix[synapse];
                correction.Clear();

                // Determine the BMU for each training element.
                foreach (INeuralDataPair pair in Training)
                {
                    INeuralData input = pair.Input;

                    int bmu = this.bmuUtil.CalculateBMU(synapse, input);

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

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

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

                    Train(bmu, synapse, input);

                }

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

            this.network.Structure.FlatUpdate = FlatUpdateNeeded.Flatten;

            // update the error
            Error = this.bmuUtil.WorstDistance;

            PostIteration();
        }