Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
Arquivo: pmf.py Projeto: ConanCui/pymf
    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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
Arquivo: pmf.py Projeto: rikkhill/pymf
    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)
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
 def __init__(self, data, num_bases=4, lamb=2.0):
     # call inherited method
     PyMFBase.__init__(self, data, num_bases=num_bases)
     self._lamb = lamb
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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