コード例 #1
0
ファイル: MatrixMxNTest.cs プロジェクト: belzecue/Common
        public void Inverse3x3()
        {
            double[,] matrix = new double[, ]
            {
                { 1, 5, 3 },
                { 1, 3, 2 },
                { 2, 4, -6 }
            };

            double[,] inverted = MatrixMxN.Inverse(matrix);

            double[,] expected = new double[, ]
            {
                { -1.44444, 2.33333, 0.05556 },
                { 0.55556, -0.66667, 0.05556 },
                { -0.11111, 0.33333, -0.11111 }
            };

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.AreEqual(expected[i, j], Math.Round(inverted[i, j], 5));
                }
            }
        }
コード例 #2
0
        public ContinuousDistributionN(double[] mean, double[,] covariance)
        {
            Dimension  = mean.Length;
            Mean       = mean;
            Covariance = covariance;

            Inverse     = MatrixMxN.Inverse(covariance);
            Determinant = MatrixMxN.Determinant(covariance);
        }
コード例 #3
0
ファイル: Statistics.cs プロジェクト: belzecue/Common
        public static double[,] CovarianceToCorrelation(double[,] covariance)
        {
            int dimensions = covariance.GetLength(0);

            double[,] correlation = new double[dimensions, dimensions];

            for (int j = 0; j < dimensions; j++)
            {
                for (int i = 0; i < dimensions; i++)
                {
                    if (i != j)
                    {
                        continue;
                    }
                    correlation[i, j] = Math.Sqrt(covariance[i, j]);
                }
            }

            double[,] inverse = MatrixMxN.Inverse(correlation);

            return(MatrixMxN.MultiplyMatrix(MatrixMxN.MultiplyMatrix(inverse, covariance), inverse));
        }
コード例 #4
0
ファイル: MatrixMxNTest.cs プロジェクト: belzecue/Common
        public void Inverse2x2()
        {
            double[,] matrix = new double[, ]
            {
                { 1, 2 },
                { 3, 4 }
            };

            double[,] inverted = MatrixMxN.Inverse(matrix);

            double[,] expected = new double[, ]
            {
                { -2, 1 },
                { 1.5, -0.5 }
            };

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Assert.AreEqual(expected[i, j], Math.Round(inverted[i, j], 5));
                }
            }
        }