Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

Entropy.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Histogram_Entropy_h
00002 #define Impala_Core_Histogram_Entropy_h
00003 
00004 #include "Core/Histogram/Histogram1dTem.h"
00005 #include <math.h>
00006 
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Histogram
00012 {
00013 
00014 // this code is a translation of Jaspers implementation.
00015 // for now only with integer histograms, is the same thing possible with
00016 // contiuous values?
00017 double
00018 Entropy(const Histogram::Histogram1dTem<int>* hist)
00019 {
00020     const double cLog2 = log(2.); // used for log with base 2
00021     double sum = hist->TotalWeight();
00022     if(sum == 0)
00023         return 0.;
00024     double e=0;
00025     for(int i=0 ; i<hist->Size() ; ++i)
00026     {
00027         double d = hist->Elem(i);
00028         if(d>0)
00029         {
00030             d /= sum;
00031             e -= d * (log(d)/cLog2);
00032         }
00033     }
00034     return e;
00035 }    
00036 
00037 } // namespace Histogram
00038 } // namespace Core
00039 } // namespace Impala
00040 
00041 #endif

Generated on Fri Mar 19 09:31:10 2010 for ImpalaSrc by  doxygen 1.5.1