예제 #1
0
 public void ToArray1D()
 {
     Matrix33F m = new Matrix33F(1, 2, 3, 4, 5, 6, 7, 8, 9);
       float[] array = m.ToArray1D(MatrixOrder.RowMajor);
       for (int i = 0; i < 9; i++)
     Assert.AreEqual(rowMajor[i], array[i]);
       array = m.ToArray1D(MatrixOrder.ColumnMajor);
       for (int i = 0; i < 9; i++)
     Assert.AreEqual(columnMajor[i], array[i]);
 }
예제 #2
0
        public void ComputeCovarianceMatrix3F()
        {
            // Make a random list.
            List <Vector3F> points3F = new List <Vector3F>(new[]
            {
                new Vector3F(-1, -2, 1),
                new Vector3F(1, 0, 2),
                new Vector3F(2, -1, 3),
                new Vector3F(2, -1, 2),
            });

            Matrix33F cov3F = StatisticsHelper.ComputeCovarianceMatrix(points3F);

            Assert.AreEqual(3f / 2, cov3F[0, 0]);
            Assert.AreEqual(1f / 2, cov3F[0, 1]);
            Assert.AreEqual(3f / 4, cov3F[0, 2]);
            Assert.AreEqual(1f / 2, cov3F[1, 0]);
            Assert.AreEqual(1f / 2, cov3F[1, 1]);
            Assert.AreEqual(1f / 4, cov3F[1, 2]);
            Assert.AreEqual(3f / 4, cov3F[2, 0]);
            Assert.AreEqual(1f / 4, cov3F[2, 1]);
            Assert.AreEqual(1f / 2, cov3F[2, 2]);

            // Compare with Vector3D version.
            List <Vector3D> points3D = new List <Vector3D>();

            foreach (var point in points3F)
            {
                points3D.Add(point.ToVector3D());
            }
            Matrix33D cov3D = StatisticsHelper.ComputeCovarianceMatrix(points3D);

            for (int i = 0; i < cov3F.ToArray1D(MatrixOrder.RowMajor).Length; i++)
            {
                var item3F = cov3F.ToArray1D(MatrixOrder.RowMajor)[i];
                var item3D = cov3D.ToArray1D(MatrixOrder.RowMajor)[i];
                Assert.AreEqual(item3F, item3D);
            }

            // Compare with VectorF version.
            List <VectorF> pointsF = new List <VectorF>();

            foreach (var point in points3F)
            {
                pointsF.Add(point.ToVectorF());
            }
            MatrixF covF = StatisticsHelper.ComputeCovarianceMatrix(pointsF);

            for (int i = 0; i < cov3F.ToArray1D(MatrixOrder.RowMajor).Length; i++)
            {
                var item3F = cov3F.ToArray1D(MatrixOrder.RowMajor)[i];
                var itemF  = covF.ToArray1D(MatrixOrder.RowMajor)[i];
                Assert.AreEqual(item3F, itemF);
            }

            // Compare with VectorF version.
            List <VectorD> pointsD = new List <VectorD>();

            foreach (var point in points3D)
            {
                pointsD.Add(point.ToVectorD());
            }
            MatrixD covD = StatisticsHelper.ComputeCovarianceMatrix(pointsD);

            for (int i = 0; i < cov3F.ToArray1D(MatrixOrder.RowMajor).Length; i++)
            {
                var item3F = cov3F.ToArray1D(MatrixOrder.RowMajor)[i];
                var itemD  = covD.ToArray1D(MatrixOrder.RowMajor)[i];
                Assert.AreEqual(item3F, itemD);
            }
        }