예제 #1
0
        public void 擬似逆行列のランダムテスト()
        {
            int row  = 8;
            int col  = 4;
            var mat  = new MatrixLib.Matrix(row, col);
            var rand = new Random();

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    mat[i, j] = rand.Next(0, 20);
                }
            }

            var denseMat = new DenseMatrix(row, col);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    denseMat[i, j] = mat[i, j];
                }
            }

            Console.WriteLine(denseMat.PseudoInverse());
            Console.WriteLine(mat.PseudoInverse());
            var pseInv      = mat.PseudoInverse();
            var densePseInv = denseMat.PseudoInverse();

            for (int i = 0; i < pseInv.RowCount; i++)
            {
                for (int j = 0; j < pseInv.ColCount; j++)
                {
                    Assert.IsTrue(Math.Abs(pseInv[i, j] - densePseInv[i, j]) < 0.001);
                }
            }
        }