Skip to content

Commit 4f33961

Browse files
committed
Make normalization an option
1 parent cfbc113 commit 4f33961

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spHistEntropy.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function h = spHistEntropy(spA)
1+
function h = spHistEntropy(spA,isNorm)
22
%SPHISTENTROPY Normalized entropy of a histogram in sparse array format.
33
%
44
% h = spHistEntropy(v): Normalized entropy of a histogram v, where the
@@ -10,6 +10,10 @@
1010
% By Andrew J. Milne, The MARCS Institute, Western Sydney University.
1111

1212

13+
if nargin < 2
14+
isNorm = 1;
15+
end
16+
1317
% Normalize to make into probability mass function
1418
histNorm = spA.Val./sum(spA.Val);
1519

@@ -19,6 +23,11 @@
1923
% Calculate entropy
2024
logHistNorm = -log(histNorm);
2125
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+
end
2332

2433
end

0 commit comments

Comments
 (0)