private void Work(object sender, DoWorkEventArgs e)
        {
            int    nr_generatii  = (int)NumericUpDown.Value;
            double eroare_dorita = (double)NumericUpDown_Eroare.Value;

            for (int i = 0; i < nr_generatii; i++)
            {
                Thread.Sleep(2);

                if (Worker.CancellationPending)
                {
                    e.Cancel = true;

                    return;
                }
                List <double> Rez  = new List <double>();
                List <double> Targ = new List <double>();
                for (int j = 0; j < Inputs.Count(); j++)
                {
                    rs.ForWordPropagation(Inputs[j], Target[j]);
                    rs.BackPropagation(Target[j]);
                    List <double> tg_aux = new List <double>(Target[j]);
                    List <double> rz_aux = new List <double>(rs.Return_Result());
                    Rez.Add(rz_aux[0]);
                    Targ.Add(tg_aux[0]);
                }
                if (i % 25 == 0)
                {
                    AmestecaInputsTargets();
                }
                BeginInvoke((MethodInvoker) delegate
                {
                    GeneratieValue_label.Text = i.ToString();
                    EroareValue_Label.Text    = $"{Eroare(Rez, Targ).ToString()}";
                    chart3.Series["Eroare"].Points.AddXY(i, Eroare(Rez, Targ));
                    if (Eroare(Rez, Targ) < eroare_dorita)
                    {
                        Stop.PerformClick();
                    }
                });
            }
            BeginInvoke((MethodInvoker) delegate
            {
                rs.ExportXML(SelectedUser_Label.Text);
            });
        }
        private void Testare_Click(object sender, EventArgs e)
        {
            string user = SelectedUser_Label.Text;

            if (user == "Nimeni")
            {
                return;
            }
            rs = new ReteaNeuronala(12, 1, nrNeuroni, 1);
            string path = $"{Path.GetDirectoryName(Application.ExecutablePath)}\\Weights\\{user}.txt";
            bool   a    = File.Exists(path);

            if (File.Exists(path))
            {
                rs.ImportXML(user);
            }
            else
            {
                rs.ExportXML(user);
            }

            Inputs = new List <List <double> >();
            Target = new List <List <double> >();


            path = $"{Path.GetDirectoryName(Application.ExecutablePath)}\\TestSet\\{SelectedUser_Label.Text}.txt";
            FileStream            f  = new FileStream(path, FileMode.Open, FileAccess.Read);
            List <List <double> > ob = (List <List <double> >)xss.Deserialize(f);

            for (int i = 0; i < ob.Count; i++)
            {
                List <double> aux = new List <double>(ob[i]);
                aux.RemoveAt(aux.Count - 1);
                Inputs.Add(new List <double>(aux));

                aux = new List <double>(ob[i]);
                aux.RemoveRange(0, 12);
                Target.Add(new List <double>(aux));
            }


            List <double> Rez  = new List <double>();
            List <double> Targ = new List <double>();

            for (int j = 0; j < Inputs.Count(); j++)
            {
                rs.ForWordPropagation(Inputs[j], Target[j]);
                List <double> tg_aux = new List <double>(Target[j]);
                List <double> rz_aux = new List <double>(rs.Return_Result());
                Rez.Add(rz_aux[0]);
                Targ.Add(tg_aux[0]);
            }

            Testare_label.Text = Eroarre(Rez, Targ).ToString() + "%";
            f.Close();
            f.Dispose();
        }
        private void Learning_Click(object sender, EventArgs e)
        {
            if (Worker.IsBusy)
            {
                return;
            }

            string user = SelectedUser_Label.Text;

            if (user == "Nimeni")
            {
                return;
            }
            rs = new ReteaNeuronala(12, 1, nrNeuroni, 1);
            string path = $"{Path.GetDirectoryName(Application.ExecutablePath)}\\Weights\\{user}.txt";
            bool   a    = File.Exists(path);

            if (File.Exists(path))
            {
                rs.ImportXML(user);
            }
            else
            {
                rs.ExportXML(user);
            }

            Inputs = new List <List <double> >();
            Target = new List <List <double> >();


            path = $"{Path.GetDirectoryName(Application.ExecutablePath)}\\TrainSet\\{user}.txt";
            FileStream            f  = new FileStream(path, FileMode.Open, FileAccess.Read);
            List <List <double> > ob = (List <List <double> >)xss.Deserialize(f);

            for (int i = 0; i < ob.Count; i++)
            {
                List <double> aux = new List <double>(ob[i]);
                aux.RemoveAt(aux.Count - 1);
                Inputs.Add(new List <double>(aux));

                aux = new List <double>(ob[i]);
                aux.RemoveRange(0, 12);
                Target.Add(new List <double>(aux));
            }


            if (!Worker.IsBusy)
            {
                chart3.Series.RemoveAt(0);
                chart3.Series.Add("Eroare");
                chart3.Series["Eroare"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
                Worker.RunWorkerAsync();
            }
        }
        private void Identificare_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();



            string         p    = $"{Path.GetDirectoryName(Application.ExecutablePath)}\\TestSample\\ Identificare.wav";
            VerificareForm form = new VerificareForm(p, DeviceNumber);

            List <NAudio.Wave.WaveInCapabilities> sourse = new List <NAudio.Wave.WaveInCapabilities>();

            for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
            {
                sourse.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
            }

            if (!(sourse.Count >= DeviceNumber - 1))
            {
                DeviceNumber = sourse.Count() - 1;
            }

            form.ShowDialog();
            if (!File.Exists(p))
            {
                MessageBox.Show("Eroare, inregistrarea nu a fost efectuata cu succes");
                return;
            }
            List <List <double> > aux = new List <List <double> >(DoMFCC(p));

            re = new List <double>();
            st = new List <string>();

            foreach (string item in Directory.GetFiles("Users"))
            {
                FileInfo f = new FileInfo(item);
                rs = new ReteaNeuronala(12, 1, nrNeuroni, 1);
                if (!File.Exists($"{Path.GetDirectoryName(Application.ExecutablePath)}\\Weights\\{f.Name}.txt"))
                {
                    rs.ExportXML(f.Name);
                }
                rs.ImportXML(f.Name);
                List <List <double> > Rezultate = new List <List <double> >();
                for (int i = 0; i < aux.Count; i++)
                {
                    List <double> target = new List <double>();
                    target.Add(1);
                    List <double> Inputs = new List <double>(aux[i]);
                    Rezultate.Add(rs.ForWordPropagation(Inputs, target));
                }

                List <double> rez  = new List <double>();
                List <double> targ = new List <double>();
                for (int i = 0; i < Rezultate.Count; i++)
                {
                    List <double> au    = new List <double>(Rezultate[i]);
                    double        value = au[0];
                    rez.Add(value);
                    targ.Add(1);
                }

                double eroare = Eroarre(rez, targ);
                if (Verificare_Label.Text == "NaN%")
                {
                    MessageBox.Show("Inregistrare esuata");
                    return;
                }
                else
                {
                    re.Add(eroare);
                    st.Add(f.Name);
                }
            }

            Sort();

            for (int i = 0; i < st.Count; i++)
            {
                listBox2.Items.Add(st[i] + $"-> {re[i]}%");
            }
        }