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.
Asked
Active
Viewed 1,207 times
-1
-
Fast approximate logs might be worth a look? https://code.google.com/p/fastapprox/ – NPE Jan 24 '15 at 16:17
-
Or maybe vectorized logs? https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-84D9D164-743E-496D-A1E4-4FB6F7F89A06.htm – NPE Jan 24 '15 at 16:19
-
1Given a maximum of 65535 symbols, that's 65535 logarithms to be calcualted in the worst case. On my 5 year old computer this takes... (runs test) ... 1.8 milliseconds. The problem being...? – Damon Jan 24 '15 at 20:08
1 Answers
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.

vy32
- 28,461
- 37
- 122
- 246