Exemplo n.º 1
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>();

            // 提案手法 Condition毎の分散
            Configuration.Stdlist = new StdList[( int )Math.Pow( 2, Configuration.L ) * 2];
            for( int i = 0; i < ( int )Math.Pow( 2, Configuration.L ); i++ )
            {
                Configuration.Stdlist[i * 2] = new StdList( i, '0' );
                Configuration.Stdlist[i * 2 + 1] = new StdList( i, '1' );
            }

            //StreamWriter LD = new StreamWriter( "./LearningData_" + 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" ) );
            //LD.WriteLine( "T,state,Action,Rho,ActionExploit" );

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

            // メインループ
            #region main roop
            while ( Configuration.T < Configuration.Iteration )
            {

                if (Configuration.T == 40269) {
                    Console.WriteLine("stoped");
                    Console.ReadLine(); }
                //Console.WriteLine( Configuration.T + " : " + P.CountNumerosity() + " : " + P.CList.Count() );
                // situation取得
                State S = Env.GetState();
                // MatchSet生成
                MatchSet M = new NormalMatchSet( S, P );
                // PredictionArray取得
                PredictionArray PA = new EpsilonGreedyPredictionArray( M );
                // Action決定
                char Action = PA.SelectAction();

                // ActionSet選択
                ActionSet AS;
                if( Configuration.ASName == "CS" )
                {
                    AS = new ConditionSigmaActionSet( M.MatchAction( Action ) );
                }
                //else if( Configuration.ASName == "MaxCS" || Configuration.ASName == "Max" )
                //{
                //    AS = new MaxConditionSigmaActionSet( M.MatchAction( Action ) );
                //}
                else if( Configuration.ASName == "WellKnown" )	// 実験1a
                {
                    AS = new NormalActionSet( M.MatchAction( Action ) );
                }
                else if( Configuration.ASName == "Updatee0CS" )	// 実験1b
                {
                    AS = new UpdateEpsilon_0_ConditionSigmaActionSet( M.MatchAction( Action ) );
                }
                else if(Configuration.ASName == "Tornament")
                {
                    AS = new TornamentSelectionActionSet( M.MatchAction( Action ) );
                }
                else
                {
                    AS = new NormalActionSet( M.MatchAction( Action ) );
                }
                // EnvにActionし、報酬獲得

                     double Rho = Env.ExecuteAction(Action);

                //if ( == "1#00##" )
                //{
                //    Configuration.Problem.WriteLine(S.state + "," + Action + "," + Configuration.T + "," + Rho);
                //}

                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;
                }

                //if (Configuration.T > 18936&&Configuration.T<18938)
                //{
                //    foreach (Classifier C in AS.CList)
                //    {
                //        if (C.C.state == "1#00##" )
                //        {
                //            Console.WriteLine(Configuration.T + " : " + S.state + " : " + Action + " : " + Rho + " : " + C.Exp);

                //        }
                //    }
                //}

                // 学習データ記録
                //LD.WriteLine( Configuration.T + "," + S.state + "," + Action + "," + Rho + "," + Env.ActionExploit( Action ) );

                // マルチステップ問題
                if( PreviousAS != null )
                {
                    double p = PreviousRho + Configuration.Gamma * PA.MAX();
                    PreviousAS.Update( P, p, Sigma );
                    PreviousAS.RunGA( PreviousS, P );	//komine
                }
                // マルチステップ問題の終着またはシングルステップ問題
                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;
                }

                //if(Configuration.ASName == "CS")
                //{
                //	SigmaNormalPopulation SP = ( SigmaNormalPopulation )P;
                //	SP.RoundRobin();
                //}

                // accuracyが一定以上のfitnessの平均値
                //double SumFitness = 0;
                //int NumberOfClassifiers = 0;
                //foreach( Classifier C in P.CList )
                //{
                //	//SumFitness += C.F;
                //	//NumberOfClassifiers++;
                //	if( C.C.state == "11####" && C.A == '0' )
                //		Configuration.ESW.WriteLine( Configuration.T + "," + C.Epsilon );
                //}
                foreach(StdList C  in Configuration.Stdlist)
                {
                    //if( C.C == "111111" && C.A == '0' )
                        //Configuration.ESW.WriteLine( Configuration.T + "," + C.S );
                }
                //Configuration.ESW.WriteLine( Configuration.T + "," + SumFitness + "," + NumberOfClassifiers + "," + SumFitness / NumberOfClassifiers);

                RhoArray[Configuration.T] = Exploit( P );
                //Num[Configuration.T] = P.CountNumerosity();
                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( ( Configuration.T < 20001 && Configuration.T % 1000 == 0 ) || Configuration.T % 5000 == 0 )
                //{
                //	P.Show();
                //}

                //if( Configuration.T % 1000 == 0 && Configuration.T < 20001 && ( 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" );
                //	foreach( StdList SL in Configuration.Stdlist )
                //	{
                //		stdSw.WriteLine( SL.C + "," + SL.A + "," + SL.S + "," + SL.T + "," + ( SL.IsConvergenceSigma() ? 1 : 0 ) );	// 1 : 収束
                //	}
                //	stdSw.Close();
                //}

                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,time,convergence" );
                        foreach( StdList SL in Configuration.Stdlist )
                        {
                            stdSw.WriteLine( SL.C + "," + SL.A + "," + SL.S + "," + SL.T + "," + ( SL.IsConvergenceSigma() ? 1 : 0 ) );	// 1 : 収束
                        }
                        stdSw.Close();
                        ConvergenceStelist = true;
                    }
                }
                //if (Configuration.T > 14896& Configuration.T <14899)
                //{
                //    P.Show();
                //    M.Show();
                //    AS.Show();//9-7 chou ループたびのpopulation 見たい
                //}

                foreach (Classifier C in P.CList)
                {
                    if (C.GetType().Name == "SigmaNormalClassifier")
                    {
                        if (C.C.state == "1000##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem_1000.WriteLine(Configuration.T + "," + SNC.C.state + ","+SNC.A+"," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));

                        }

                        if (C.C.state == "0100##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem_0100.WriteLine(Configuration.T + "," + SNC.C.state  + ","+SNC.A +"," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));

                        }

                        if (C.C.state == "0010##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem_0010.WriteLine(Configuration.T + "," + SNC.C.state + "," + SNC.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));

                        }

                        if (C.C.state == "0001##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem_0001.WriteLine(Configuration.T + "," + SNC.C.state + "," + SNC.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));

                        }
                        if (C.C.state == "1#00##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem__100.WriteLine(Configuration.T + "," + SNC.C.state + "," + C.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));

                        }
                        if (C.C.state == "#100##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem__100.WriteLine(Configuration.T + "," + SNC.C.state + "," + C.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));
                        }

                        if (C.C.state == "001###")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem__100.WriteLine(Configuration.T + "," + SNC.C.state + "," + C.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));
                        }

                        if (C.C.state == "00#1##")
                        {
                            SigmaNormalClassifier SNC = (SigmaNormalClassifier)C;

                            Configuration.Problem__100.WriteLine(Configuration.T + "," + SNC.C.state + "," + C.A + "," + C.F + "," + C.Kappa + ","
                                + C.Epsilon + "," + C.Epsilon_0 + "," + C.N + "," + (SNC.IsConvergenceEpsilon() ? 1 : 0));
                        }
                    }
                }
                //if (Configuration.T > 19835 && Configuration.T < 19840)
                //{
                //    P.Show();
                //}
                //if (Configuration.T > 7200 && Configuration.T < 7300)
                //{
                //    P.Show();
                //}
                //if (Configuration.T > 7700 && Configuration.T < 7850)
                //{
                //    P.Show();
                //}
                //if (Configuration.T > 8400 && Configuration.T < 8600)
                //{
                //    P.Show();
                //}
                //if (Configuration.T >11400 && Configuration.T < 11500)
                //{
                //    P.Show();
                //}
                //if (Configuration.T > 14200 && Configuration.T < 14300)
                //{
                //    P.Show();
                //}
                Configuration.T++;

                //if (Configuration.T > 19996)
                //{
                //    Console.Read();
                //}
            }
            #endregion

            Configuration.Problem_1_00.Close();
            Configuration.Problem__100.Close();
            Configuration.Problem_1000.Close();
            Configuration.Problem_0100.Close();
            Configuration.Problem_0010.Close();
            Configuration.Problem_0001.Close();
            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" ) );

            //StreamWriter sw = new StreamWriter( "./performance_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
            //	+ "AS_" + "CS" + "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" ) );

            //StreamWriter sw = new StreamWriter( "./performance_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
            //	+ "AS_" + "CS" + "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" ) );

            //StreamWriter sw = new StreamWriter( "./performance_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth
            //	+ "AS_" + "CS" + "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();

            foreach( StdList SL in Configuration.Stdlist )
            {
                //Console.WriteLine( SL.C + " " + SL.A + " " + SL.T + " " + SL.M + " " + SL.S );
            }

            //StreamWriter sow = new StreamWriter( "./sigma_" + Configuration.Seed + "CnoiseWidth_" + Configuration.NoiseWidth + "e0_" + Configuration.Epsilon_0 + ".csv", true, System.Text.Encoding.GetEncoding( "shift_jis" ) );

            //foreach( double d in Std )
            //{
            //	sow.WriteLine( d );
            //}
            //sow.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();
        }
Exemplo n.º 2
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();
        }