src/mf_algorithms/mf.py
def leftbrk(self, X, lf, rf, row, **kwargs):
    
        '''
        Block randomized Kaczmarz update step (the subset of columns in the right factor matrix are chosen via weighted sample)
        
        Parameters:
        ---------------
        X:      array
                The data matrix "X" to be factored
        lf:     array
                The left factor matrix to be updated
        rf:     array
                The right factor matrix used in the update
        row:    int 
                The row of the data matrix "X" used in the update
        '''
        
        siter = kwargs.get('siter', 1)
        eps = kwargs.get('eps', 1e-3)
        s = kwargs.get('s', 1)
        
        
        for i in np.arange(siter):
            if s == 1:
                # sample index for entry of data matrix
                kaczcol = np.random.choice(rf.shape[1], size = s, p = self.weightsample(rf, 0), replace = False)
                lf[row, :] = lf[row, :] + (X[row, kaczcol] - lf[row, :] @ rf[:, kaczcol]) / (np.linalg.norm(rf[:, kaczcol])**2) * rf[:, kaczcol].T 
            else:
                # sample until at least one row/column is nonzero
                resample = True
                while(resample):
                    kaczcol = np.random.choice(rf.shape[1], size = s, replace = False)
                    if (np.linalg.norm(rf[:, kaczcol]) > 0):
                        resample = False

                # compute BRK step
                lf[row, :] = lf[row, :] + np.linalg.lstsq(rf[:, kaczcol].T, (X[None, row, kaczcol] - lf[row, :] @ rf[:, kaczcol]).T, rcond = None)[0].T	
            if np.linalg.norm(lf[row, :] @ rf - X[row, :]) < eps:
                break
        return lf

        Block randomized Kaczmarz update step (the subset of columns in the right factor matrix are chosen via weighted sample)
        
        Parameters:
        ---------------
        X:      array
                The data matrix "X" to be factored
        lf:     array
                The left factor matrix to be updated
        rf:     array
                The right factor matrix used in the update
        row:    int 
                The row of the data matrix "X" used in the update
        
Block randomized Kaczmarz update step (the subset of columns in the right factor matrix are chosen via weighted sample)
Parameters.

array
The data matrix "X" to be factored
lf:     array
The left factor matrix to be updated
rf:     array
The right factor matrix used in the update
row:    int
The row of the data matrix "X" used in the update
Block randomized Kaczmarz update step ( the subset of columns in the right factor matrix are chosen via weighted sample ) Parameters . array The data matrix " X " to be factored lf : array The left factor matrix to be updated rf : array The right factor matrix used in the update row : int The row of the data matrix " X " used in the update
def leftbrk(self, X, lf, rf, row, **kwargs):
        siter = kwargs.get('siter', 1)
        eps = kwargs.get('eps', 1e-3)
        s = kwargs.get('s', 1)
        for i in np.arange(siter):
            if s == 1:
                kaczcol = np.random.choice(rf.shape[1], size = s, p = self.weightsample(rf, 0), replace = False)
                lf[row, :] = lf[row, :] + (X[row, kaczcol] - lf[row, :] @ rf[:, kaczcol]) / (np.linalg.norm(rf[:, kaczcol])**2) * rf[:, kaczcol].T 
            else:
                resample = True
                while(resample):
                    kaczcol = np.random.choice(rf.shape[1], size = s, replace = False)
                    if (np.linalg.norm(rf[:, kaczcol]) > 0):
                        resample = False
                lf[row, :] = lf[row, :] + np.linalg.lstsq(rf[:, kaczcol].T, (X[None, row, kaczcol] - lf[row, :] @ rf[:, kaczcol]).T, rcond = None)[0].T	
            if np.linalg.norm(lf[row, :] @ rf - X[row, :]) < eps:
                break
        return lf
def leftbrk ( self , X , lf , rf , row , ** kwargs ) : siter = kwargs . get ( 'siter' , 1 ) eps = kwargs . get ( 'eps' , 1e-3 ) s = kwargs . get ( 's' , 1 ) for i in np . arange ( siter ) : if s == 1 : kaczcol = np . random . choice ( rf . shape [ 1 ] , size = s , p = self . weightsample ( rf , 0 ) , replace = False ) lf [ row , : ] = lf [ row , : ] + ( X [ row , kaczcol ] - lf [ row , : ] @ rf [ : , kaczcol ] ) / ( np . linalg . norm ( rf [ : , kaczcol ] ) ** 2 ) * rf [ : , kaczcol ] . T else : resample = True while ( resample ) : kaczcol = np . random . choice ( rf . shape [ 1 ] , size = s , replace = False ) if ( np . linalg . norm ( rf [ : , kaczcol ] ) > 0 ) : resample = False lf [ row , : ] = lf [ row , : ] + np . linalg . lstsq ( rf [ : , kaczcol ] . T , ( X [ None , row , kaczcol ] - lf [ row , : ] @ rf [ : , kaczcol ] ) . T , rcond = None ) [ 0 ] . T if np . linalg . norm ( lf [ row , : ] @ rf - X [ row , : ] ) < eps : break return lf
Block randomized Kaczmarz update step (the subset of columns in the right factor matrix are chosen via weighted sample)
Parameters:
Block randomized Kaczmarz update step ( the subset of columns in the right factor matrix are chosen via weighted sample ) Parameters :
'''
        Block randomized Kaczmarz update step (the subset of columns in the right factor matrix are chosen via weighted sample)
        
        Parameters:
        ---------------
        X:      array
                The data matrix "X" to be factored
        lf:     array
                The left factor matrix to be updated
        rf:     array
                The right factor matrix used in the update
        row:    int 
                The row of the data matrix "X" used in the update
        ''' # sample index for entry of data matrix # sample until at least one row/column is nonzero # compute BRK step
self
X
lf
rf
row