Exemplo n.º 1
0
 def execute(self, rowmatrix, objective, return_N=False):
     """
     matrix: a RowMatrix object storing the matrix A
     objective: either 'x' or 'N'
         'x': the function returns the solution to the problem min_x || PA[:,:-1]x - PA[:,-1] ||_2
         'N': the function returns a square matrix N such that PA[:,:-1]*inv(N) is a matrix with orthonormal columns
     return_N: when the objective is 'x', whether to return the matrix N which makes PA[:,:-1]*inv(N) have orthonormal columns
     """
     logger.info('In projections, computing {0}!'.format(objective))
     PA = self.__project(rowmatrix)
     if objective == 'x':
         return PA.map(lambda (key,pa): get_x(pa,return_N)).collect()
     elif objective == 'N':
         return PA.map(lambda (key,pa): get_N(pa)).collect()
     else:
         raise ValueError('Please enter a valid objective!')
    def execute(self, matrix, objective, s, return_N=False):
        """
        matrix: a RowMatrix object storing the matrix A
        objective: either 'x' or 'N'
            'x': the function returns the solution to the problem min_x || SA[:,:-1]x - SA[:,-1] ||_2
            'N': the function returns a square matrix N such that SA[:,:-1]*inv(N) is a matrix with orthonormal columns
        s: samping size
        return_N: when the objective is 'x', whether to return the matrix N which makes SA[:,:-1]*inv(N) has orthonormal columns
        """
        logger.info('In sampling, computing {0}!'.format(objective))
        lev_sum = self.__get_lev_sum(matrix)
        SA = self.__sample(matrix, s, lev_sum)

        if objective == 'x':
            return SA.map(lambda (key,sa): get_x(sa,return_N)).collect()
        elif objective == 'N':
            return SA.map(lambda (key,sa): get_N(sa)).collect()
        else:
            raise ValueError('Please enter a valid objective!')