home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / compress / 2792 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.2 KB  |  41 lines

  1. Newsgroups: comp.compression
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!dog.ee.lbl.gov!overload.lbl.gov!s1.gov!lip
  3. From: lip@s1.gov (Loren I. Petrich)
  4. Subject: Re: more entropy
  5. Message-ID: <1992Jul24.003709.21603@s1.gov>
  6. Sender: usenet@s1.gov
  7. Nntp-Posting-Host: s1.gov
  8. Organization: LLNL
  9. References: <1992Jul23.174740.14559@usenet.ins.cwru.edu>
  10. Date: Fri, 24 Jul 1992 00:37:09 GMT
  11. Lines: 28
  12.  
  13. In article <1992Jul23.174740.14559@usenet.ins.cwru.edu> daf10@po.CWRU.Edu (David A. Ferrance) writes:
  14.  
  15. >If I have an unsigned int count[256][256], what is wrong with
  16. >calculating entropy like this:
  17.  
  18. >for (i=0;i<256;i++) for (j=0;j<256;j++)  {
  19. >    freq = count[i][j] / total;
  20. >    ent += freq * log10(1/freq) / 0.30103;
  21. >    }
  22.  
  23.     I presume that the code also included:
  24.  
  25.     ent = 0;
  26.     total = 0;
  27.     for (i=0;i<256;i++) for (j=0;j<256;j++)
  28.       total += count[i][j];
  29.  
  30. >Where total and ent are doubles, total is the # of bytes total, ent
  31. >starts off as 0, and the values of the array are the # of occurances of
  32. >each 2 letter combination?
  33.  
  34. >I get values > 8.
  35.  
  36.     The theoretical maximum value is log2(256*256) = 16.
  37.  
  38.     Yes, some versions of C do have a "log2" function (logarithm
  39. to base two).
  40.  
  41.