File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments