def _update_w(self): svd_mdl = SVD(self.data) svd_mdl.factorize() U, S, V = svd_mdl.U, svd_mdl.S, svd_mdl.V # The first left singular vector is nonnegative # (abs is only used as values could be all negative) self.W[:, 0] = np.sqrt(S[0, 0]) * np.abs(U[:, 0]) #The first right singular vector is nonnegative self.H[0, :] = np.sqrt(S[0, 0]) * np.abs(V[0, :].T) for i in range(1, self._num_bases): # Form the rank one factor Tmp = np.dot(U[:, i:i + 1] * S[i, i], V[i:i + 1, :]) # zero out the negative elements Tmp = np.where(Tmp < 0, 0.0, Tmp) # Apply 2nd SVD svd_mdl_2 = SVD(Tmp) svd_mdl_2.factorize() u, s, v = svd_mdl_2.U, svd_mdl_2.S, svd_mdl_2.V # The first left singular vector is nonnegative self.W[:, i] = np.sqrt(s[0, 0]) * np.abs(u[:, 0]) #The first right singular vector is nonnegative self.H[i, :] = np.sqrt(s[0, 0]) * np.abs(v[0, :].T)
def _update_w(self): svd_mdl = SVD(self.data) svd_mdl.factorize() U, S, V = svd_mdl.U, svd_mdl.S, svd_mdl.V # The first left singular vector is nonnegative # (abs is only used as values could be all negative) self.W[:,0] = np.sqrt(S[0,0]) * np.abs(U[:,0]) #The first right singular vector is nonnegative self.H[0,:] = np.sqrt(S[0,0]) * np.abs(V[0,:].T) for i in range(1,self._num_bases): # Form the rank one factor Tmp = np.dot(U[:,i:i+1]*S[i,i], V[i:i+1,:]) # zero out the negative elements Tmp = np.where(Tmp < 0, 0.0, Tmp) # Apply 2nd SVD svd_mdl_2 = SVD(Tmp) svd_mdl_2.factorize() u, s, v = svd_mdl_2.U, svd_mdl_2.S, svd_mdl_2.V # The first left singular vector is nonnegative self.W[:,i] = np.sqrt(s[0,0]) * np.abs(u[:,0]) #The first right singular vector is nonnegative self.H[i,:] = np.sqrt(s[0,0]) * np.abs(v[0,:].T)
def _update_w(self): # compute eigenvectors and eigenvalues using SVD svd_mdl = SVD(self.data) svd_mdl.factorize() # argsort sorts in ascending order -> do reverese indexing # for accesing values in descending order S = np.diag(svd_mdl.S) order = np.argsort(S)[::-1] # select only a few eigenvectors ... if self._num_bases >0: order = order[:self._num_bases] self.W = svd_mdl.U[:,order] self.eigenvalues = S[order]
def update_w(self): # compute eigenvectors and eigenvalues using SVD svd_mdl = SVD(self.data) svd_mdl.factorize() # argsort sorts in ascending order -> do reverese indexing # for accesing values in descending order S = np.diag(svd_mdl.S) order = np.argsort(S)[::-1] # select only a few eigenvectors ... if self._num_bases >0: order = order[:self._num_bases] self.W = svd_mdl.U[:,order] self.eigenvalues = S[order]
def comp_prob(d, k): # compute statistical leverage score c = np.round(k - k/5.0) svd_mdl = SVD(d, k=c) svd_mdl.factorize() if scipy.sparse.issparse(self.data): A = svd_mdl.V.multiply(svd_mdl.V) ## Rule 1 pcol = np.array(A.sum(axis=0)/k) else: A = svd_mdl.V[:k,:]**2.0 ## Rule 1 pcol = A.sum(axis=0)/k #c = k * np.log(k/ (self._eps**2.0)) #pcol = c * pcol.reshape((-1,1)) pcol /= np.sum(pcol) return pcol
def comp_prob(d, k): # compute statistical leverage score c = np.round(k - k / 5.0) svd_mdl = SVD(d, k=c) svd_mdl.factorize() if scipy.sparse.issparse(self.data): A = svd_mdl.V.multiply(svd_mdl.V) ## Rule 1 pcol = np.array(A.sum(axis=0) / k) else: A = svd_mdl.V[:k, :]**2.0 ## Rule 1 pcol = A.sum(axis=0) / k #c = k * np.log(k/ (self._eps**2.0)) #pcol = c * pcol.reshape((-1,1)) pcol /= np.sum(pcol) return pcol