Ejemplo n.º 1
0
        public void Matrix_Covariance_Test()
        {
            // from: http://www.itl.nist.gov/div898/handbook/pmc/section5/pmc541.htm

            Matrix x = new[,]
               {{ 4.0, 2.0, .60 },
                { 4.2, 2.1, .59 },
                { 3.9, 2.0, .58 },
                { 4.3, 2.1, .62 },
                { 4.1, 2.2, .63 }};

            Matrix covTruth = new[,]
               {{ 0.02500, 0.00750, 0.00175 },
                { 0.00750, 0.00700, 0.00135 },
                { 0.00175, 0.00135, 0.00043 }};

            var cov = x.Covariance().Round(5);
            Assert.Equal(covTruth, cov);
        }
Ejemplo n.º 2
0
        public void TestMatrixCovariance()
        {
            var testInput = new[,]
            {
                {90D, 60D, 90D},
                {90D, 90D, 30D},
                {60D, 60D, 60D},
                {60D, 60D, 90D},
                {30D, 30D, 30D}
            };

            var testResult = testInput.Covariance();

            Assert.AreEqual(504D, testResult[0, 0]);
            Assert.AreEqual(360D, testResult[0, 1]);
            Assert.AreEqual(180D, testResult[0, 2]);

            Assert.AreEqual(360D, testResult[1, 0]);
            Assert.AreEqual(360D, testResult[1, 1]);
            Assert.AreEqual(0, testResult[1, 2]);

            Assert.AreEqual(180D, testResult[2, 0]);
            Assert.AreEqual(0D, testResult[2, 1]);
            Assert.AreEqual(720D, testResult[2, 2]);
        }