ToPS
VariableLengthMarkovChain.hpp
00001 /*
00002  *       VariableLengthMarkovChain.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 VLMC_MARKOV_CHAIN_HPP
00026 #define VLMC_MARKOV_CHAIN_HPP
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include "ProbabilisticModel.hpp"
00031 #include "Sequence.hpp"
00032 #include "FactorableModel.hpp"
00033 #include "ContextTree.hpp"
00034 
00035 
00036 #include <boost/shared_ptr.hpp>
00037 
00038 
00039 namespace tops{
00040 
00041 
00043   class DLLEXPORT VariableLengthMarkovChain : public FactorableModel {
00044   public:
00045     VariableLengthMarkovChain(){
00046     };
00047 
00048     VariableLengthMarkovChain(ContextTreePtr tree) {
00049       _tree = tree;
00050     }
00051     virtual ~VariableLengthMarkovChain() {};
00052 
00054     virtual void setTree(ContextTreePtr tree) {
00055       _tree = tree;
00056     }
00058     virtual ContextTreePtr getTree(){
00059       return _tree;
00060     }
00061     std::string print_graph () const ;
00063     virtual double evaluatePosition(const Sequence & s, unsigned int i) const;
00064 
00066     virtual double choosePosition(const Sequence & s, int i) const ;
00067 
00069     virtual std::string str() const ;
00070 
00072     virtual std::string model_name () const {
00073       return "VariableLengthMarkovChain";
00074     }
00075 
00077     virtual ProbabilisticModelCreatorPtr getFactory() const ;
00078 
00080     virtual int size() const;
00081 
00083     virtual void initialize(const ProbabilisticModelParameters & p) ;
00084 
00086     virtual ProbabilisticModelParameters parameters() const;
00087 
00088     virtual void removeSequenceFromModel(const Sequence & s,  int phase);
00089   private:
00090     ContextTreePtr _tree;
00091 
00092     void printDistribution(ContextTreePtr tree, ContextTreeNodePtr node, std::stringstream & out, AlphabetPtr alphabet) const ;
00093 
00094 
00095   };
00096   typedef boost::shared_ptr<VariableLengthMarkovChain> VariableLengthMarkovChainPtr;
00097 }
00098 
00099 #endif