def _transform(self, data, X): logger.info("Transforming data") loadings = self.model.loadings[:self.n_components] loadings = DenseMatrix(X.numCols(), self.n_components, loadings.flatten()) X = X.multiply(loadings) data = join(data, X, self.spark) del X return data
def fourier(X: RowMatrix, n_features, seed=23, gamma=1): p = X.numCols() random_state = numpy.random.RandomState(seed) w = numpy.sqrt(2 * gamma) * random_state.normal(size=(p, n_features)) w = DenseMatrix(p, n_features, w.flatten(), isTransposed=True) b = random_state.uniform(0, 2 * numpy.pi, size=n_features) Y = fourier_transform(X, w, b) return Y, w, b
def _transform(self, data): logger.info("Transforming data") W = self.model.loadings[:, :self.n_components] W = DenseMatrix(numRows=W.shape[0], numCols=W.shape[1], isTransposed=True, values=W.flatten()) X = self._row_matrix(data).multiply(W) data = join(data, X, self.spark) del X return data
def _whiten(self, X): s, v, _ = svd(X, X.numCols()) K = (v.T / s)[:, :self.n_components] S = K * scipy.sqrt(X.numRows()) S = DenseMatrix(S.shape[0], S.shape[1], S.flatten(), True) return X.multiply(S), K