ToPS
DegenerateDistribution.hpp
00001 /*
00002  *       DegenerateDistribution.hpp
00003  *
00004  *       Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br>
00005  *                      Ígor Bonádio <ibonadio@ime.usp.br>
00006  *                      Vitor Onuchic <vitoronuchic@gmail.com>
00007  *                      Alan Mitchell Durham <aland@usp.br>
00008  *
00009  *       This program is free software; you can redistribute it and/or modify
00010  *       it under the terms of the GNU  General Public License as published by
00011  *       the Free Software Foundation; either version 3 of the License, or
00012  *       (at your option) any later version.
00013  *
00014  *       This program is distributed in the hope that it will be useful,
00015  *       but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *       GNU General Public License for more details.
00018  *
00019  *       You should have received a copy of the GNU General Public License
00020  *       along with this program; if not, write to the Free Software
00021  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022  *       MA 02110-1301, USA.
00023  */
00024 
00025 #ifndef DEGENERATE_DISTRIBUTION_H
00026 #define DEGENERATE_DISTRIBUTION_H
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include "DiscreteIIDModel.hpp"
00031 
00032 namespace tops {
00034   class DLLEXPORT DegenerateDistribution : public DiscreteIIDModel
00035   {
00036     friend class boost::serialization::access;
00037     template <class Archive>
00038     void serialize (Archive & ar, const unsigned int )
00039     {
00040       ar & boost::serialization::base_object<DiscreteIIDModel> (*this);
00041       ar & _constant;
00042     }
00043   private:
00044     int _constant;
00045     double _huge_;
00046     double _zero;
00047   public:
00048     ~DegenerateDistribution() {}
00049     DegenerateDistribution() {
00050       _huge_ = -HUGE;
00051       _zero = 0.0;
00052     }
00053     DegenerateDistribution(int c) : DiscreteIIDModel("DegenerateDistribution")
00054     {
00055       _huge_ = -HUGE;
00056       _zero = 0.0;
00057       _constant=c;
00058     }
00059 
00061     virtual double evaluate(const Sequence & sequence, unsigned int begin, unsigned int end) const
00062     {
00063       for (int i = begin; (i < (int)sequence.size()) && (i < (int)end);  i++)
00064         if (sequence[i] != _constant)
00065           return -HUGE;
00066       return 0.0;
00067     }
00068 
00070     virtual double choose(Sequence & s, unsigned int size) const
00071     {
00072       s.resize(size);
00073       for (int i = 0; i < (int)size; i++)
00074         s[i] = _constant;
00075       return 0.0;
00076     }
00077     virtual std::string str() const
00078     {
00079           std::stringstream out;
00080           out << _constant << std::endl;
00081           return out.str();
00082     }
00083     virtual double & log_probability_of(int c)
00084     {
00085       if(c != _constant)
00086         return _huge_;
00087       return _zero;
00088     }
00089 
00090     virtual int choose () const
00091     {
00092       return _constant;
00093     }
00094   };
00095   typedef boost::shared_ptr <DegenerateDistribution> DegenerateDistributionPtr;
00096 }
00097 
00098 #endif