예제 #1
0
        /// <summary>
        /// Returns a sorted list of EigenObjects sorted by their corresponding comparator implemention (eigenvalue in our case)
        /// </summary>
        /// <param name="Decomposition">Decomposition after solving the GEVP</param>
        /// <returns></returns>
        private List <EigenObject> GetSortedEigenObjects(IEigenvalueDecomposition Decomposition)
        {
            List <EigenObject> Res          = new List <EigenObject>();
            IMatrix            Eigenvectors = Decomposition.EigenvectorMatrix;

            for (int j = 0; j < Eigenvectors.Columns; j++)
            {
                EigenObject Eigen       = new EigenObject();
                double[]    eigenvector = new double[Eigenvectors.Rows];
                double      magnitude   = 0.0;
                double      eigenvalue  = Decomposition.RealEigenvalues[j];
                for (int i = 0; i < Eigenvectors.Rows; i++)
                {
                    eigenvector[i] = Eigenvectors[i, j];
                    magnitude     += Eigenvectors[i, j] * Eigenvectors[i, j];
                }
                magnitude         = Math.Sqrt(magnitude);
                Eigen.Magnitude   = magnitude;
                Eigen.Eigenvalue  = eigenvalue;
                Eigen.Eigenvector = eigenvector;
                Res.Add(Eigen);
            }
            Res.Sort();
            return(Res);
        }
예제 #2
0
 public int CompareTo(EigenObject Other)
 {
     if (Eigenvalue < Other.Eigenvalue)
     {
         return(1);
     }
     else if (this.Eigenvalue == Other.Eigenvalue)
     {
         return(0);
     }
     return(-1);
 }
예제 #3
0
        public int CompareTo(Object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            EigenObject Other = obj as EigenObject;

            if (Other != null)
            {
                return(CompareTo(Other));
            }
            else
            {
                throw new ArgumentException("Object is not an EigenFace");
            }
        }
예제 #4
0
        /// <summary>
        /// After solving the GEVP and having sorted the eigen values, we retrieve C-1 eigenvectors
        /// </summary>
        /// <param name="Eigens"> List of EigenObjects</param>
        /// <param name="numVectors">Number of vector.</param>
        /// <returns></returns>
        private IMatrix GetLDABase(List <EigenObject> Eigens, int numVectors)
        {
            if (numVectors > (C - 1))
            {
                throw new ArgumentException("LDA Produces at MOST C-1 eigenvectors.");
            }
            if (Eigens == null || Eigens.Count < 1)
            {
                throw new ArgumentException("EigenObject list cannot be empty nor null!");
            }
            IMatrix Res = new Matrix(Eigens[0].Eigenvector.Length, numVectors);

            for (int j = 0; j < numVectors; j++)
            {
                EigenObject Eg = Eigens[j];
                for (int i = 0; i < Eg.Eigenvector.Length; i++)
                {
                    Res[i, j] = Eg.Eigenvector[i] / Eg.Magnitude;
                }
                Console.WriteLine(j + " : " + Eg.Eigenvalue);
            }
            return(Res);
        }