ToPS
InhomogeneousMarkovChain.hpp
00001 /*
00002  *       InhomogeneousMarkovChain.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 WEIGHT_ARRAY_MODEL_HPP
00026 #define WEIGHT_ARRAY_MODEL_HPP
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include "ContextTree.hpp"
00031 #include "ProbabilisticModel.hpp"
00032 #include "InhomogeneousFactorableModel.hpp"
00033 #include "InhomogeneousMarkovChainCreator.hpp"
00034 #include <boost/shared_ptr.hpp>
00035 
00036 namespace tops {
00037 
00039   class DLLEXPORT InhomogeneousMarkovChain : public InhomogeneousFactorableModel
00040   {
00041   private:
00042     std::vector <ContextTreePtr> _context_trees;
00043     bool _phased;
00044 
00045 
00046     void printDistribution(ContextTreePtr tree, ContextTreeNodePtr node, std::stringstream & out, AlphabetPtr alphabet) const;
00047   public:
00048     InhomogeneousMarkovChain(){
00049       _phased = false;
00050     }
00051 
00052     virtual void setPositionSpecificDistribution(std::vector<ContextTreePtr> position_specific_context_trees) {
00053       _context_trees = position_specific_context_trees;
00054     }
00055 
00057     virtual double evaluatePosition(const Sequence & s, int i, int t) const;
00058 
00060     virtual int choosePosition(const Sequence & s, int i, int t ) const;
00061 
00062     virtual int maximumTimeValue() const {
00063       return _context_trees.size()-1;
00064     }
00065 
00066     virtual bool isPhased() const{
00067       return _phased;
00068     }
00069     virtual void phased(bool phased) {
00070       _phased  = phased;
00071     }
00072     virtual std::string model_name() const {
00073       return "InhomogeneousMarkovChain";
00074     }
00075     virtual ProbabilisticModelCreatorPtr getFactory () const {
00076       return InhomogeneousMarkovChainCreatorPtr(new InhomogeneousMarkovChainCreator());
00077     }
00078     virtual InhomogeneousFactorableModel * inhomogeneous()  {
00079       return this;
00080     }
00081     virtual std::string str() const ;
00082     virtual int size() const ;
00083 
00084     virtual void removeSequenceFromModel(const Sequence & s,  int phase) ;
00085 
00086     virtual void initialize(const ProbabilisticModelParameters & p)  ;
00087     virtual ProbabilisticModelParameters parameters() const;
00088   };
00089 
00090   typedef boost::shared_ptr <InhomogeneousMarkovChain> InhomogeneousMarkovChainPtr;
00091 
00092 }
00093 
00094 
00095 #endif