c# - Getting entropy of large file -


after going through posts related entropy of file question arose obtain entropy of large file. mean how can done , algorithm solve problem. possible somehow use linq , if how fast solution? advance.

it this.

static double calculateentropy(fileinfo file) {     int range = byte.maxvalue + 1; // 0 -> 256     byte[] values = file.readallbytes(file.fullname);      long[] counts = new long[range];     foreach (byte value in values)     {         counts[value]++;     }      double entropy = 0;     foreach (long count in counts)     {         if (count != 0)         {             double probability = (double)count / values.longlength;             entropy -= probability * math.log(probability, range);         }     }     return entropy; } 

you calculate character entropy rather byte entropy swapping in file.readalltext() , replacing byte char. doubt find faster solution using linq, try make puzzle.


Comments