Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/entropy.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function H = entropy(v, scale) |
matthiasm@8 | 2 % ENTROPY Entropy log base 2 |
matthiasm@8 | 3 % H = entropy(v) |
matthiasm@8 | 4 % If v is a matrix, we compute the entropy of each column |
matthiasm@8 | 5 % |
matthiasm@8 | 6 % % H = entropy(v,1) means we scale the result so that it lies in [0,1] |
matthiasm@8 | 7 |
matthiasm@8 | 8 if nargin < 2, scale = 0; end |
matthiasm@8 | 9 |
matthiasm@8 | 10 v = v + (v==0); |
matthiasm@8 | 11 H = -1 * sum(v .* log2(v), 1); % sum the rows |
matthiasm@8 | 12 |
matthiasm@8 | 13 if scale |
matthiasm@8 | 14 n = size(v, 1); |
matthiasm@8 | 15 unif = normalise(ones(n,1)); |
matthiasm@8 | 16 H = H / entropy(unif); |
matthiasm@8 | 17 end |