Exemple #1
0
        private void treinar_rede()
        {
            progressBar1.Value = 0;

            int n1  = int.Parse(textBox1.Text);
            int n2  = int.Parse(textBox2.Text);
            int n3  = int.Parse(textBox3.Text);
            int max = int.Parse(textBox4.Text);

            N.e = float.Parse(textBox5.Text);

            RN rede = new RN(1, n1, n2, n3);

            List <float[]> entradas = new List <float[]>();
            List <float[]> saidas   = new List <float[]>();

            gp.Clear(pictureBox1.BackColor);
            foreach (ponto pt in pontos)
            {
                entradas.Add(new float[] { pt.x / W });
                saidas.Add(new float[] { pt.y / H });
                gp.FillEllipse(Brushes.Black, pt.x - 3, pt.y - 3, 6, 6);
            }

            float step  = max / 100f;
            float value = step;

            //treinamento da rede
            for (int iteracao = 0; iteracao < max; iteracao++)
            {
                if (iteracao > value)
                {
                    value += step;
                    progressBar1.Value += 1;
                }

                rede.treinar(entradas, saidas);
            }

            //desenha curva apartir da rede treinada
            float py = 0f;

            for (int px = 0; px < W; px += 2)
            {
                py = H * rede.update(new float[] { px / W })[0];
                gp.FillEllipse(Brushes.Red, px - 2, py - 2, 4, 4);
            }

            pictureBox1.Image  = bmp;
            progressBar1.Value = 100;
            update_buttons(true);
            thr.Abort();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (rede == null)
            {
                return;
            }

            float[] ent = new float[12 * 10];

            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    int idx = 10 * i + j;
                    if (caracter.Controls[idx].BackColor == Color.Blue)
                    {
                        ent[idx] = 1.0f;
                    }
                }
            }

            float[] s = rede.update(ent);

            listBox3.Items.Clear();
            float max = 0f;
            int   k   = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] > max)
                {
                    max = s[i];
                    k   = i;
                }
                this.listBox3.Items.Add(string.Format("{0:0.000}", s[i]));
            }

            //label7.Text = string.Format("{0:0.000}", s);
            //float num = 10f * (float)Math.Round(s, 1);
            //saida.Text = num.ToString();

            saida.Text = k.ToString();
        }