Пример #1
0
def test_lassoMask():
    np.random.seed(0)
    print("test lassoMask")
    ##############################################
    # Decomposition of a large number of signals
    ##############################################
    # data generation
    X = np.asfortranarray(np.random.normal(size=(300, 300)))
    # X=X./repmat(sqrt(sum(X.^2)),[size(X,1) 1])
    X = np.asfortranarray(X / np.tile(np.sqrt((X * X).sum(axis=0)),
                                      (X.shape[0], 1)),
                          dtype=myfloat)
    D = np.asfortranarray(np.random.normal(size=(300, 50)))
    D = np.asfortranarray(D / np.tile(np.sqrt((D * D).sum(axis=0)),
                                      (D.shape[0], 1)),
                          dtype=myfloat)
    mask = np.asfortranarray((X > 0))  # generating a binary mask
    param = {
        'lambda1': 0.15,  # not more than 20 non-zeros coefficients
        'numThreads':
        -1,  # number of processors/cores to use, the default choice is -1
        # and uses all the cores of the machine
        'mode': spams.PENALTY
    }  # penalized formulation
    tic = time.time()
    alpha = spams.lassoMask(X, D, mask, **param)
    tac = time.time()
    t = tac - tic
    print("%f signals processed per second\n" % (float(X.shape[1]) / t))

    return None
Пример #2
0
def test_lassoMask():
    np.random.seed(0)
    print("test lassoMask")
##############################################
# Decomposition of a large number of signals
##############################################
# data generation
    X = np.asfortranarray(np.random.normal(size=(300,300)))
    # X=X./repmat(sqrt(sum(X.^2)),[size(X,1) 1]);
    X = np.asfortranarray(X / np.tile(np.sqrt((X*X).sum(axis=0)),(X.shape[0],1)),dtype= myfloat)
    D = np.asfortranarray(np.random.normal(size=(300,50)))
    D = np.asfortranarray(D / np.tile(np.sqrt((D*D).sum(axis=0)),(D.shape[0],1)),dtype= myfloat)
    mask = np.asfortranarray((X > 0))  # generating a binary mask
    param = {
        'lambda1' : 0.15, # not more than 20 non-zeros coefficients
        'numThreads' : -1, # number of processors/cores to use; the default choice is -1
        # and uses all the cores of the machine
        'mode' : spams.PENALTY}        # penalized formulation
    tic = time.time()
    alpha = spams.lassoMask(X,D,mask,**param)
    tac = time.time()
    t = tac - tic
    print("%f signals processed per second\n" %(float(X.shape[1]) / t))

    return None
Пример #3
0
    def _transform_lasso(self, X, mask):
        """
        Performs LASSO transformation
        
        :param X: Input data. See `.fit` for more information.
        :param mask: Mask on input data. See `.fit` for more information.
        :return: Reconstruction parameters
        """

        if mask is None:
            return spams.lasso(**self.lasso_params(X)).T

        return spams.lassoMask(B=np.asfortranarray(mask.T),
                               **self.lasso_params(X)).T