view util/classes/@dictionary/spark.m @ 224:fd0b5d36f6ad danieleb

Updated the contents of this branch with the contents of the default branch.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 12 Apr 2012 13:52:28 +0100
parents e3035d45d014
children
line wrap: on
line source
function varargout = Spark(obj)
% Calculates the minimum number of linearly dependent atoms in the matrix A
% WARNING: this function computes a combinatorial function, use only if the
% size of the problem is small (i.e. <20)
if nargout <= 1
    A = obj.phi;
    k = size(A,2);
    if k>20
        warning('This function computes a combinatorial function, use only if thesize of the problem is small (i.e. <20).');
        choice = input('The calculation of spark will take a long time... do you wish to continue anyway (y/n)','s');
        if strcmpi( choice,'n')
            return
        end
    end
    sigma = 2;
    while true
        P = nchoosek(1:k,sigma);
        for i=1:size(P,1)
            r = rank(A(:,P(i,:)));
            if r<sigma
                varargout{1} = sigma;
                return
            end
        end
        sigma = sigma + 1;
        if sigma==k
            varargout{1} = inf;
            return
        end
    end
else
    %% TODO: calculate lower and upper bounds on the spark
    varargout{1} = 2;
    varargout{2} = inf;
end