问题
Is there a fast way to calculate shannon entropy of a buffer of 16-bit numbers without having the calculate the log2 of every frequency count? The log calculations are quite slow.
回答1:
Okay, so the answer is that there is no way to do it without calculating the log function, but if you pre-calculate the logs, it's not so bad.
My buffer is 4096 bytes in size, so there are between 1..2048 of each possible 2-byte value. So the logs of 1/2048 .. 2048/2048 need to be pre-calculated. Then the calculation of each log is just an array lookup.
来源:https://stackoverflow.com/questions/28127433/fast-shannon-entropy-calculation