def get_zca_whitening_principal_components_img(X):
 flatX = np.reshape(X, (X.shape[0], ((X.shape[1] * X.shape[2]) * X.shape[3])))
 print 'zca : computing sigma ..'
 sigma = (np.dot(flatX.T, flatX) / flatX.shape[0])
 print 'zca : computing U, S and V ..'
 (U, S, V) = linalg.svd(sigma)
 print 'zca : computing principal components ..'
 principal_components = np.dot(np.dot(U, np.diag((1.0 / np.sqrt((S + 1e-06))))), U.T)
 return principal_components

def get_zca_whitening_principal_components_img ( X ) : flatX = np . reshape ( X , ( X . shape [ 0 ] , ( ( X . shape [ 1 ] * X . shape [ 2 ] ) * X . shape [ 3 ] ) ) ) print 'zca : computing sigma ..' sigma = ( np . dot ( flatX . T , flatX ) / flatX . shape [ 0 ] ) print 'zca : computing U, S and V ..' ( U , S , V ) = linalg . svd ( sigma ) print 'zca : computing principal components ..' principal_components = np . dot ( np . dot ( U , np . diag ( ( 1.0 / np . sqrt ( ( S + 1e-06 ) ) ) ) ) , U . T ) return principal_components
return the zca whitening principal components matrix .