We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cfbc113 commit 4f33961Copy full SHA for 4f33961
spHistEntropy.m
@@ -1,4 +1,4 @@
1
-function h = spHistEntropy(spA)
+function h = spHistEntropy(spA,isNorm)
2
%SPHISTENTROPY Normalized entropy of a histogram in sparse array format.
3
%
4
% h = spHistEntropy(v): Normalized entropy of a histogram v, where the
@@ -10,6 +10,10 @@
10
% By Andrew J. Milne, The MARCS Institute, Western Sydney University.
11
12
13
+if nargin < 2
14
+ isNorm = 1;
15
+end
16
+
17
% Normalize to make into probability mass function
18
histNorm = spA.Val./sum(spA.Val);
19
@@ -19,6 +23,11 @@
23
% Calculate entropy
20
24
logHistNorm = -log(histNorm);
21
25
logHistNorm(isinf(logHistNorm)) = 0;
22
-h = histNorm'*logHistNorm/log(N);
26
27
+if isNorm == 1
28
+ h = histNorm'*logHistNorm/log(N);
29
+else
30
+ h = histNorm'*logHistNorm;
31
32
33
end
0 commit comments