Ejemplo n.º 1
0
 private void btn_Pso10000_Click(object sender, EventArgs e)
 {
     for (int it = 0; it < 10000; it++)
     {
         W = GeneralCom.GetRandom(0.1, 0.9);
         C1 = GeneralCom.GetRandom(0.1, 2);
         C2 = GeneralCom.GetRandom(0.1, 2);
         Pso ps = new Pso(C, _n, M, W, C1, C2, 30, _data[0].DataDim.Val.Length, _data, _maxD);
         int i = 0;
         for (i = 0; i < 200; i++)
         {
             ps.Calc();
             if (ps.Variance < _rate)
                 break;
         }
         File.AppendAllText("PSOIterate", it + ";" + W + ";" + C1 + ";" + C2 + ";" + i + ";" + ps.GloablBestFitness + ";" + "\t\n");
     }
 }
Ejemplo n.º 2
0
 private void btn_PSOFCMRR_Click(object sender, EventArgs e)
 {
     _data = _data.OrderBy(x => Guid.NewGuid()).ToList();
     int step = 100;
     var tempData = _data.Skip(0).Take(step).ToList();
     var now = DateTime.Now;
     _n=tempData.Count;
     Pso ps = new Pso(C, _n, M, W, C1, C2, 30, _data[0].DataDim.Val.Length, tempData, _maxD);
     for (int i = 0; i < 200; i++)
     {
         ps.Calc();
         if (ps.Variance < _rate)
             break;
     }
     Fcm fc = new Fcm(C, _n, M, 30, _data[0].DataDim.Val.Length, tempData, ps.U);
     for (int a = 0; a < 100; a++)
     {
         fc.CalcCenter();
         fc.CalcU();
         fc.CalcFitness(_data, M);
         //File.AppendAllText(DateSet + "//FitnessFCMPSO", fc.Fitness + "\t;\t" + DateTime.Now.Subtract(now).TotalSeconds + "\t\n");
     }
     var aCenters = fc.Centers.OrderBy(p => p.Val[0]).ThenBy(p => p.Val[1]).ThenBy(p => p.Val[2]).ThenBy(p => p.Val[3]).ThenBy(p => p.Val[4]).ToArray();
     for (int it = 0; it < 1000; it++)
     {
         tempData.AddRange(_data.Skip(it*step+step).Take(step).ToList());
         _n = tempData.Count;
         ps = new Pso(C, _n, M, W, C1, C2, 30, _data[0].DataDim.Val.Length, tempData, _maxD,aCenters);
         for (int i = 0; i < 200; i++)
         {
             ps.Calc();
             if (ps.Variance < _rate)
                 break;
         }
         fc = new Fcm(C, _n, M, 30, _data[0].DataDim.Val.Length, tempData, ps.U);
         for (int a = 0; a < 100; a++)
         {
             fc.CalcCenter();
             fc.CalcU();
             fc.CalcFitness(_data, M);
         }
         double delta = 0;
         var bCenters = fc.Centers.OrderBy(p => p.Val[0]).ThenBy(p => p.Val[1]).ThenBy(p => p.Val[2]).ThenBy(p => p.Val[3]).ThenBy(p => p.Val[4]).ToArray();
         for(int d=0;d<aCenters.Length;d++)
         {
             delta += GeneralCom.Euclideandistance(aCenters[d], bCenters[d]);    
         }
         delta /= aCenters.Length;
         File.AppendAllText(DateSet + "//RRR100", delta + "\t;\t" + fc.Fitness + "\t;\t" + DateTime.Now.Subtract(now).TotalSeconds + "\t;\t" + aCenters.Aggregate("", (current, d) => current + (d + "&")) + "\t;\t" + bCenters.Aggregate("", (current, d) => current + (d + "&")) + "\t\n");
         aCenters = bCenters;
         //MessageBox.Show(delta.ToString());
     }
 }
Ejemplo n.º 3
0
        private void btn_PSOFCM_Click(object sender, EventArgs e)
        {
            Pso ps = new Pso(C, _n, M, W, C1, C2, 30, _data[0].DataDim.Val.Length, _data, _maxD);
            //File.WriteAllText("log", "");
            //File.WriteAllText("FitnessParticle", "");
            File.WriteAllText(DateSet + "//FitnessPSO", "");
            File.WriteAllText(DateSet + "//FitnessFCMPSO", "");
            //File.WriteAllText("datares", "");
            //File.WriteAllText("datafcm", "");
            var now = DateTime.Now;
            for (int i = 0; i < 200; i++)
            {
                ps.Calc();
                File.AppendAllText(DateSet + "//FitnessPSO", ps.GloablBestFitness + "\t\n");
                //File.AppendAllText("log", ps.GloablBestError + "\t;\t" + ps.Variance + "\t\n");
                if (ps.Variance < _rate)
                    break;
            }

            //for (int i = 0; i < ps.N; i++)
            //{
            //    for (int j = 0; j < ps.C; j++)
            //    {
            //        File.AppendAllText("datares", ps.U[i, j].ToString(CultureInfo.InvariantCulture) + ";");
            //    }
            //    File.AppendAllText("datares", "\t\n");
            //}
            Fcm fc = new Fcm(C, _n, M, 30, _data[0].DataDim.Val.Length, _data, ps.U);

            for (int a = 0; a < 100; a++)
            {
                fc.CalcCenter();
                fc.CalcU();
                fc.CalcFitness(_data, M);
                File.AppendAllText(DateSet+"//FitnessFCMPSO", fc.Fitness + "\t;\t"+DateTime.Now.Subtract(now).TotalSeconds + "\t\n");
                
            }
            //for (int i = 0; i < ps.N; i++)
            //{
            //    for (int j = 0; j < ps.C; j++)
            //    {
            //        File.AppendAllText(DateSet + "//datafcm", fc.U[i, j].ToString(CultureInfo.InvariantCulture) + ";");
            //    }
            //    File.AppendAllText(DateSet + "//datafcm", "\t\n");
            //}

        }