コード例 #1
0
        /// <summary>
        /// Force any neurons that did not win to off-load patterns from overworked
        /// neurons.
        /// </summary>
        ///
        /// <param name="won"></param>
        /// <param name="leastRepresented"></param>
        /// <param name="matrix">The synapse to modify.</param>
        /// <returns>True if a winner was forced.</returns>
        private bool ForceWinners(Matrix matrix, int[] won,
                                  IMLData leastRepresented)
        {
            double maxActivation       = Double.MinValue;
            int    maxActivationNeuron = -1;

            IMLData output = _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[outputNeuron] > maxActivation))
                    {
                        maxActivation       = output[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(matrix, maxActivationNeuron, leastRepresented);
                return(true);
            }
            return(false);
        }