Ejemplo n.º 1
0
        // Sigmaは飾り
        public override void Update(Population Pop, double P, StdList Sigma)
        {
            double SumNumerosity = 0;

            foreach (Classifier C in this.CList)
            {
                SumNumerosity += C.N;
            }

            foreach (Classifier C in this.CList)
            {
                C.Exp++;

                if (C.Exp < 1 / Configuration.Beta)
                {
                    C.P += (P - C.P) / C.Exp;
                }
                else
                {
                    C.P += Configuration.Beta * (P - C.P);
                }

                if (C.Exp < Configuration.Beta)
                {
                    C.Epsilon += (Math.Abs(P - C.P) - C.Epsilon) / C.Exp;
                }
                else
                {
                    C.Epsilon += Configuration.Beta * (Math.Abs(P - C.P) - C.Epsilon);
                }

                if (C.Exp < Configuration.Beta)
                {
                    C.As += (SumNumerosity - C.As) / C.Exp;
                }
                else
                {
                    C.As += Configuration.Beta * (SumNumerosity - C.As);
                }

                //if( C.C.state == "11####" && C.A == '0' )
                //{
                //	Configuration.ESW.WriteLine( Configuration.T + "," + C.F + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.Epsilon + "," + C.Exp + "," + Math.Sqrt( C.S / ( C.St - 1 ) ) );
                //	//Console.WriteLine( Configuration.T + " " + this.Exp );
                //}

                // 標準偏差計算
                C.St++;
                double X = P - C.M;
                C.M += X / C.St;
                C.S += (C.St - 1) * X * X / C.St;
            }

            this.UpdateFitness();

            if (Configuration.DoActionSetSubsumption)
            {
                this.Subsumption(Pop);
            }
        }
Ejemplo n.º 2
0
        public StdList Clone()
        {
            var clone = new StdList();

            clone.C = C;
            clone.T = T;
            clone.M = M;
            clone.S = S;
            return(clone);
        }
Ejemplo n.º 3
0
        public override void Update( Population Pop, double P, StdList Sigma )
        {
            double SumNumerosity = 0;
            foreach( Classifier C in this.CList )
            {
                SumNumerosity += C.N;
            }

            //if( Configuration.URE_Epsilon0 != Configuration.Rho )
            //{
            //	Configuration.URE_Epsilon0 += Configuration.Epsilon_0 * 5;

            //	foreach( Classifier C in this.CList )
            //	{
            //		C.Epsilon_0 += Configuration.Beta * ( Configuration.URE_Epsilon0 - C.Epsilon_0 );
            //	}
            //}
            //else
            //{
            //if( SNC.IsConvergenceEpsilon() && Sigma.IsConvergenceSigma() )
            //{

            //	foreach( Classifier C in this.CList )
            //	{

            //	}
            //}
            //}

            foreach( Classifier C in this.CList )
            {
                C.Exp++;

                if( C.Exp < 1 /Configuration.Beta )
                {
                    C.P += ( P - C.P ) / C.Exp;
                }
                else
                {
                    C.P += Configuration.Beta * ( P - C.P );
                }

                //if( C.Exp < Configuration.Beta )  // 9-23 張 ここscript は exp < 1/beta
                if (C.Exp < Configuration.Beta)
                {
                    C.As += ( SumNumerosity - C.As ) / C.Exp;
                }
                else
                {
                    C.As += Configuration.Beta * ( SumNumerosity - C.As );
                }

                if( C.C.state == "11###0" && C.A == '1' )
                {
                    //Configuration.ESW.WriteLine( Configuration.T + "," + C.F + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.Epsilon + "," + C.Exp + "," + Math.Sqrt( C.S / ( C.St - 1 ) ) );
                    //Console.WriteLine( Configuration.T + " " + C.Exp );
                }

                // 標準偏差計算
                C.St++;
                double X = P - C.M;
                C.M += X / C.St;
                C.S += ( C.St - 1 ) * X * X / C.St;

                if( C.GetType().Name == "SigmaNormalClassifier" )
                {
                    // このIterationまでのepsilonを記録ずらし
                    SigmaNormalClassifier SNC = ( SigmaNormalClassifier )C;
                    for( int index = SNC.EpsilonList.Count() - 1; index > 0; index-- )
                    {
                        SNC.EpsilonList[index] = SNC.EpsilonList[index - 1];
                    }

                    SNC.EpsilonList[0] = Math.Sqrt(C.S / (C.St - 1));

                    //bool StateFlag = true;
                    //foreach(StdList SL in Configuration.Stdlist)
                    //{
                    //	// 分類子に含まれるstate
                    //	//if(SL.IsIncluded(SNC.C.state, SNC.A))
                    //	//{
                    //		// 一つでも収束していなければ
                    //		if(!SL.IsConvergenceSigma())
                    //		{
                    //			StateFlag = false;
                    //		}
                    //	//}
                    //}
                    //if( SNC.IsConvergenceEpsilon() )
                    //if( SNC.IsConvergenceEpsilon() && StateFlag )

                    if( Sigma.IsConvergenceSigma() )
                    {
                        double sigma_a=0;
                        double sigma_b=0;
                        //9-24 張 1#00 算出する時用のもの追加
                        if(C.C.state=="1#00##")
                        {
                            //1100 と 1000 のsigma で1#00を更新
                            foreach(StdList SL in Configuration.Stdlist)
                            {
                            if(SL.C=="110000"){  sigma_a =SL.S;}
                            if(SL.C=="100000"){ sigma_b =SL.S;}

                            }

                            //sigma はvariancetableから
                            C.Epsilon_0 += Configuration.Beta * (Math.Sqrt(sigma_a*sigma_a +sigma_b*sigma_b) + Configuration.Epsilon_0 - C.Epsilon_0);
                        }
                        if (C.C.state == "#100##")
                        {
                            //1100 と 1000 のsigma で1#00を更新
                            foreach (StdList SL in Configuration.Stdlist)
                            {
                                if (SL.C == "110000") { sigma_a = SL.S; }
                                if (SL.C == "010000") { sigma_b = SL.S; }

                            }

                            //sigma はvariancetableから
                            C.Epsilon_0 += Configuration.Beta * (Math.Sqrt(sigma_a * sigma_a + sigma_b * sigma_b) + Configuration.Epsilon_0 - C.Epsilon_0);
                        }
                        if (C.C.state == "001###")
                        {
                            //1100 と 1000 のsigma で1#00を更新
                            foreach (StdList SL in Configuration.Stdlist)
                            {
                                if (SL.C == "001100") { sigma_a = SL.S; }
                                if (SL.C == "001000") { sigma_b = SL.S; }

                            }

                            //sigma はvariancetableから
                            C.Epsilon_0 += Configuration.Beta * (Math.Sqrt(sigma_a * sigma_a + sigma_b * sigma_b) + Configuration.Epsilon_0 - C.Epsilon_0);
                        }
                        if (C.C.state == "00#1##")
                        {
                            //1100 と 1000 のsigma で1#00を更新
                            foreach (StdList SL in Configuration.Stdlist)
                            {
                                if (SL.C == "001100") { sigma_a = SL.S; }
                                if (SL.C == "000100") { sigma_b = SL.S; }

                            }

                            //sigma はvariancetableから
                            C.Epsilon_0 += Configuration.Beta * (Math.Sqrt(sigma_a * sigma_a + sigma_b * sigma_b) + Configuration.Epsilon_0 - C.Epsilon_0);
                        }
                        else
                        {
                        C.Epsilon_0 += Configuration.Beta * ( Sigma.S + Configuration.Epsilon_0 - C.Epsilon_0 );
                        }
                    }

                    if( SNC.IsConvergenceEpsilon() )
                    //if( SNC.IsConvergenceEpsilon() && StateFlag )
                    //if(SNC.Exp > 1)
                    //if(SNC.IsConvergenceEpsilon() && Sigma.IsConvergenceSigma())
                    {
                        Configuration.FlagSigma = true;
                        SNC.Epsilon = SNC.EpsilonList[0];

                        //SNC.Epsilon += Configuration.Beta * ( SNC.EpsilonList[0] - SNC.Epsilon );
                        //if( C.Exp < Configuration.Beta )
                        //{
                        //	C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                        //}
                        //else
                        //{
                        //	C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                        //}

                        //C.Epsilon_0 += Configuration.Beta * ( Sigma.S + Configuration.Epsilon_0 - C.Epsilon_0 );

                        //C.Epsilon_0 = Sigma.S + Configuration.Epsilon_0;
                        //C.Epsilon_0 = Sigma.S;
                    }
                    else
                    {
                        //if (C.Exp < Configuration.Beta)//9-23 張 ここscript は exp<Beta
                        if (C.Exp < Configuration.Beta)
                        {
                            C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                        }
                        else
                        {
                            C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                        }
                    }
                }
                else //SigmaNormalClassifier ではない場合
                {
                    //if( C.Exp < Configuration.Beta )//9-23 張 ここscript は exp<Beta
                    if (C.Exp < Configuration.Beta)
                    {
                        C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                    }
                    else
                    {
                        C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                    }
                }

                //if(C.St > 250)
                //{
                //C.Epsilon_0 += Configuration.Beta * (Configuration.Epsilon_0 + Math.Sqrt( C.S / ( C.St - 1 ) ) - C.Epsilon_0);
                //Console.WriteLine(C.Epsilon_0);
                //Console.WriteLine("st" + C.St);
                //}

                //if( Configuration.T > 5000 )
                //if(Configuration.IsConvergenceSigma())

            }

            this.UpdateFitness();

            if( Configuration.DoActionSetSubsumption )
            {
                this.Subsumption( Pop );
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Fitness更新
 /// </summary>
 /// <param name="Pop">Population</param>
 /// <param name="P">報酬の値</param>
 public abstract void Update( Population Pop, double P, StdList Sigma );
Ejemplo n.º 5
0
 /// <summary>
 /// Fitness更新
 /// </summary>
 /// <param name="Pop">Population</param>
 /// <param name="P">報酬の値</param>
 public abstract void Update( Population Pop, double P, StdList Sigma );
Ejemplo n.º 6
0
        public override void Update(Population Pop, double P, StdList Sigma)
        {
            double SumNumerosity = 0;

            foreach (Classifier C in this.CList)
            {
                SumNumerosity += C.N;
            }

            foreach (Classifier C in this.CList)
            {
                C.Exp++;

                if (C.Exp < 1 / Configuration.Beta)
                {
                    C.P  += (P - C.P) / C.Exp;
                    C.As += (SumNumerosity - C.As) / C.Exp;
                }
                else
                {
                    C.P  += Configuration.Beta * (P - C.P);
                    C.As += Configuration.Beta * (SumNumerosity - C.As);
                }

                // 標準偏差計算
                C.St++;
                double X = P - C.M;
                C.M += X / C.St;
                C.S += (C.St - 1) * X * X / C.St;                  //あっている??
                if (double.IsNaN(C.S))
                {
                    Console.ReadLine();
                }


                if (C.GetType().Name == "SigmaNormalClassifier")
                {
                    // このIterationまでのepsilonを記録ずらし
                    SigmaNormalClassifier SNC = ( SigmaNormalClassifier )C;
                    for (int index = SNC.EpsilonList.Count() - 1; index > 0; index--)
                    {
                        SNC.EpsilonList[index] = SNC.EpsilonList[index - 1];
                    }

                    SNC.EpsilonList[0] = Math.Sqrt(C.S / (C.St - 1));



#region 分類子が照合する全状態のVTの分散と平均を使って e0 を推測  chou 160107
                    //分類子が照合する全状態のVTの分散と平均を使って e0 を推測  chou 160107
                    if (Configuration.IsConvergenceVT)
                    {
                        if (C.Exp > 2)                      //0120 cho
                        {
                            if (SNC.IsConvergenceEpsilon()) //分類子のstd が収束するときepsilon を更新
                            {
                                C.Epsilon = SNC.EpsilonList[0];
                            }
                            else//epsilon収束しない場合 強化学習
                            {
                                if (C.Exp < Configuration.Beta)
                                {
                                    C.Epsilon += (Math.Abs(P - C.P) - C.Epsilon) / C.Exp;
                                }
                                else
                                {
                                    C.Epsilon += Configuration.Beta * (Math.Abs(P - C.P) - C.Epsilon);
                                }
                            }
                        }


                        Classifier cl0 = new NormalClassifier();

                        cl0.S  = 0;
                        cl0.M  = 0;
                        cl0.St = 0;
                        List <StdList> cpStdLists = new List <StdList>();

                        foreach (var std in Configuration.ConvergentedVT)
                        {
                            if (std.IsIncluded(C.C.state))
                            {
                                cpStdLists.Add(std.Clone()); //クローンメソット  
                            }
                        }
                        if (cpStdLists.Count == 1)
                        {
                            C.Epsilon_0 = cpStdLists[0].S + Configuration.Epsilon_0;
                        }
                        else
                        {
                            foreach (var std in cpStdLists)
                            {
                                //St 出現回数
                                cl0.St += std.T;
                                cl0.M  += std.M * std.T;
                            }

                            //ここst= 0 , cl0.M がNULLになる
                            cl0.M = cl0.M / cl0.St;

                            foreach (var std in cpStdLists)
                            {
                                cl0.S += std.T * Math.Pow(std.S, 2) + std.T * Math.Pow((cl0.M - std.M), 2);
                            }

                            cl0.S = Math.Sqrt(cl0.S / cl0.St);

                            C.Epsilon_0 = cl0.S + Configuration.Epsilon_0;
                        }
                    }
                    #endregion


                    #region tatumi 160106 XCS-SAC  VTが全部収束したら 加重平均でe0更新
                    //if (Configuration.IsConvergenceVT)
                    //{
                    //    //tatumi 160106 XCS-SAC  VTが全部収束したら 加重平均でe0更新
                    //    if (C.Exp > 2 && SNC.IsConvergenceEpsilon())//0120 cho
                    //    {

                    //        C.Epsilon = SNC.EpsilonList[0];
                    //    }

                    //    double WeightedSum = 0;
                    //    int WeightedCount = 0;
                    //    foreach (StdList SL in Configuration.Stdlist)
                    //    {
                    //        if (SL.IsIncluded(C.C.state))
                    //        {
                    //            if (!double.IsNaN(SL.S))
                    //            {
                    //                WeightedSum += (SL.T - 1) * Math.Pow(SL.S, 2);
                    //                WeightedCount += SL.T;
                    //            }
                    //        }
                    //    }
                    //    // 下駄適応済み
                    //    if (WeightedCount > 1)
                    //    {
                    //        WeightedSum = Math.Sqrt(WeightedSum / (WeightedCount - 1)) + Configuration.Epsilon_0;
                    //    }
                    //    else
                    //    {
                    //        WeightedSum = Configuration.Epsilon_0;
                    //    }
                    //    C.Epsilon_0 = WeightedSum;
                    //}
                    //else
                    //{
                    //    if (C.Exp < Configuration.Beta)
                    //    {
                    //        C.Epsilon += (Math.Abs(P - C.P) - C.Epsilon) / C.Exp;
                    //    }
                    //    else
                    //    {
                    //        C.Epsilon += Configuration.Beta * (Math.Abs(P - C.P) - C.Epsilon);
                    //    }
                    //}
                    #endregion
                }
                else                 //SigmaNormalClassifier ではない場合
                {
                    //if( C.Exp < Configuration.Beta )//9-23 張 ここscript は exp<Beta
                    if (C.Exp < Configuration.Beta)
                    {
                        C.Epsilon += (Math.Abs(P - C.P) - C.Epsilon) / C.Exp;
                    }
                    else
                    {
                        C.Epsilon += Configuration.Beta * (Math.Abs(P - C.P) - C.Epsilon);
                    }
                }
            }

            this.UpdateFitness();

            if (Configuration.DoActionSetSubsumption)
            {
                this.Subsumption(Pop);
            }
        }
        public override void Update( Population Pop, double P, StdList Sigma )
        {
            double SumNumerosity = 0;
            foreach( Classifier C in this.CList )
            {
                SumNumerosity += C.N;
            }

            //if( Configuration.URE_Epsilon0 != Configuration.Rho )
            //{
            //	Configuration.URE_Epsilon0 += Configuration.Epsilon_0 * 5;

            //	foreach( Classifier C in this.CList )
            //	{
            //		C.Epsilon_0 += Configuration.Beta * ( Configuration.URE_Epsilon0 - C.Epsilon_0 );
            //	}
            //}
            //else
            //{
            //if( SNC.IsConvergenceEpsilon() && Sigma.IsConvergenceSigma() )
            //{

            //	foreach( Classifier C in this.CList )
            //	{

            //	}
            //}
            //}

            foreach( Classifier C in this.CList )
            {
                C.Exp++;

                if( C.Exp < 1 / Configuration.Beta )
                {
                    C.P += ( P - C.P ) / C.Exp;
                }
                else
                {
                    C.P += Configuration.Beta * ( P - C.P );
                }

                if( C.Exp < Configuration.Beta )
                {
                    C.As += ( SumNumerosity - C.As ) / C.Exp;
                }
                else
                {
                    C.As += Configuration.Beta * ( SumNumerosity - C.As );
                }

                //if( C.C.state == "0000#######" && C.A == '0' )
                //{
                //	Configuration.ESW.WriteLine( Configuration.T + "," + C.F + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.Epsilon + "," + C.Exp + "," + Math.Sqrt( C.S / ( C.St - 1 ) ) );
                //	Console.WriteLine( Configuration.T + " " + C.Exp );
                //}

                //if( C.C.state == "10##0#" && C.A == '0' )
                //{
                //	Configuration.ESW.WriteLine( Configuration.T + "," + C.F + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.Epsilon + "," + C.Exp + "," + Math.Sqrt( C.S / ( C.St - 1 ) ) );
                //	//Console.WriteLine( Configuration.T + " " + this.Exp );
                //}

                // 標準偏差計算
                C.St++;
                double X = P - C.M;
                C.M += X / C.St;
                C.S += ( C.St - 1 ) * X * X / C.St;

                if( C.GetType().Name == "SigmaNormalClassifier" )
                {
                    // このIterationまでのepsilonを記録ずらし
                    SigmaNormalClassifier SNC = ( SigmaNormalClassifier )C;
                    for( int index = SNC.EpsilonList.Count() - 1; index > 0; index-- )
                    {
                        SNC.EpsilonList[index] = SNC.EpsilonList[index - 1];
                    }

                    SNC.EpsilonList[0] = Math.Sqrt( C.S / ( C.St - 1 ) );

                    //bool StateFlag = true;
                    //foreach(StdList SL in Configuration.Stdlist)
                    //{
                    //	// 分類子に含まれるstate
                    //	//if(SL.IsIncluded(SNC.C.state, SNC.A))
                    //	//{
                    //		// 一つでも収束していなければ
                    //		if(!SL.IsConvergenceSigma())
                    //		{
                    //			StateFlag = false;
                    //		}
                    //	//}
                    //}
                    //if( SNC.IsConvergenceEpsilon() )
                    //if( SNC.IsConvergenceEpsilon() && StateFlag )

                    if( Sigma.IsConvergenceSigma() )
                    {
                        C.Epsilon_0 += Configuration.Beta * ( Sigma.S + Configuration.Epsilon_0 - C.Epsilon_0 );
                    }

                    if( C.Exp < Configuration.Beta )
                    {
                        C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                    }
                    else
                    {
                        C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                    }

                }
                else
                {
                    if( C.Exp < Configuration.Beta )
                    {
                        C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                    }
                    else
                    {
                        C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                    }
                }

                //if(C.St > 250)
                //{
                //C.Epsilon_0 += Configuration.Beta * (Configuration.Epsilon_0 + Math.Sqrt( C.S / ( C.St - 1 ) ) - C.Epsilon_0);
                //Console.WriteLine(C.Epsilon_0);
                //Console.WriteLine("st" + C.St);
                //}

                //if( Configuration.T > 5000 )
                //if(Configuration.IsConvergenceSigma())

            }

            this.UpdateFitness();

            if( Configuration.DoActionSetSubsumption )
            {
                this.Subsumption( Pop );
            }
        }
Ejemplo n.º 8
0
 public StdList(StdList toCopy)
 {
     this.T = toCopy.T;
     this.M = toCopy.M;
     this.S = toCopy.S;
 }
        // Sigmaは飾り
        public override void Update( Population Pop, double P, StdList Sigma )
        {
            double SumNumerosity = 0;
            foreach( Classifier C in this.CList )
            {
                SumNumerosity += C.N;
            }

            foreach( Classifier C in this.CList )
            {
                C.Exp++;

                if( C.Exp < 1 / Configuration.Beta )
                {
                    C.P += ( P - C.P ) / C.Exp;
                }
                else
                {
                    C.P += Configuration.Beta * ( P - C.P );
                }

                if( C.Exp < Configuration.Beta )
                {
                    C.Epsilon += ( Math.Abs( P - C.P ) - C.Epsilon ) / C.Exp;
                }
                else
                {
                    C.Epsilon += Configuration.Beta * ( Math.Abs( P - C.P ) - C.Epsilon );
                }

                if( C.Exp < Configuration.Beta )
                {
                    C.As += ( SumNumerosity - C.As ) / C.Exp;
                }
                else
                {
                    C.As += Configuration.Beta * ( SumNumerosity - C.As );
                }

                //if( C.C.state == "11####" && C.A == '0' )
                //{
                //	Configuration.ESW.WriteLine( Configuration.T + "," + C.F + "," + C.Kappa + "," + C.Epsilon_0 + "," + C.Epsilon + "," + C.Exp + "," + Math.Sqrt( C.S / ( C.St - 1 ) ) );
                //	//Console.WriteLine( Configuration.T + " " + this.Exp );
                //}

                // 標準偏差計算
                C.St++;
                double X = P - C.M;
                C.M += X / C.St;
                C.S += ( C.St - 1 ) * X * X / C.St;
            }

            this.UpdateFitness();

            if( Configuration.DoActionSetSubsumption )
            {
                this.Subsumption( Pop );
            }
        }
Ejemplo n.º 10
0
        public static void Experiment(Environment Env, Population P)
        {
            // 変数初期化
            Configuration.T = 0;
            ActionSet PreviousAS  = null;
            double    PreviousRho = 0;
            State     PreviousS   = null;

            // stdlist収束
            bool ConvergenceStelist = false;

            // 移動平均計算用
            double[] RhoArray = new double[Configuration.Iteration];
            int[]    Num      = new int[Configuration.Iteration];
            //double[] Std = new double[Configuration.Iteration];

            Configuration.ZeroList = new List <double>();
            Configuration.OneList  = new List <double>();

            List <string> DataList         = Env.GetDataList();
            List <string> DistinctDataList = DataList.Distinct().ToList();

            int DistinctDataNum = DistinctDataList.Count();

            // 提案手法 入力データ個数分の分散
            Configuration.Stdlist = new StdList[DistinctDataNum];
            // 収束した VTの値を保存する  ちょう
            Configuration.ConvergentedVT = new StdList[DistinctDataNum];

            for (int i = 0; i < DistinctDataNum; i++)
            {
                Configuration.ConvergentedVT[i] = new StdList(DistinctDataList[i], '0');
                //Configuration.ConvergentedVT[i * 4 + 1] = new StdList(i, '1');
            }
            for (int i = 0; i < DistinctDataNum; i++)
            {
                Configuration.Stdlist[i] = new StdList(DistinctDataList[i], '0');
                //Configuration.Stdlist[i * 4 + 1] = new StdList( i, '1' );
            }

            // 実験1a ノイズを既知のものとして扱う
            if (Configuration.ASName == "WellKnown")
            {
                Configuration.Epsilon_0 += Configuration.NoiseWidth;
            }

            Configuration.Problem.WriteLine("state ,iter,P , cl.M ,cl.Epsilon , cl.F , cl.N , cl.Exp , cl.Ts ,cl.As , cl.Kappa ,cl.Epsilon_0 , cl.St , cl.GenerateTime");
            StreamWriter goodsleep1 = new StreamWriter("./goodsleep_rule1.csv");

            goodsleep1.WriteLine("state ,iter,P , cl.M ,cl.Epsilon , cl.F , cl.N , cl.Exp , cl.Ts ,cl.As , cl.Kappa ,cl.Epsilon_0 , cl.St , cl.GenerateTime");

            StreamWriter goodsleep2 = new StreamWriter("./goodsleep_rule2.csv");

            goodsleep2.WriteLine("state ,iter,P , cl.M ,cl.Epsilon , cl.F , cl.N , cl.Exp , cl.Ts ,cl.As , cl.Kappa ,cl.Epsilon_0 , cl.St , cl.GenerateTime");

            StreamWriter badsleep = new StreamWriter("./badsleep_rule.csv");

            badsleep.WriteLine("state ,iter,P , cl.M ,cl.Epsilon , cl.F , cl.N , cl.Exp , cl.Ts ,cl.As , cl.Kappa ,cl.Epsilon_0 , cl.St , cl.GenerateTime");
            // メインループ
            #region main roop
            while (Configuration.T < Configuration.Iteration)
            {
                // VTの収束
                if (!Configuration.IsConvergenceVT)
                {
                    bool flag = true;
                    //入力データのSLが収束すれば、VTが収束とみなす。
                    foreach (StdList SL in Configuration.Stdlist)
                    {
                        if (flag && !SL.IsConvergenceSigma())
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)   // 初めてTrue
                    {
                        Configuration.IsConvergenceVT = true;
                        //収束したVTを保存する
                        for (int i = 0; i < DistinctDataList.Count; i++)
                        {
                            Configuration.ConvergentedVT[i].M = Configuration.Stdlist[i].M;
                            //Configuration.ConvergentedVT[i * 4+1].M = Configuration.Stdlist[i * 2+1].M;


                            Configuration.ConvergentedVT[i].S = Configuration.Stdlist[i].S;
                            //Configuration.ConvergentedVT[i * 4 + 1].S = Configuration.Stdlist[i*2+1].S;

                            Configuration.ConvergentedVT[i].T = Configuration.Stdlist[i].T;
                            //Configuration.ConvergentedVT[i * 4 + 1].T = Configuration.Stdlist[i * 2 + 1].T;
                        }


                        // [P]の全てを新しい基準で再評価
                        foreach (Classifier C in P.CList)
                        {
                            // 加重平均
                            double ST   = 0;
                            int    SumT = 0;
                            foreach (StdList SL in Configuration.Stdlist)
                            {
                                if (SL.IsIncluded(C.C.state))
                                {
                                    ST   += SL.S * SL.T;
                                    SumT += SL.T;
                                }
                            }
                            ST /= SumT;

                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;
                            C.Epsilon_0 = ST + Configuration.Epsilon_0;
                            if (C.Exp > 2)
                            {
                                C.Epsilon = SNC.EpsilonList[0];
                            }
                        }
                    }
                }



                State S = Env.GetState();

                // MatchSet生成
                MatchSet M = new NormalMatchSet(S, P);

                foreach (Classifier cl in M.CList)
                {
                    if (cl.C.state[4] == '2' & cl.C.state[7] == '#')//"bath2  rehabi# or bath# rehabi0"
                    {
                        goodsleep1.WriteLine(cl.C.state + "," + Configuration.T + "," + cl.P + "," + cl.M + "," + cl.Epsilon + "," + cl.F + "," + cl.N + "," + cl.Exp + "," + cl.Ts + "," + cl.As + "," + cl.Kappa + "," + cl.Epsilon_0 + "," + cl.St + "," + cl.GenerateTime);
                    }
                    if (cl.C.state[4] == '#' & cl.C.state[7] == '0')//"bath2  rehabi# or bath# rehabi0"
                    {
                        goodsleep2.WriteLine(cl.C.state + "," + Configuration.T + "," + cl.P + "," + cl.M + "," + cl.Epsilon + "," + cl.F + "," + cl.N + "," + cl.Exp + "," + cl.Ts + "," + cl.As + "," + cl.Kappa + "," + cl.Epsilon_0 + "," + cl.St + "," + cl.GenerateTime);
                    }
                }
                foreach (Classifier cl in P.CList)
                {
                    if (cl.C.state[4] == '0' & cl.C.state[7] == '1')//"bath0 rehabi1"
                    {
                        badsleep.WriteLine(cl.C.state + "," + Configuration.T + "," + cl.P + "," + cl.M + "," + cl.Epsilon + "," + cl.F + "," + cl.N + "," + cl.Exp + "," + cl.Ts + "," + cl.As + "," + cl.Kappa + "," + cl.Epsilon_0 + "," + cl.St + "," + cl.GenerateTime);
                    }
                }

                // ActionSetはただMをコピーするだけ,アクションがないから
                ActionSet AS;
                if (Configuration.ASName == "CS")
                {
                    AS = new ConditionSigmaActionSet(M.CList);
                }
                else
                {
                    AS = new NormalActionSet(M.CList); /*M.MatchAction(Action))*/;
                }


                char   Action = '0';//action ないから、全部0にする
                double Rho    = Env.ExecuteAction(Action);



                StdList Sigma = null;

                // 提案手法 分散の計算
                foreach (StdList SL in Configuration.Stdlist)
                {
                    if ((SL.C == S.state) /*&& ( SL.A == Action )*/)
                    {
                        // situationの分散取得
                        SL.Update(Rho);
                        Sigma = SL;
                    }
                }

                // 提案手法(中田)
                if (Configuration.ASName == "CS")
                {
                    Configuration.URE_Epsilon0 = -1;

                    // 最小値
                    double d = Configuration.Rho;

                    foreach (SigmaNormalClassifier C in AS.CList)
                    {
                        if (d > C.S && C.IsConvergenceEpsilon())
                        {
                            d = Math.Sqrt(C.S / (C.St - 1));
                        }
                    }

                    Configuration.URE_Epsilon0 = d;
                }
                //chou 1000回の報酬平均を保存

                if (Configuration.T < 1000)
                {
                    Configuration.RewardList.Add(Rho);
                }
                if (Configuration.T == 1000)
                {
                    Configuration.RewardAverage = Configuration.RewardList.Mean();
                }

                // マルチステップ問題の終着またはシングルステップ問題
                if (Env.Eop)
                {
                    double p = Rho;
                    AS.Update(P, p, Sigma);
                    AS.RunGA(S, P);                      //komine



                    PreviousAS = null;
                }
                else
                {
                    PreviousAS  = AS;
                    PreviousRho = Rho;
                    PreviousS   = S;
                }



                Num[Configuration.T] = P.CList.Count();
                //Std[Configuration.T] = Math.Sqrt( Stdlist[20].Sigma / (Stdlist[20].T - 1));

                if (Configuration.StartTime < 0 && Configuration.FlagSigma && Configuration.FlagEpsilon)
                {
                    Configuration.StartTime = Configuration.T;
                }
                Configuration.FlagSigma = Configuration.FlagEpsilon = false;



                if (!ConvergenceStelist && (Configuration.ASName == "CS" || Configuration.ASName == "MaxCS" || Configuration.ASName == "Max" || Configuration.ASName == "Updatee0CS"))
                {
                    int i = 1;

                    foreach (StdList SL in Configuration.Stdlist)
                    {
                        i *= (SL.IsConvergenceSigma() ? 1 : 0);
                    }

                    if (i == 1)
                    {
                        StreamWriter stdSw = new StreamWriter("./ConvergenceVT_" + Configuration.T + "_" + Configuration.Seed + "CnoiseWidth" + Configuration.NoiseWidth
                                                              + "AS_" + Configuration.ASName + "ET_" + Configuration.ExpThreshold + "DS_" + Configuration.DifferenceSigma + "LS_" + Configuration.LookBackSigma
                                                              + "DE_" + Configuration.DifferenceEpsilon + "LE_" + Configuration.LookBackEpsilon + ".csv", true, System.Text.Encoding.GetEncoding("shift_jis"));

                        stdSw.WriteLine("condition,action,sigma,average,time,convergence");
                        foreach (StdList SL in Configuration.Stdlist)
                        {
                            stdSw.WriteLine(SL.C + "," + SL.A + "," + SL.S + "," + SL.M + "," + SL.T + "," + (SL.IsConvergenceSigma() ? 1 : 0));                                // 1 : 収束
                        }
                        stdSw.Close();
                        ConvergenceStelist = true;
                    }
                }



                Configuration.T++;
                Console.WriteLine(Configuration.T);
            }
            P.Show();
            #endregion
            goodsleep1.Close();
            goodsleep2.Close();
            badsleep.Close();

            Configuration.Problem.Close();
            P.Compact();
            //P.Show();

            if ((Configuration.ASName == "CS" || Configuration.ASName == "MaxCS" || Configuration.ASName == "Max" || Configuration.ASName == "Updatee0CS"))
            {
                StreamWriter stdSw = new StreamWriter("./VarianceTable_" + Configuration.T + "_" + Configuration.Seed + "CnoiseWidth" + Configuration.NoiseWidth
                                                      + "AS_" + Configuration.ASName + "ET_" + Configuration.ExpThreshold + "DS_" + Configuration.DifferenceSigma + "LS_" + Configuration.LookBackSigma
                                                      + "DE_" + Configuration.DifferenceEpsilon + "LE_" + Configuration.LookBackEpsilon + ".csv", true, System.Text.Encoding.GetEncoding("shift_jis"));

                stdSw.WriteLine("condition,action,sigma,time,convergence,convergencetime");
                foreach (StdList SL in Configuration.Stdlist)
                {
                    stdSw.WriteLine(SL.C + "," + SL.A + "," + SL.S + "," + SL.T + "," + (SL.IsConvergenceSigma() ? 1 : 0) + "," + SL.ConvergenceTime);                          // 1 : 収束
                }
                stdSw.Close();
            }

            //LD.Close();


            StreamWriter sw = new StreamWriter("./performance_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
                                               + "AS_" + Configuration.ASName + "ET_" + Configuration.ExpThreshold + "DS_" + Configuration.DifferenceSigma + "LS_" + Configuration.LookBackSigma
                                               + "DE_" + Configuration.DifferenceEpsilon + "LE_" + Configuration.LookBackEpsilon + ".csv", true, System.Text.Encoding.GetEncoding("shift_jis"));



            sw.WriteLine("Performance,PopulationSize," + Configuration.StartTime);

            for (int i = 0; i < RhoArray.Count() - Configuration.SMA; i++)
            {
                double R = 0;
                double N = 0;
                for (int j = 0; j < Configuration.SMA; j++)
                {
                    R += RhoArray[i + j];
                    N += Num[i + j];
                }
                R /= Configuration.SMA;
                N /= Configuration.SMA;

                sw.WriteLine(R + "," + N);
            }

            sw.Close();



            StreamWriter Zerosw = new StreamWriter("./Zero_per_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
                                                   + "AS_" + Configuration.ASName + "ET_" + Configuration.ExpThreshold + "DS_" + Configuration.DifferenceSigma + "LS_" + Configuration.LookBackSigma
                                                   + "DE_" + Configuration.DifferenceEpsilon + "LE_" + Configuration.LookBackEpsilon + ".csv", true, System.Text.Encoding.GetEncoding("shift_jis"));


            Zerosw.WriteLine("Performance,dummy," + Configuration.StartTime);

            for (int i = 0; i < Configuration.ZeroList.Count() - Configuration.SMA; i++)
            {
                double R = 0;
                double N = 0;
                for (int j = 0; j < Configuration.SMA; j++)
                {
                    R += Configuration.ZeroList[i + j];
                    N += Num[i + j];
                }
                R /= Configuration.SMA;
                N /= Configuration.SMA;

                Zerosw.WriteLine(R + "," + N);
            }

            Zerosw.Close();


            StreamWriter Onesw = new StreamWriter("./One_per_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
                                                  + "AS_" + Configuration.ASName + "ET_" + Configuration.ExpThreshold + "DS_" + Configuration.DifferenceSigma + "LS_" + Configuration.LookBackSigma
                                                  + "DE_" + Configuration.DifferenceEpsilon + "LE_" + Configuration.LookBackEpsilon + ".csv", true, System.Text.Encoding.GetEncoding("shift_jis"));



            Onesw.WriteLine("Performance,dummy," + Configuration.StartTime);

            for (int i = 0; i < Configuration.OneList.Count() - Configuration.SMA; i++)
            {
                double R = 0;
                double N = 0;
                for (int j = 0; j < Configuration.SMA; j++)
                {
                    R += Configuration.OneList[i + j];
                    N += Num[i + j];
                }
                R /= Configuration.SMA;
                N /= Configuration.SMA;

                Onesw.WriteLine(R + "," + N);
            }

            Onesw.Close();

            Configuration.ESW.Close();
            //Configuration.Problem.Close();


            System.IO.Directory.SetCurrentDirectory("../");
            StreamWriter swP = new StreamWriter("PPP.csv", true, System.Text.Encoding.GetEncoding("shift_jis"));

            swP.WriteLine(Configuration.NoiseWidth + "," + Configuration.ASName + "," + P.CList.Count());
            swP.Close();
        }