AForge.Neuro.DistanceNetwork.GetWinner C# (CSharp) Method

GetWinner() public method

Get winner neuron.
The method returns index of the neuron, which weights have the minimum distance from network's input.
public GetWinner ( ) : int
return int
        public int GetWinner( )
        {
            // find the MIN value
            double min = output[0];
            int    minIndex = 0;

            for ( int i = 1; i < output.Length; i++ )
            {
                if ( output[i] < min )
                {
                    // found new MIN value
                    min = output[i];
                    minIndex = i;
                }
            }

            return minIndex;
        }
    }

Usage Example

Example #1
0
        // Update map
        private void UpdateMap( DistanceNetwork network )
        {
            // get first layer
            Layer layer = network[0];

            // lock
            Monitor.Enter( this );

            // run through all neurons
            for ( int i = 0, n = layer.NeuronsCount; i < n; i++ )
            {
                Neuron neuron = layer[i];

                int x = i % networkSize;
                int y = i / networkSize;

                map[y, x, 0] = (int) neuron[0];
                map[y, x, 1] = (int) neuron[1];
                map[y, x, 2] = 0;
            }

            // collect active neurons
            for ( int i = 0; i < pointsCount; i++ )
            {
                network.Compute( trainingSet[i] );
                int w = network.GetWinner( );

                map[w / networkSize, w % networkSize, 2] = 1;
            }

            // unlock
            Monitor.Exit( this );

            //
            mapPanel.Invalidate( );
        }