// -*- c++ -*- /*****************************************************************************/ // Copyright (c) Illumina 2008 // Author: Richard Shaw // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). /*****************************************************************************/ #ifndef INFO_CALC_H #define INFO_CALC_H /*****************************************************************************/ #include #include "common/MathCompatibility.hh" /*****************************************************************************/ class Info_Calc { public: /** It is up to the user to guard against pointless instantiation, i.e. with a total_freq of 0, to avoid repeated checks in pointless calls of the operator() method. */ Info_Calc(unsigned int total_freq) : my_total_freq(total_freq), my_entropy(0.0) { assert(total_freq > 0); } ~Info_Calc() { } void operator()(const unsigned int freq) { if (freq > 0) { const double prob((1.0 * freq) / my_total_freq); my_entropy += (prob * log(prob)); } } double info_val() { return ((((my_entropy * our_to_base2) + our_prior_entropy) / 2.0) * my_total_freq); } private: unsigned int my_total_freq; double my_entropy; static const float our_prior_entropy; static const float our_to_base2; }; /*****************************************************************************/ const float Info_Calc::our_prior_entropy(2.0); const float Info_Calc::our_to_base2(1.0 / log(2.0)); /*****************************************************************************/ #endif // ! INFO_CALC_H /*****************************************************************************/