crazybones
春芽
共回答了12个问题采纳率:83.3% 举报
已经调试过了
信息熵计算源代码
函数源程序 CalEntropy.m
Information Shannon Entropy calculation
jma@hebut.edu.cn, 22/08/2007
array : Discrete Probabilities Set
H : Output Shannon Entropy
function H = CalEntropy(array)
Vector number
num = length(array);
Check probabilities sum to 1:
if abs(sum(array) - 1) > .00001,
error('Probablities don''t sum to 1.')
end
Remove any zero probabilities %%
zeroProbs = find(array < eps);
if ~isempty(zeroProbs),
array(zeroProbs) = [];
disp('Removed zero or negative probabilities.')
End
Compute the entropy
H = -sum(array .* log2(array)); % 单位 bit/symbol
1年前
2