public void TestInverseVarianceCovarianceMatrix()
        {
            Console.WriteLine("計画行列の分散・共分行列を返すメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = -1;
            A[0, 1]     = 8;

            A[1, 0] = 0;
            A[1, 1] = 4;

            A[2, 0] = 1;
            A[2, 1] = -4;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[,] B = DesignMatrix.VarianceCovariance(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の分散・共分散行列" + nameof(B));


            double[,] C = DesignMatrix.InverseVarianceCovarianceMatrix(A);
            TestMatrix.WriteLineMatrix(C, nameof(A) + "の分散・共分散行列の逆行列" + nameof(C));


            double[,] D = Matrix.Multiply(B, C);
            TestMatrix.WriteLineMatrix(D, nameof(B) + nameof(C));
        }
コード例 #2
0
        public void TestSign()
        {
            Console.WriteLine("行列の各要素の符号を±1で表すメソッドのテストです。(ただし0.0は0を返す)");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = -2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.Sign(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の各要素の符号を±1で表した行列" + nameof(B));
        }
コード例 #3
0
        public void TestLInfinityNorm()
        {
            Console.WriteLine("L∞の計算を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double d = Matrix.LInfinityNorm(A);

            Console.WriteLine(nameof(A) + "のL∞ノルムは" + d);
        }
        public void TestClone()
        {
            Console.WriteLine("行列をコピーするメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.Clone(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の各要素をコピーした行列" + nameof(B));
        }
        public void TestReciprocalNumber()
        {
            Console.WriteLine("行列の各要素の逆数を返すメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.ReciprocalNumber(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の各要素を逆数に変換した行列" + nameof(B));
        }
コード例 #6
0
        public void TestInverse()
        {
            Console.WriteLine("逆行列の計算を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 2;
            A[0, 1]     = 0;
            A[1, 0]     = 0;
            A[1, 1]     = 2;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.Inverse(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の逆行列");
        }
        public void TestNaturalLogarithm()
        {
            Console.WriteLine("行列の各要素の自然対数を計算するメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 1;
            A[0, 1]     = Math.E;
            A[1, 0]     = Math.E * Math.E;
            A[1, 1]     = 4;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.NaturalLogarithm(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の各要素の自然対数に変換した行列" + nameof(B));
        }
        public void TestTranspose()
        {
            Console.WriteLine("行列の転置行列を返すメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.Transpose(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "のの転置行列" + nameof(B));
        }
        public void TestTrace()
        {
            Console.WriteLine("正方行列の跡を計算するメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 1;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double d = Matrix.Trace(A);

            Console.WriteLine(nameof(A) + "の跡は" + d);
        }
コード例 #10
0
        public void TestSum()
        {
            Console.WriteLine("行列の各要素の和を返すメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double d = Matrix.Sum(A);

            Console.WriteLine(nameof(A) + "の行列の各要素の和は" + d);
        }
コード例 #11
0
        public void TestRowVector()
        {
            Console.WriteLine("行列から行ベクトルを取り出すメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] b = Matrix.RowVector(A, 1);
            TestMatrix.WriteLineMatrix(b, nameof(A) + "の第1行を取り出した列ベクトル" + nameof(b));
        }
        public void TestL2Norm()
        {
            Console.WriteLine("計画行列のL2ノルムに関するメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 2;
            A[1, 0]     = 1;
            A[1, 1]     = 4;
            A[2, 0]     = 2;
            A[2, 1]     = 6;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[] B = DesignMatrix.L2Norms(A);
            Console.WriteLine("計画行列" + nameof(A) + "の各行ベクトルのL2ノルムを返す");
            foreach (double d in B)
            {
                Console.WriteLine(d);
            }
            Console.WriteLine("");


            double bmax = DesignMatrix.L2NormMaximum(A);

            Console.WriteLine("計画行列" + nameof(A) + "の各行ベクトルのL2ノルムの最大値");
            Console.WriteLine(bmax);
            Console.WriteLine("");

            int bmaxInt = DesignMatrix.L2NormMaximumIndex(A);

            Console.WriteLine("計画行列" + nameof(A) + "の各行ベクトルのL2ノルムの最大値の要素番号");
            Console.WriteLine(bmaxInt);
            Console.WriteLine("");


            double bmin = DesignMatrix.L2NormMinimum(A);

            Console.WriteLine("計画行列" + nameof(A) + "の各行ベクトルのL2ノルムの最小値");
            Console.WriteLine(bmin);
            Console.WriteLine("");

            int bminInt = DesignMatrix.L2NormMinimumIndex(A);

            Console.WriteLine("計画行列" + nameof(A) + "の各行ベクトルのL2ノルムの最小値の要素番号");
            Console.WriteLine(bminInt);
            Console.WriteLine("");
        }
コード例 #13
0
        public void TestDeterminant()
        {
            Console.WriteLine("行列式の計算を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 2;
            A[0, 1]     = 0;
            A[1, 0]     = 0;
            A[1, 1]     = 2;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double determinant = Matrix.Determinant(A);

            Console.WriteLine(nameof(A) + "の行列式 " + determinant);
        }
コード例 #14
0
        public void TestMultiplyByScalar()
        {
            Console.WriteLine("行列のスカラー積を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double b = 10;

            double[,] C = Matrix.MultiplyByScalar(A, b);

            TestMatrix.WriteLineMatrix(C, nameof(b) + nameof(A));
        }
        public void TestAverage()
        {
            Console.WriteLine("計画行列の平均ベクトル(行ベクトル)を返すメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 2;
            A[1, 0]     = 1;
            A[1, 1]     = 4;
            A[2, 0]     = 2;
            A[2, 1]     = 6;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[,] B = DesignMatrix.Average(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の平均ベクトル" + nameof(B));
        }
        public void TestVarianceCovariance()
        {
            Console.WriteLine("計画行列の分散・共分行列を返すメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = -1;
            A[0, 1]     = 8;

            A[1, 0] = 0;
            A[1, 1] = 4;

            A[2, 0] = 1;
            A[2, 1] = -4;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[,] B = DesignMatrix.VarianceCovariance(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の分散・共分散行列" + nameof(B));
        }
コード例 #17
0
        public void TestZeroMatrix()
        {
            Console.WriteLine("零行列を作成するメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.ZeroMatrix(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "と同じ行列数の零行列" + nameof(B));


            double[,] C = Matrix.ZeroMatrix(3, 5);
            TestMatrix.WriteLineMatrix(C, "3行5列の零行列" + nameof(C));
        }
        public void TestCorelation()
        {
            Console.WriteLine("計画行列の相関係数行列を返すメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = -1;
            A[0, 1]     = 8;

            A[1, 0] = 0;
            A[1, 1] = 4;

            A[2, 0] = 1;
            A[2, 1] = -4;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[,] B = DesignMatrix.Corelation(A);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の相関係数行列" + nameof(B));
        }
        public void TestRowVector()
        {
            Console.WriteLine("計画行列から行ベクトルを返すメソッドのテストです。");

            double[,] A = new double[3, 2];
            A[0, 0]     = -1;
            A[0, 1]     = 8;

            A[1, 0] = 0;
            A[1, 1] = 4;

            A[2, 0] = 1;
            A[2, 1] = -4;
            TestMatrix.WriteLineMatrix(A, "計画行列" + nameof(A));


            double[,] B = DesignMatrix.RowVector(A, 2);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の要素番号2の行ベクトル" + nameof(B));
        }
コード例 #20
0
        public void TestSubMatrix()
        {
            Console.WriteLine("行列をコピーするメソッドのテストです。");

            double[,] A = new double[3, 3];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[0, 2]     = 2;
            A[1, 0]     = 3;
            A[1, 1]     = 4;
            A[1, 2]     = 5;
            A[2, 0]     = 6;
            A[2, 1]     = 7;
            A[2, 2]     = 8;
            TestMatrix.WriteLineMatrix(A, nameof(A));


            double[,] B = Matrix.SubMatrix(A, 1, 2, 2, 1);
            TestMatrix.WriteLineMatrix(B, nameof(A) + "の(1,2)成分を起点に、2行1列を取り出した行列" + nameof(B));
        }
コード例 #21
0
        public void TestHadamardMultiply()
        {
            Console.WriteLine("アダマール積を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double[,] B = new double[2, 2];
            B[0, 0]     = 1;
            B[0, 1]     = 2;
            B[1, 0]     = 3;
            B[1, 1]     = 4;
            TestMatrix.WriteLineMatrix(B, nameof(B));


            double[,] C = Matrix.HadamardMultiply(A, B);
            TestMatrix.WriteLineMatrix(C, nameof(A) + " ◦ " + nameof(B));
        }
コード例 #22
0
        public void TestAdd()
        {
            Console.WriteLine("行列の加算を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double[,] B = new double[2, 2];
            B[0, 0]     = 1;
            B[0, 1]     = 2;
            B[1, 0]     = 3;
            B[1, 1]     = 4;
            TestMatrix.WriteLineMatrix(B, nameof(B));


            double[,] C = Matrix.Add(A, B);
            TestMatrix.WriteLineMatrix(C, nameof(A) + " + " + nameof(B));
        }
コード例 #23
0
        public void TestHadamardDivide()
        {
            Console.WriteLine("アダマール積風の除算を行うメソッドのテストです。");

            double[,] A = new double[2, 2];
            A[0, 0]     = 0;
            A[0, 1]     = 1;
            A[1, 0]     = 2;
            A[1, 1]     = 3;
            TestMatrix.WriteLineMatrix(A, nameof(A));

            double[,] B = new double[2, 2];
            B[0, 0]     = 1;
            B[0, 1]     = 2;
            B[1, 0]     = 3;
            B[1, 1]     = 4;
            TestMatrix.WriteLineMatrix(B, nameof(B));


            double[,] C = Matrix.HadamardDivide(A, B);
            TestMatrix.WriteLineMatrix(C, nameof(A) + "の各要素を" + nameof(B) + "の各要素で割った行列");
        }