def __init__(self, data, S, w_augments, h_augments=None, num_bases=4, mask_zeros=False, **kwargs): PyMFBase.__init__(self, data, num_bases, **kwargs) if mask_zeros: mask = (data != 0).astype(int) else: mask = np.ones(data.shape) self.S = S * mask self.S_sqrt = np.sqrt(S) self.comp_S = (S - 1) * -1 self.w_augments = w_augments self.h_augments = h_augments S_shape = S.shape # Make sure augments have the right dimensions assert w_augments.shape[0] == S_shape[0] assert w_augments.shape[1] <= num_bases # set w_augments index m_range_w = list(range(0, S_shape[0])) n_range_w = list(range(num_bases - w_augments.shape[1], num_bases)) self.w_augments_idx = np.ix_(m_range_w, n_range_w)
def factorize(self, show_progress=False, compute_w=True, compute_h=True, compute_err=True, niter=1): """ Factorize s.t. WH = data Parameters ---------- show_progress : bool print some extra information to stdout. compute_h : bool iteratively update values for H. compute_w : bool iteratively update values for W. compute_err : bool compute Frobenius norm |data-WH| after each update and store it to .ferr[k]. Updated Values -------------- .W : updated values for W. .H : updated values for H. .ferr : Frobenius norm |data-WH|. """ PyMFBase.factorize(self, niter=1, show_progress=show_progress, compute_w=compute_w, compute_h=compute_h, compute_err=compute_err)
def __init__(self, data, num_bases=4, augments=None, smoothness=100, **kwargs): # Setup self.num_bases = num_bases self.smoothness = smoothness data_shape = data.shape self.w_outer = data_shape[0] self.h_outer = data_shape[1] self.augments = augments if self.augments is not None: # Make sure augments have the right dimensions assert augments.shape[0] == data.shape[0] assert augments.shape[1] <= num_bases m_range = list(range(0, data.shape[0])) n_range = list(range(num_bases - augments.shape[1], num_bases)) self.augments_idx = np.ix_(m_range, n_range) PyMFBase.__init__(self, data, num_bases, **kwargs) self._parse_args(**kwargs)
def __init__(self, data, S, num_bases=4, mask_zeros=False, **kwargs): PyMFBase.__init__(self, data, num_bases, **kwargs) if mask_zeros: mask = (data != 0).astype(int) else: mask = np.ones(data.shape) self.S = S * mask self.S_sqrt = np.sqrt(S) self.comp_S = (S - 1) * -1
def __init__(self, data, num_bases=0, center_mean=True, **kwargs): PyMFBase.__init__(self, data, num_bases=num_bases) # center the data around the mean first self._center_mean = center_mean if self._center_mean: # copy the data before centering it self._data_orig = data self._meanv = self._data_orig[:,:].mean(axis=1).reshape(-1,1) self.data = self._data_orig - self._meanv else: self.data = data
def __init__(self, data, w_augments, h_augments=None, num_bases=4, **kwargs): PyMFBase.__init__(self, data, num_bases, **kwargs) self.w_augments = w_augments self.h_augments = h_augments S_shape = data.shape # Make sure augments have the right dimensions assert w_augments.shape[0] == S_shape[0] assert w_augments.shape[1] <= num_bases #assert h_augments.shape[0] == S_shape[1] # set w_augments index m_range_w = list(range(0, S_shape[0])) n_range_w = list(range(num_bases - w_augments.shape[1], num_bases)) self.w_augments_idx = np.ix_(m_range_w, n_range_w)
def factorize(self, niter=10, compute_w=True, compute_h=True, show_progress=False, compute_err=True): """ Factorize s.t. WH = data Parameters ---------- niter : int number of iterations. show_progress : bool print some extra information to stdout. compute_h : bool iteratively update values for H. compute_w : bool iteratively update values for W. compute_err : bool compute Frobenius norm |data-WH| after each update and store it to .ferr[k]. Updated Values -------------- .W : updated values for W. .H : updated values for H. .ferr : Frobenius norm |data-WH| for each iteration. """ # init some learning parameters self._lamb_W = 1.0 / niter self._lamb_H = 1.0 / niter PyMFBase.factorize(self, niter=niter, compute_w=compute_w, compute_h=compute_h, show_progress=show_progress, compute_err=compute_err)
def factorize(self, niter=10, compute_w=True, compute_h=True, show_progress=False, compute_err=True): """ Factorize s.t. WH = data Parameters ---------- niter : int number of iterations. show_progress : bool print some extra information to stdout. compute_h : bool iteratively update values for H. compute_w : bool iteratively update values for W. compute_err : bool compute Frobenius norm |data-WH| after each update and store it to .ferr[k]. Updated Values -------------- .W : updated values for W. .H : updated values for H. .ferr : Frobenius norm |data-WH| for each iteration. """ # init some learning parameters self._lamb_W = 1.0/niter self._lamb_H = 1.0/niter PyMFBase.factorize(self, niter=niter, compute_w=compute_w, compute_h=compute_h, show_progress=show_progress, compute_err=compute_err)
def __init__(self, data, num_bases=4, lamb=2.0): # call inherited method PyMFBase.__init__(self, data, num_bases=num_bases) self._lamb = lamb
def __init__(self, data, k=-1, num_bases=4): # call inherited method PyMFBase.__init__(self, data, num_bases=num_bases) self._k = k if self._k == -1: self._k = num_bases