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

ForceWinners() private method

Force any neurons that did not win to off-load patterns from overworked neurons.
private ForceWinners ( ISynapse synapse, int won, INeuralData leastRepresented ) : bool
synapse ISynapse An array that specifies how many times each output neuron has /// "won".
won int The training pattern that is the least represented by this /// neural network.
leastRepresented INeuralData The synapse to modify.
return bool
        private bool ForceWinners(ISynapse synapse, int[] won,
                 INeuralData leastRepresented)
        {

            double maxActivation = double.MinValue;
            int maxActivationNeuron = -1;

            INeuralData output = this.network.Compute(leastRepresented);

            // Loop over all of the output neurons. Consider any neurons that were
            // not the BMU (winner) for any pattern. Track which of these
            // non-winning neurons had the highest activation.
            for (int outputNeuron = 0; outputNeuron < won.Length; outputNeuron++)
            {
                // Only consider neurons that did not "win".
                if (won[outputNeuron] == 0)
                {
                    if ((maxActivationNeuron == -1)
                            || (output.Data[outputNeuron] > maxActivation))
                    {
                        maxActivation = output.Data[outputNeuron];
                        maxActivationNeuron = outputNeuron;
                    }
                }
            }

            // If a neurons was found that did not activate for any patterns, then
            // force it to "win" the least represented pattern.
            if (maxActivationNeuron != -1)
            {
                CopyInputPattern(synapse, maxActivationNeuron, leastRepresented);
                return true;
            }
            else
            {
                return false;
            }
        }