コード例 #1
0
 /// <summary>
 /// ForTesting
 /// Sets the norm of column vectors in a matrix to 1
 /// </summary>
 /// <param name="matrix"></param>
 private static void NormalizeCollumnVectorsInMatrix(Matrix <double> matrix)
 {
     for (int i = 0; i < matrix.ColumnCount; i++)
     {
         Vector <double> v = matrix.Column(i);
         v.Divide(Math.Sqrt(PCATester.ScalarProduct(v, v)));
         matrix.SetColumn(i, v);
     }
 }
コード例 #2
0
        /// <summary>
        /// PCA works as intended
        /// </summary>
        public void TestPCA()
        {
            PCATester       pcatester  = new PCATester(1000);
            Matrix <double> baseMatrix = GetSymetricMatrixForEigenVectors(pcatester.Qs);
            var             evd        = baseMatrix.Evd();
            Matrix <double> output     = evd.EigenVectors;

            Console.WriteLine("Input vectors:");
            Console.WriteLine(String.Format("{0} {1} {2}", pcatester.v1[0], pcatester.v2[0], pcatester.v3[0]));
            Console.WriteLine(String.Format("{0} {1} {2}", pcatester.v1[1], pcatester.v2[1], pcatester.v3[1]));
            Console.WriteLine(String.Format("{0} {1} {2}", pcatester.v1[2], pcatester.v2[2], pcatester.v3[2]));

            Console.WriteLine("PCA output:");
            Console.WriteLine(output.ToMatrixString());
        }