Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import numpy as np
from scipy import linalg
class ZCA():
Performs ZCA. Based on
def __init__(self, regularization=10**-5):
self.regularization = regularization
def fit(self, X):
X = np.array(X)
X = X.astype(np.float32)
self._mean = np.mean(X, axis=0)
X -= self._mean
sigma =,X) / X.shape[1]
U, S, V = linalg.svd(sigma)
tmp =, np.diag(1/np.sqrt(S+self.regularization)))
self._components =, U.T)
return self
def transform(self, X):
X = np.array(X)
X = X.astype(np.float32)
X_transformed = X - self._mean
X_transformed =, self._components.T)
return X_transformed
Copy link

yueranyuan commented Dec 1, 2015

removed dependency on sklearn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment