function H = entropy(counts)
%#codegen    
    p = counts(:)/sum(counts(:));
    p = p(p>0);
    H = -sum(p.*log(p));
    %for i=1:numel(p)
    %    H = H - p(i)*log2(p(i));
    %end
end