问题
So, after trying a heavy cicle-based function for calculating the joint entropy of two sources of information, I found this useful MATLAB function, accumarray
, and tried the following code:
function e = jointEntropy(fonte1, fonte2)
i = double(fonte1(:))+ 1;
j = double(fonte2(:)) + 1;
subs = [i j];
f = accumarray(subs, ones(length(fonte1), 1));
p = f / length(fonte1);
freq = f ~= 0;
prob = p(freq);
e = -sum(prob.*log2(prob));
end
, where fonte1
and fonte2
are the information sources, 1xN
arrays. This worked just fine with examples in which both sources had only positive integer values, but then I tried to use it with audio files (i.e., arrays whose values ranged from -1 to 1) and it kept giving me an error. I tried adding 1 to each array (to range from 0 to 2), multiplying them by 100 and rounding the numbers, in order to obtain non-negative integers, but it still doesn't work.
Any idea/ alternative to this code would be greatly appreciated.
来源:https://stackoverflow.com/questions/26512778/joint-entropy-of-audio-files