Ejemplo n.º 1
0
        /// <summary>
        /// обучение сети Хэмминга
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog(this) == DialogResult.OK)
            {
                sources = new List <List <double> >();

                hammingNet   = new HammingNetwork();
                hammingNet.K = 0.1;


                names = new List <string>();
                hammingNet.NeuronCount = openFileDialog2.FileNames.Count();
                hammingNet.Eps         = 0.5 / hammingNet.NeuronCount;

                for (int i = 0; i < openFileDialog2.FileNames.Count(); i++)
                {
                    ImageStringForm gfrom1 = new ImageStringForm(openFileDialog2.FileNames[i],
                                                                 i.ToString());
                    if (gfrom1.ShowDialog() == DialogResult.OK)
                    {
                        names.Add(gfrom1.exampleName);
                    }
                    else
                    {
                        MessageBox.Show("Ошибка");
                    }

                    Bitmap bitmap = new Bitmap(openFileDialog2.FileNames[i]);
                    sources.Add(new List <double>());
                    hammingNet.VectorSize = bitmap.Width * bitmap.Height;
                    hammingNet.MaxValue   = bitmap.Width * bitmap.Height;

                    for (int w = 0; w < bitmap.Width; w++)
                    {
                        for (int h = 0; h < bitmap.Height; h++)
                        {
                            double val = bitmap.GetPixel(w, h).R +
                                         bitmap.GetPixel(w, h).G +
                                         bitmap.GetPixel(w, h).B;
                            if (val <= 128 + 128 + 128)
                            {
                                val = 1;
                            }
                            else
                            {
                                val = -1;
                            }
                            sources[i].Add(val);
                        }
                    }
                }
                hammingNet.Init(sources);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// обучение сети Кохонена
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog(this) == DialogResult.OK)
            {
                sources = new List <List <double> >();

                kohonenNet = new KohonenNetwork();

                kohonenNet.Alpha         = decimal.ToDouble(numericUpDown1.Value);
                kohonenNet.DistanceParam = decimal.ToDouble(numericUpDown2.Value);

                names = new List <string>();
                for (int i = 0; i < openFileDialog2.FileNames.Count(); i++)
                {
                    ImageStringForm gfrom1 = new ImageStringForm(openFileDialog2.FileNames[i],
                                                                 i.ToString());
                    if (gfrom1.ShowDialog() == DialogResult.OK)
                    {
                        names.Add(gfrom1.exampleName);
                    }
                    else
                    {
                        MessageBox.Show("Ошибка");
                    }

                    Bitmap bitmap = new Bitmap(openFileDialog2.FileNames[i]);
                    sources.Add(new List <double>());

                    for (int w = 0; w < bitmap.Width; w++)
                    {
                        for (int h = 0; h < bitmap.Height; h++)
                        {
                            double val = bitmap.GetPixel(w, h).R +
                                         bitmap.GetPixel(w, h).G +
                                         bitmap.GetPixel(w, h).B;
                            if (val <= 128 + 128 + 128)
                            {
                                val = 1;
                            }
                            else
                            {
                                val = 0;
                            }
                            sources[i].Add(val);
                        }
                    }
                }
                kohonenNet.Init(sources);
            }
        }