Skip to content

Commit 3cbab8b

Browse files
committed
Initial commit
1 parent 233b97e commit 3cbab8b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spHistEntropy.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function h = spHistEntropy(spA)
2+
%SPHISTENTROPY Normalized entropy of a histogram in sparse array format.
3+
%
4+
% h = spHistEntropy(v): Normalized entropy of a histogram v, where the
5+
% histogram is normalized to convert it into a probability mass function so
6+
% its emtropy can be calculated. Normalized entropy is entropy divided by
7+
% maximum possible entropy; it is, therefore, unitless and in the interval
8+
% [0,1]; it allows for comparisons between differently sized sample spaces.
9+
%
10+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University.
11+
12+
13+
% Normalize to make into probability mass function
14+
histNorm = spA.Val./sum(spA.Val);
15+
16+
% Size of sample space
17+
N = prod(spA.Size);
18+
19+
% Calculate entropy
20+
logHistNorm = -log(histNorm);
21+
logHistNorm(isinf(logHistNorm)) = 0;
22+
h = histNorm'*logHistNorm/log(N);
23+
24+
end

0 commit comments

Comments
 (0)