public DigitImage NextDigit()
        {
            /*byte[][] pixels = new byte[28][];
             * for (int i = 0; i < pixels.Length; ++i)
             *  pixels[i] = new byte[28];*/

            double[][] pixels = new double[28][];

            for (int i = 0; i < 28; ++i)
            {
                pixels[i] = new double[28];

                for (int j = 0; j < 28; ++j)
                {
                    byte   t  = brImages.ReadByte();
                    double tt = t / 255f;
                    pixels[i][j] = tt;
                }
            }

            int lbl = brLabels.ReadByte();

            DigitImage dImage = new DigitImage(pixels, lbl);

            return(dImage);
        }
        private void DibujarNumero(PictureBox box, Label lab, DigitImage numero)
        {
            int tam    = 10;
            int pixels = numero.pixels.Length;

            Bitmap   bmp = new Bitmap(box.Width, box.Height);
            Graphics g   = Graphics.FromImage(bmp);
            Pen      p   = new Pen(Color.Black);

            int x = 0, y = 0;

            for (int i = 0; i < pixels; i++)
            {
                for (int j = 0; j < pixels; j++)
                {
                    int   v           = 255 - (int)Math.Round(numero.pixels[i][j] * 255);
                    Color customColor = Color.FromArgb(v, v, v);

                    if (v == 255)
                    {
                        customColor = Color.FromArgb(102, 255, 51);
                    }

                    SolidBrush customBrush = new SolidBrush(customColor);

                    g.FillRectangle(customBrush, x, y, tam, tam);
                    g.DrawRectangle(p, x, y, tam, tam);

                    x += tam;
                }
                x  = 0;
                y += tam;
            }

            lab.Text          = numero.label.ToString();
            pictureBox1.Image = bmp;
            pictureBox1.Update();
        }
        private void train_Click(object sender, EventArgs eargs)
        {
            MinistReader trainFileReader;

            //DigitImage di;
            double[] inputs  = new double[784];
            double[] outputs = new double[10];
            int      epocas  = int.Parse(textBox1.Text);

            for (int e = 1; e <= epocas; e++)
            {
                trainFileReader = new MinistReader(MinistReader.Modo.Train);

                for (int c = 1; c < trainFileReader.numImages; c++) //trainFileReader.numImages
                {
                    DigitImage di = trainFileReader.NextDigit();

                    for (int i = 0; i < di.pixels.Length; i++)
                    {
                        for (int j = 0; j < di.pixels[i].Length; j++)
                        {
                            inputs[di.pixels.Length * i + j] = di.pixels[i][j];
                        }
                    }

                    for (int i = 0; i < outputs.Length; i++)
                    {
                        outputs[i] = 0.01f;
                    }
                    outputs[di.LabelInt()] = 0.99f;

                    net.Train(new NeuralNetwork.DataSet(inputs, outputs), c, e);
                }

                trainFileReader.Close();
            }
        }