Beispiel #1
0
 private void Textlist_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     this.Invoke(new MethodInvoker(delegate()
     {
         string newtxt = e.NewItems[0].ToString();
         listBox1.Items.Add(e.NewItems[0]);
         if (newtxt.Contains("Iteration"))
         {
             label7.Text = e.NewItems[0].ToString();
         }
         if (newtxt.Contains("Sequence "))
         {
             // var lista = MainGA.fitness.Where(x => x.Individual.Contains(textBox1.Text)).ToList();
             var lista = MainGA.fitness.Where(x => x.Histogramdistance == MainGA.fitness.Max(r => r.Histogramdistance)).ToList();
             if (lista.Count > 0)
             {
                 //  string s=textlist.Where(l => l.Contains(textBox1.Text+"x")).FirstOrDefault();
                 testfitness   = lista[0];
                 textBox1.Text = lista[0].Individual;
                 textBox2.Text = lista[0].Histogramdistance + "";
                 textBox3.Text = lista[0].Cleanupperrange + "";
                 textBox5.Text = lista[0].Lowerupperrange + "";
                 textBox4.Text = lista[0].Crossentropy + "";
                 textBox7.Text = lista[0].Crossentropy_PDE + "";
                 textBox6.Text = lista[0].Lvalue + "";
                 test          = true;
                 testac();
             }
         }
     }));
 }
        private Fitnessvalues DifferenceMethod()
        {
            Lvalueavg = Math.Abs(Lcleanvalueavg - Ladvvalueavg);
            //   Lvalueavg = 1 / Lvalueavg;


            double distance           = 0.0;
            double distancepercentage = 0.0;

            if (cleanupperrange > adversupperrange && cleanlowerrange > adversupperrange)
            {
                distance           = cleanlowerrange - adversupperrange;
                distancepercentage = distance / cleanlowerrange;
                distance           = distance * distance;
            }
            else if (adversupperrange > cleanupperrange && adverselowerrange > cleanupperrange)
            {
                distance           = adverselowerrange - cleanupperrange;
                distancepercentage = distance / adverselowerrange;
                distance           = distance * distance;
            }
            else
            {
                distance           = Math.Abs(adversupperrange + adverselowerrange - cleanupperrange - cleanlowerrange);
                distancepercentage = distance / adversupperrange;
            }
            // diff = distance;


            double lbp_distance = 0.0;

            if (lbp_cleanupperrange > lbp_adversupperrange && lbp_cleanlowerrange > lbp_adversupperrange)
            {
                lbp_distance = lbp_cleanlowerrange - lbp_adversupperrange;
                lbp_distance = lbp_distance * lbp_distance;
            }
            else if (lbp_adversupperrange > lbp_cleanupperrange && lbp_adverselowerrange > lbp_cleanupperrange)
            {
                lbp_distance = lbp_adverselowerrange - lbp_cleanupperrange;
                lbp_distance = lbp_distance * lbp_distance;
            }
            else
            {
                lbp_distance = Math.Abs(lbp_adversupperrange + lbp_adverselowerrange - lbp_cleanupperrange - lbp_cleanlowerrange);
            }


            Accord.Math.Distances.Euclidean euclidean = new Accord.Math.Distances.Euclidean();

            var p = Array.ConvertAll <int, double>(adv_histogram.ToArray(), x => (double)x / (double)adv_histogram.Max);
            var q = Array.ConvertAll <int, double>(clean_histogram.ToArray(), x => (double)x / (double)clean_histogram.Max);

            //   foreach(var b in q)
            //      Console.Write(b + "");
            var plist = p.ToList();
            var qlist = q.ToList();

            double ecu_distance  = euclidean.Distance(p, q);
            double crossentropyp = CEL.Crossentropy(plist, plist);
            double crossentropyq = CEL.Crossentropy(qlist, qlist);
            double crossentropy  = CEL.Crossentropy(plist, qlist);
            //   Console.WriteLine(sta + " crossentropy " + crossentropyp + " " + crossentropyq + " " + crossentropy);
            // var adv_normal = new NormalDistribution(mean: plist.Average(), stdDev: plist.StdDev);
            //   var clean_normal = new NormalDistribution(mean: clean_histogram.Mean, stdDev: clean_histogram.StdDev);
            double crossentropyppde = CEL.CrossentropyPDE(plist, plist);
            double crossentropyqpde = CEL.CrossentropyPDE(qlist, qlist);
            double crossentropypde  = CEL.CrossentropyPDE(qlist, plist);;
            //     Console.WriteLine(sta + " crossentropypde " + crossentropyppde + " " + crossentropyqpde + " " + crossentropypde);
            double deltax = 0 - lbp_distance;// point1[0];
            double deltay = 0 - distance;
            double deltaz = 0 - ecu_distance;

            diff = (double)Math.Sqrt(
                (deltax * deltax) +
                (deltay * deltay) +
                (deltaz * deltaz));
            //  Console.WriteLine(sta+ " fitness " + diff+"-"+ ecu_distance + "-"+ lbp_distance);


            euc_cleanupperrange = clean_histogram.Mean + clean_histogram.StdDev;
            euc_cleanlowerrange = clean_histogram.Mean - clean_histogram.StdDev;

            string sa = sta + ", LVALUE, " + Lvalueavg + " fitness ," + diff + "," + ecu_distance + "," + lbp_distance + " ," + crossentropy + " ," + crossentropypde;
            //  if (!MainGA.recodedfilters.Contains(sta + "," + diff + "," + cleanupperrange + "," + cleanlowerrange + "," + lbp_cleanupperrange + "," + lbp_cleanlowerrange + "," + euc_cleanupperrange + "," + euc_cleanlowerrange));
            //   MainGA.recodedfilters.Add(sta + "," + diff + "," + cleanupperrange + "," + cleanlowerrange + "," + lbp_cleanupperrange + "," + lbp_cleanlowerrange + "," + euc_cleanupperrange + "," + euc_cleanlowerrange);


            Fitnessvalues fitnessvalues = new Fitnessvalues();

            fitnessvalues.Individual        = sta;
            fitnessvalues.Histogramdistance = diff;
            fitnessvalues.Cleanupperrange   = cleanupperrange;
            fitnessvalues.Lowerupperrange   = cleanlowerrange;

            fitnessvalues.Lbp_distance        = lbp_distance;
            fitnessvalues.Lbp_cleanupperrange = lbp_cleanupperrange;
            fitnessvalues.Lbp_lowerupperrange = lbp_cleanlowerrange;

            fitnessvalues.Ecu_distance        = Math.Abs(ecu_distance);
            fitnessvalues.Ecu_histogram_clean = clean_histogram;
            fitnessvalues.Ecu_histogram_adv   = adv_histogram;

            fitnessvalues.Lvalue = Lvalueavg;

            fitnessvalues.Crossentropy       = crossentropy;
            fitnessvalues.Crossentropy_clean = crossentropyq;
            fitnessvalues.Crossentropy_adv   = crossentropyp;

            fitnessvalues.Crossentropy_PDE       = crossentropypde;
            fitnessvalues.Crossentropy_PDE_clean = crossentropyqpde;
            fitnessvalues.Crossentropy_PDE_adv   = Math.Abs(crossentropyppde);

            MainGA.fitness.Add(fitnessvalues);

            return(fitnessvalues);
        }