Ejemplo n.º 1
0
        // Generate point
        void GeneratePoints()
        {
            int width    = pointsPanel.ClientRectangle.Width;
            int height   = pointsPanel.ClientRectangle.Height;
            int diameter = groupRadius * 2;

            // generate groups of ten points
            for (int i = 0; i < pointsCount;)
            {
                int cx = rand.Next(width);
                int cy = rand.Next(height);

                // generate group
                for (int j = 0; (i < pointsCount) && (j < 10);)
                {
                    int x = cx + rand.Next(diameter) - groupRadius;
                    int y = cy + rand.Next(diameter) - groupRadius;

                    // check if wee are not out
                    if ((x < 0) || (y < 0) || (x >= width) || (y >= height))
                    {
                        continue;
                    }

                    // add point
                    points[i, 0] = x;
                    points[i, 1] = y;

                    j++;
                    i++;
                }
            }

            map = null;
            pointsPanel.Invalidate();
            mapPanel.Invalidate();
        }
Ejemplo n.º 2
0
        // Update map from network weights
        void UpdateMap()
        {
            // lock
            System.Threading.Monitor.Enter(this);

            // lock bitmap
            BitmapData mapData = mapBitmap.LockBits(new RectI(0, 0, 200, 200),
                                                    ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int   stride = mapData.Stride;
            int   offset = stride - 200 * 3;
            Layer layer  = network.Layers[0];

            byte[] ptr       = mapData.Scan0;
            int    ptr_index = 0;

            // for all rows
            for (int y = 0, i = 0; y < 100; y++)
            {
                // for all pixels
                for (int x = 0; x < 100; x++, i++, ptr_index += 6)
                {
                    Neuron neuron = layer.Neurons[i];

                    // red
                    ptr[ptr_index + 2] = ptr[ptr_index + 2 + 3] = ptr[ptr_index + 2 + stride] = ptr[ptr_index + 2 + 3 + stride] =
                        (byte)Math.Max(0, Math.Min(255, neuron.Weights[0]));
                    // green
                    ptr[ptr_index + 1] = ptr[ptr_index + 1 + 3] = ptr[ptr_index + 1 + stride] = ptr[ptr_index + 1 + 3 + stride] =
                        (byte)Math.Max(0, Math.Min(255, neuron.Weights[1]));
                    // blue
                    ptr[ptr_index + 0] = ptr[ptr_index + 0 + 3] = ptr[ptr_index + 0 + stride] = ptr[ptr_index + 0 + 3 + stride] =
                        (byte)Math.Max(0, Math.Min(255, neuron.Weights[2]));
                }

                ptr_index += offset;
                ptr_index += stride;
            }

            // unlock image
            mapBitmap.UnlockBits(mapData);

            // unlock
            System.Threading.Monitor.Exit(this);

            // invalidate maps panel
            mapPanel.Invalidate();
        }