public void Demo_003_Design_Matrix_calculation()
        {
            Console.WriteLine("今回は、計画行列の計算を紹介します");

            Console.WriteLine("\nまず、計算に使用する計画行列を表示します");

            Uniform_Distribution ud = new Uniform_Distribution(1);

            Console.WriteLine("\n計画行列X");
            double[,] matrix_A = new double[6, 2];
            for (int j = 0; j < matrix_A.GetLength(0); j++)
            {
                for (int k = 0; k < matrix_A.GetLength(1); k++)
                {
                    matrix_A[j, k] = Math.Round(100.0 * (2 * j + 3.0 * k + 1 + ud.NextDouble(2, -2))) / 100.0;
                }
            }
            this.Show_Matrix_Element(matrix_A);
            Console.ReadKey();

            Console.WriteLine("\n計画行列Xの平均ベクトルμ^T");
            double[,] result = Design_Matrix.Average(matrix_A);
            this.Show_Matrix_Element(result);
            Console.ReadKey();

            Console.WriteLine("\n計画行列Xの第3行の行ベクトルを得る");
            result = Design_Matrix.Pick_Up_Row_Vector(matrix_A, 3);
            this.Show_Matrix_Element(result);
            Console.ReadKey();

            Console.WriteLine("\n計画行列Xの各行ベクトルのL2ノルムを得る");
            result = Design_Matrix.Norm_L2_Array(matrix_A);
            this.Show_Matrix_Element(result);
            //Console.ReadKey();

            Console.WriteLine("\n計画行列Xの行ベクトルの中で、L2ノルムの最大値を得る");
            double scalar = Design_Matrix.Maximum_Norm_L2(matrix_A);

            Console.WriteLine(scalar);

            Console.WriteLine("\n計画行列Xの行ベクトルの中で、L2ノルム最大の行番号を得る");
            int integer = Design_Matrix.Maximum_Norm_L2_Index(matrix_A);

            Console.WriteLine(integer);
            //Console.ReadKey();

            Console.WriteLine("\n計画行列Xの行ベクトルの中で、L2ノルムの最小値値を得る");
            scalar = Design_Matrix.Minimum_Norm_L2(matrix_A);
            Console.WriteLine(scalar);

            Console.WriteLine("\n計画行列Xの行ベクトルの中で、L2ノルム最小の行番号を得る");
            integer = Design_Matrix.Minimum_Norm_L2_Index(matrix_A);
            Console.WriteLine(integer);
            Console.ReadKey();


            Console.WriteLine("\n計画行列Xの標準偏差");
            result = Design_Matrix.Standard_Deviation(matrix_A);
            this.Show_Matrix_Element(result);

            Console.WriteLine("\n計画行列Xの分散・共分散行列");
            result = Design_Matrix.Variance_Covariance_Matrix(matrix_A);
            this.Show_Matrix_Element(result);

            Console.WriteLine("\n計画行列Xの分散・共分散行列の逆行列");
            result = Design_Matrix.Inverse_Variance_Covariance_Matrix(matrix_A);
            this.Show_Matrix_Element(result);

            Console.WriteLine("\n計画行列Xの分散・共分散行列と、逆行列の積が単位行列になることを確認する。");
            result = Matrix.Multiplication(Design_Matrix.Variance_Covariance_Matrix(matrix_A), Design_Matrix.Inverse_Variance_Covariance_Matrix(matrix_A));
            this.Show_Matrix_Element(result);
            Console.ReadKey();


            Console.WriteLine("\n計画行列Xの相関係数の行列を得る");
            result = Design_Matrix.Corelation_Matrix(matrix_A);
            this.Show_Matrix_Element(result);
            Console.ReadKey();



            double[,] result2 = new double[1, 2];
            Console.WriteLine("\n計画行列Xを3分割して、第0グループをテストデータにする。残りは訓練データにする");
            Design_Matrix.Prepare_k_fold_cross_validation(matrix_A, 3, 0, ref result, ref result2);
            Console.WriteLine("\nテストデータ");
            this.Show_Matrix_Element(result);
            Console.WriteLine("\n訓練データ");
            this.Show_Matrix_Element(result2);
            Console.ReadKey();

            Console.WriteLine("\n計画行列Xを6分割して、第1行をテストデータにする。残りは訓練データにする");
            Design_Matrix.Prepare_Leave_one_out_cross_validation(matrix_A, 1, ref result, ref result2);
            Console.WriteLine("\nテストデータ");
            this.Show_Matrix_Element(result);
            Console.WriteLine("\n訓練データ");
            this.Show_Matrix_Element(result2);
            Console.ReadKey();
        }
Example #2
0
        public void Demo_004_Random_Number_Calculation()
        {
            Console.WriteLine("今回は、乱数の計算を紹介します");
            Console.WriteLine("幹葉表示風のヒストグラムで、分布を確認します。");


            //頻度
            string count = "\t";

            for (int j = 0; j < 15; j++)
            {
                count += "        " + (j + 1) * 10;
            }



            Console.WriteLine("\n一様乱数を最大値299 , 最小値0で計算します。");
            Uniform_Distribution ud = new Uniform_Distribution(1);

            string[] histgram = new string[30];
            for (int j = 0; j < histgram.Length; j++)
            {
                histgram[j] = j * 10 + "\t" + "|";
            }

            int integer = 0;

            for (int j = 0; j < 2500; j++)
            {
                integer = (int)(Math.Round(ud.NextDouble(299, 0)));
                histgram[integer / 10] += integer % 10;
            }
            Console.WriteLine(count);
            foreach (string s in histgram)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();


            Console.WriteLine("\nPolar法で生成した正規分布乱数を平均値150 , 標準偏差50で計算します。");
            Normal_Distribution_Polar ndp = new Normal_Distribution_Polar(1, 2);

            histgram = new string[30];
            for (int j = 0; j < histgram.Length; j++)
            {
                histgram[j] = j * 10 + "\t" + "|";
            }
            for (int j = 0; j < 1000; j++)
            {
                integer = (int)(Math.Round(ndp.NextDouble(150, 50)));
                if (integer < 0 || histgram.Length * 10 - 1 < integer)
                {
                    continue;
                }
                else
                {
                    histgram[integer / 10] += integer % 10;
                }
            }
            Console.WriteLine(count);
            foreach (string s in histgram)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();


            Console.WriteLine("\nPolar法で生成した半正規分布乱数を標準偏差50で計算します。");
            Half_Normal_Distribution_Polar hndp = new Half_Normal_Distribution_Polar(1, 2);

            histgram = new string[30];
            for (int j = 0; j < histgram.Length; j++)
            {
                histgram[j] = j * 10 + "\t" + "|";
            }
            for (int j = 0; j < 500; j++)
            {
                integer = (int)(Math.Round(hndp.NextDouble(50)));
                if (integer < 0 || histgram.Length * 10 - 1 < integer)
                {
                    continue;
                }
                else
                {
                    histgram[integer / 10] += integer % 10;
                }
            }
            Console.WriteLine(count);
            foreach (string s in histgram)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();


            Console.WriteLine("\nPolar法で生成した対数正規分布乱数を、正規分布の平均値150 , 標準偏差50で計算します。");
            Log_Normal_Distribution_Polar lndp = new Log_Normal_Distribution_Polar(1, 2);

            histgram = new string[30];
            for (int j = 0; j < histgram.Length; j++)
            {
                histgram[j] = j * 10 + "\t" + "|";
            }
            for (int j = 0; j < 1000 * 100; j++)
            {
                integer = (int)(Math.Round(lndp.NextDouble(150, 50)));
                if (integer < 0 || histgram.Length * 10 - 1 < integer)
                {
                    continue;
                }
                else
                {
                    histgram[integer / 10] += integer % 10;
                }
            }
            Console.WriteLine(count);
            foreach (string s in histgram)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();


            Console.WriteLine("\nPolar法で生成した対数正規分布乱数を位置母数150 , 尺度母数50で計算します。");
            Cauchy_distribution_Porlar cdp = new Cauchy_distribution_Porlar(1, 2);

            histgram = new string[30];
            for (int j = 0; j < histgram.Length; j++)
            {
                histgram[j] = j * 10 + "\t" + "|";
            }
            for (int j = 0; j < 1000; j++)
            {
                integer = (int)(Math.Round(cdp.NextDouble(150, 50)));
                if (integer < 0 || histgram.Length * 10 - 1 < integer)
                {
                    continue;
                }
                else
                {
                    histgram[integer / 10] += integer % 10;
                }
            }
            Console.WriteLine(count);
            foreach (string s in histgram)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();
        }