Esempio n. 1
0
 def compute(self, X, y):
     # turn into numpy representation
     Xc = asColumnMatrix(X)
     y = np.asarray(y)
     # gather some statistics about the dataset
     n = len(y)
     c = len(np.unique(y))
     # define features to be extracted
     pca = PCA(num_components = (n-c))
     lda = LDA(num_components = self._num_components)
     # fisherfaces are a chained feature of PCA followed by LDA
     model = ChainOperator(pca,lda)
     # computing the chained model then calculates both decompositions
     model.compute(X,y)
     # store eigenvalues and number of components used
     self._eigenvalues = lda.eigenvalues
     self._num_components = lda.num_components
     # compute the new eigenspace as pca.eigenvectors*lda.eigenvectors
     self._eigenvectors = np.dot(pca.eigenvectors,lda.eigenvectors)
     # finally compute the features (these are the Fisherfaces)
     features = []
     for x in X:
         xp = self.project(x.reshape(-1,1))
         features.append(xp)
     return features
Esempio n. 2
0
    def compute(self, X, y):
        XC = asColumnMatrix(X)
        y = np.asarray(y)

        pca = PCA(num_components=(len(y) - len(np.unique(y))))
        lda = LDA(num_components=self._num_components)

        model = ChainOperator(pca, lda)
        model.compute(X, y)
        
        self._eigenvalues = lda.eigenvalues
        self._num_components = lda.num_components
        self._eigenvectors = np.dot(pca.eigenvectors, lda.eigenvectors)

        features = []
        for x in X:
            xp = self.project(x.reshape(-1,1))
            features.append(xp)
        return features