From dcabb9e1db4292f4c59edde591c11320d731b8b3 Mon Sep 17 00:00:00 2001 From: vonclites Date: Wed, 16 Dec 2015 12:19:15 -0500 Subject: [PATCH] Changed LDA Feature class to handle non-continuous sets of class labels. Before, class labels had to be {0,1,2,3,..., n}. Now, labels may be {1, 3, 7, ..., n} --- py/facerec/feature.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/facerec/feature.py b/py/facerec/feature.py index de746f5..34c86fb 100644 --- a/py/facerec/feature.py +++ b/py/facerec/feature.py @@ -113,7 +113,7 @@ def compute(self, X, y): y = np.asarray(y) # calculate dimensions d = XC.shape[0] - c = len(np.unique(y)) + c = len(np.unique(y)) # set a valid number of components if self._num_components <= 0: self._num_components = c-1 @@ -124,7 +124,7 @@ def compute(self, X, y): # calculate the within and between scatter matrices Sw = np.zeros((d, d), dtype=np.float32) Sb = np.zeros((d, d), dtype=np.float32) - for i in range(0,c): + for i in np.unique(y): Xi = XC[:,np.where(y==i)[0]] meanClass = np.mean(Xi, axis = 1).reshape(-1,1) Sw = Sw + np.dot((Xi-meanClass), (Xi-meanClass).T)