コード例 #1
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");
            //}
        }
コード例 #2
0
        private void btn_FCM_Click(object sender, EventArgs e)
        {
            File.WriteAllText(DateSet + "//FitnessFCM", "");
            //File.WriteAllText(DateSet + "datafcm", "");
            var now = DateTime.Now;

            double[,] U = new double[_n, C];
            for (int i = 0; i < _n; i++)
            {
                double[] tem = new double[C];
                double   sum = 0;
                for (int j = 0; j < C; j++)
                {
                    tem[j] = GeneralCom.GetRandom() + 0.001;
                    sum   += tem[j];
                }
                for (int j = 0; j < C; j++)
                {
                    U[i, j] = tem[j] / sum;
                }
            }
            Fcm fc = new Fcm(C, _n, M, 30, _data[0].DataDim.Val.Length, _data, U);

            for (int a = 0; a < 100; a++)
            {
                fc.CalcCenter();
                fc.CalcU();
                fc.CalcFitness(_data, M);
                File.AppendAllText(DateSet + "//FitnessFCM", fc.Fitness + "\t;\t" + DateTime.Now.Subtract(now).TotalSeconds + "\t\n");
            }
            //for (int i = 0; i < _n; i++)
            //{
            //    for (int j = 0; j < C; j++)
            //    {
            //        File.AppendAllText(DateSet + "//datafcm", fc.U[i, j].ToString(CultureInfo.InvariantCulture) + ";");
            //    }
            //    File.AppendAllText(DateSet + "//datafcm", "\t\n");
            //}
        }
コード例 #3
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());
            }
        }