Exemple #1
0
def _somp(X_g, D, Gram, n_nonzero_coefs=None):
    n_atoms = D.shape[1]
    n_group_samples = X_g.shape[1]
    Z = np.zeros((n_atoms, n_group_samples))
    Dx = np.array([])
    Dx = Dx.astype(int)
    R = X_g

    if n_nonzero_coefs is not None:
        tol = 1e-20

        def cont_criterion():
            not_reached_sparsity = i < n_nonzero_coefs
            return (not_reached_sparsity and frobenius_squared(R) > tol)
    else:
        cont_criterion = lambda: frobenius_squared(R) > tol

    i = 0
    while (cont_criterion()):

        A = fast_dot(D.T, R)
        j = np.argmax([norm(A[k, :]) for k in range(n_atoms)])

        Dx = np.append(Dx, j)
        G = Gram[Dx, :][:, Dx]
        G = np.atleast_2d(G)
        try:
            G_inv = inv(G)
        except LinAlgError:
            print gram_singular_msg
            break

        Z[Dx, :] = fast_dot(fast_dot(inv(G_inv), D[:, Dx].T), X_g)
        R = X_g - fast_dot(D, Z)
        i += 1

    return Z
def _somp(X_g, D, Gram, n_nonzero_coefs=None):
    n_atoms = D.shape[1]
    n_group_samples = X_g.shape[1]
    Z = np.zeros((n_atoms, n_group_samples))
    Dx = np.array([])
    Dx = Dx.astype(int)
    R = X_g

    if n_nonzero_coefs is not None:
        tol = 1e-20

        def cont_criterion():
            not_reached_sparsity = i < n_nonzero_coefs
            return (not_reached_sparsity and frobenius_squared(R) > tol)
    else:
        cont_criterion = lambda: frobenius_squared(R) > tol

    i = 0
    while (cont_criterion()):

        A = fast_dot(D.T, R)
        j = np.argmax([norm(A[k, :]) for k in range(n_atoms)])

        Dx = np.append(Dx, j)
        G = Gram[Dx, :][:, Dx]
        G = np.atleast_2d(G)
        try:
            G_inv = inv(G)
        except LinAlgError:
            print gram_singular_msg
            break

        Z[Dx, :] = fast_dot(fast_dot(inv(G_inv), D[:, Dx].T), X_g)
        R = X_g - fast_dot(D, Z)
        i += 1

    return Z
 def cont_criterion():
     not_reached_sparsity = i < n_nonzero_coefs
     return (not_reached_sparsity and frobenius_squared(R) > tol)
Exemple #4
0
def approx_error_proc(X, Z, D):
    error = frobenius_squared(X - fast_dot(D, Z))
    return error
Exemple #5
0
def approx_error(D, Z, X, n_jobs=1):
    """computes the approximation error ||X-DZ||_{F}^{2} """
    if n_jobs > 1:
        set_openblas_threads(n_jobs)
    error = frobenius_squared(X - fast_dot(D, Z))
    return error
Exemple #6
0
 def cont_criterion():
     not_reached_sparsity = i < n_nonzero_coefs
     return (not_reached_sparsity and frobenius_squared(R) > tol)
Exemple #7
0
def approx_error_proc(X, Z, D):
    error = frobenius_squared(X - fast_dot(D, Z))
    return error
Exemple #8
0
def approx_error(D, Z, X, n_jobs=1):
    """computes the approximation error ||X-DZ||_{F}^{2} """
    if n_jobs > 1:
        set_openblas_threads(n_jobs)
    error = frobenius_squared(X - fast_dot(D, Z))
    return error