Пример #1
0
        public void TestOrthogonalization()
        {
            List<IVector> Acols = MatrixUtils.GetColumnVectors(A);
            List<IVector> vstarlist = Orthogonalization.Orthogonalize(Acols);
            for (int i = 0; i < vstarlist.Count-1; ++i)
            {
                for (int j = i + 1; j < vstarlist.Count; ++j)
                {
                    Assert.True(vstarlist[i].Multiply(vstarlist[j]) < 1e-10);
                }
            }

        }
Пример #2
0
        public void TestOrthoNormal()
        {
            List<IVector> Rcols;
            List<IVector> Acols = MatrixUtils.GetColumnVectors(A);
            List<IVector> vstarlist = Orthogonalization.Orthogonalize(Acols, out Rcols);

            for (int i = 0; i < Rcols.Count; ++i)
            {
                int count = 0;
                for (int j = 0; j < Rcols[i].Dimension; ++j)
                {
                    count += (System.Math.Abs(Rcols[i][j]) > 1e-10) ? 1 : 0;
                }

                Assert.Equal(i + 1, count);
            }

            for (int i = 0; i < Acols.Count; ++i)
            {
                IVector pi = new SparseVector(Acols[i].Dimension);
                for (int j = 0; j < vstarlist.Count; ++j)
                {
                    pi = pi.Add(vstarlist[j].Multiply(Rcols[i][j]));
                }
                
                for (int d = 0; d < Acols[i].Dimension; ++d)
                {
                    Assert.Equal(Acols[i][d], pi[d]);
                }
                Assert.True(Acols[i].Equals(pi));
            }

            List<double> norms;
            List<IVector> qlist = VectorUtils.Normalize(vstarlist, out norms);

            for (int i = 0; i < qlist.Count - 1; ++i)
            {
                for (int j = i + 1; j < vstarlist.Count; ++j)
                {
                    Assert.True(qlist[i].Multiply(qlist[j]) < 1e-10);
                }
                Assert.True(qlist[i].Norm(2) - 1 < 1e-10);
            }

            for (int i = 0; i < vstarlist.Count; ++i)
            {
                Assert.Equal(norms[i], vstarlist[i].Norm(2));
            }

            IMatrix R = MatrixUtils.GetMatrix(Rcols);
            foreach (int r in R.RowKeys)
            {
                R[r] = R[r].Multiply(norms[r]);
            }

            for (int i = 0; i < A.RowCount; ++i)
            {
                for (int j = 0; j < A.ColCount; ++j)
                {
                    Assert.Equal(R[i][j], Rcols[j][i] * norms[i]);
                }
            }
        }