protected override void Subsumption(Population Pop)
        {
            Classifier Cl = null;

            foreach (Classifier C in this.CList)
            {
                if (C.CouldSubsume())
                {
                    if ((Cl == null) || (C.C.NumberOfSharp > Cl.C.NumberOfSharp) || ((C.C.NumberOfSharp == Cl.C.NumberOfSharp) && (Configuration.MT.NextDouble() < 0.5)))
                    {
                        Cl = C;
                    }
                }
            }

            if (Cl != null)
            {
                // 削除中にforeachできない
                List <Classifier> CL = new List <Classifier>();

                foreach (Classifier C in this.CList)
                {
                    if (Cl.IsMoreGeneral(C))
                    {
                        Cl.N += C.N;
                        // 削除Classifier登録
                        CL.Add(C);
                    }
                }

                foreach (Classifier C in CL)
                {
                    this.Remove(C);
                    Pop.Remove(C);
                }
            }
        }
        //学習終了後に圧縮にする
        public override void Compact()
        {
            List <Classifier> copyActionSet = new List <Classifier>();

            foreach (Classifier classifier in CList)
            {
                copyActionSet.Add(classifier);
            }

            int N = copyActionSet.Count;

            for (int i = 0; i < N; i++)
            {
                #region subsume
                Classifier Cl = null;

                //なかに最も一般的な分類子をClにする
                foreach (Classifier C in copyActionSet)
                {
                    if (C.CouldSubsume())
                    {
                        if ((Cl == null) || (C.C.NumberOfSharp > Cl.C.NumberOfSharp) || ((C.C.NumberOfSharp == Cl.C.NumberOfSharp) && (Configuration.MT.NextDouble() < 0.5)))
                        {
                            Cl = C;
                        }
                    }
                }

                //Cl が包摂できる分類子を吸収する
                if (Cl != null)
                {
                    // 削除中にforeachできない
                    List <Classifier> CL = new List <Classifier>();

                    foreach (Classifier C in copyActionSet)
                    {
                        if (Cl.IsMoreGeneral(C))
                        {
                            SigmaNormalClassifier Snc_ko  = (SigmaNormalClassifier)C;
                            SigmaNormalClassifier Snc_oya = (SigmaNormalClassifier)Cl;
                            //10の数字は適当 可変にするか? 1/10にする 10-7 あんまり変わらない
                            //分散が同じの判断基準 他に??t test を使う 予定  特殊化がでない
                            //
                            //double t = (Snc_oya.M - Snc_ko.M)/Math.Sqrt(Snc_oya.S/30 + Snc_ko.S/30);

                            //double studentT = StudentT.InvCDF(0, 1, 60, 0.005);

                            //if (t < studentT || t > Math.Abs(studentT))//t test で有意差がある 包摂しない
                            //{

                            //}
                            // else//有意差がない 統合しでもよい ただ 特殊化ルールどう識別するか
                            //{
                            if (/*Math.Abs(Cl.M - C.M) < 10 &&*/
                                // Math.Abs(Cl.Epsilon_0 - C.Epsilon_0)< 10&&
                                // Cl.Kappa == 1
                                //&& Snc_oya.Epsilon < Snc_ko.Epsilon
                                (Cl.Epsilon_0 < C.Epsilon_0 || Math.Abs(Cl.Epsilon_0 - C.Epsilon_0) < Cl.Epsilon_0 / 10)
                                //&& Math.Abs(Cl.Epsilon_0 - C.Epsilon_0) < 10//case 1 +- 10
                                // Cl.Epsilon < C.Epsilon
                                && Snc_ko.IsConvergenceEpsilon() &&
                                Snc_oya.IsConvergenceEpsilon()

                                ) //
                            {
                                Cl.N += C.N;
                                // 包摂された、削除したいClassifier C をCLに登録
                                CL.Add(C);
                            }
                            // }
                        }
                    }

                    foreach (Classifier C in CL)
                    {
                        this.Remove(C);//包摂された分類子 C を pop からCを削除
                    }
                }

                //最も一般化されるもの copyActionSetからを削除 
                copyActionSet.Remove(Cl);

                #endregion
            }
        }
Example #3
0
        // 包摂
        protected override void Subsumption(Population Pop)
        {
            List <Classifier> copyActionSet = new List <Classifier>();

            foreach (Classifier classifier in CList)
            {
                copyActionSet.Add(classifier);
            }
            int N = copyActionSet.Count;

            //最大N回実行する
            //for (int i = 0; i < N; i++)
            //{
            #region subsume
            Classifier Cl = null;

            //actionsetなかに最も一般的な分類子をClにする
            foreach (Classifier C in copyActionSet)
            {
                if (C.CouldSubsume())
                {
                    if ((Cl == null) || (C.C.NumberOfSharp > Cl.C.NumberOfSharp) || ((C.C.NumberOfSharp == Cl.C.NumberOfSharp) && (Configuration.MT.NextDouble() < 0.5)))
                    {
                        Cl = C;
                    }
                }
            }

            if (Cl != null)
            {
                // 削除中にforeachできない

                List <Classifier> CL = new List <Classifier>();

                // 包摂された、削除したいClassifier C をCLに登録
                foreach (Classifier C in copyActionSet)
                {
                    if (Cl.IsMoreGeneral(C))
                    {
                        SigmaNormalClassifier Snc_ko  = (SigmaNormalClassifier)C;
                        SigmaNormalClassifier Snc_oya = (SigmaNormalClassifier)Cl;

                        // e0 の値を3位まで見る、近いものは差がないとみなす
                        var subsumer = Math.Round(Cl.Epsilon_0, 3);
                        var subsumed = Math.Round(C.Epsilon_0, 3);

                        if ((subsumer <= (subsumed + subsumer / 10)) &&
                            Snc_ko.IsConvergenceEpsilon() &&
                            Snc_oya.IsConvergenceEpsilon()
                            )
                        {
                            Cl.N += C.N;

                            CL.Add(C);
                        }
                    }
                }

                foreach (Classifier C in CL)
                {
                    SigmaNormalClassifier SNC = (SigmaNormalClassifier)Cl;


                    if (C.C.state[4] == '0' & C.C.state[7] == '1')    //"bath0 rehabi1"
                    {
                        Configuration.Problem.WriteLine(C.C.state + "," + Configuration.T + "," + C.P + "," + C.M + "," + C.Epsilon + "," + C.F + "," + C.N + "," + C.Exp + "," + C.Ts + "," + C.As + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.St + "," + C.GenerateTime + ", in AS");
                    }

                    this.Remove(C);   //as から削除
                    Pop.Remove(C);    //pop から削除
                }

                //いまの最も一般化されたものを削除する
                //copyActionSet.Remove(Cl);
            }
            #endregion
            //}
        }