Version 4.0.0
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

Markov.h

Go to the documentation of this file.
00001 /* seqpp/Markov.h
00002  *
00003  * Copyright (C) 2003 Laboratoire Statistique & Génome
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00028 #ifndef SEQPP_MARKOV_H
00029 #define SEQPP_MARKOV_H
00030 
00031 #include <seqpp/PhasedMarkov.h>
00032 #include <seqpp/arnoldi.h>
00033 
00043 class Markov : public PhasedMarkov
00044 {
00045  public :
00046  
00048   /*
00049     \param markov_file description of an input model in a file (generated by print method) 
00050     \param calc_rank calculus of the convergence rank if true
00051     Exple of file:
00052     \code
00053     # 4 <- Order of the phased Markov chain<br>
00054     # 3 <- Phase<br>
00055     # 4 <- Alphabet size<br>
00056     # 10 steps <- Convergence to the stationnary distribution (!!Optionnal!!)<br>
00057     # Transition matrix:<br>
00058     ...<br>
00059     # Stationnary Probability: (!!Optionnal!!)<<br>
00060     ...
00061     \endcode
00062   */
00063   Markov( const char * ConfFile, 
00064           bool calc_rank = false );
00066 
00070   Markov( const SequenceSet & seqset,
00071           bool calc_rank = false );
00073 
00077   Markov( const Sequence & seq,
00078           bool calc_rank = false );
00079 
00081   Markov( const Markov & );
00082   
00084   Markov();
00085 
00087 
00092   Markov( short size, short order):PhasedMarkov(size,order,1) 
00093   {//cout<<"Markov constr. 6"<<endl;
00094     _Pi=_Pis[0];_Mu=NULL;_PowPi=NULL;};
00095 
00097 
00102   Markov(const Markov &M1, const Markov &M2,const float p);
00103 
00105 
00123   Markov( const gsl_rng * r,
00124           short size, short order,
00125           bool calc_rank = false)
00126     : PhasedMarkov( r, size, order, 1, calc_rank ){
00127     _Pi=_Pis[0];_Mu=NULL;_PowPi=NULL;
00128   };
00129 
00131 
00137   Markov( unsigned long * count,
00138           short size, short order,
00139           bool calc_rank = false );
00140 
00142   virtual Markov::~Markov();
00143 
00144   //---------------------------------------
00146 
00152   template <class TSeq>
00153   void estimate( const TSeq & tseq,
00154                  unsigned long beg, unsigned long end,
00155                  bool calc_rank ) {
00156     this->PhasedMarkov::estimate( tseq, 1,0, beg, end, calc_rank );
00157   }
00158   
00159   //---------------------------------------
00161   const double * markov_matrix() const{
00162     return PhasedMarkov::markov_matrix(0);
00163   } 
00164 
00166 
00185   void draw_markov_matrix(const  gsl_rng * r){
00186     PhasedMarkov::draw_markov_matrices(r);
00187   }
00188 
00190   void free_markov_matrix(){
00191     PhasedMarkov::free_markov_matrices();
00192   }
00194   /*
00195     \param force "true" to force the calculation, even if the law already exists. Default => "false". 
00196   */ 
00197   void compute_stat_law( bool force ){
00198     PhasedMarkov::compute_stat_laws( force );
00199     _Mu = _Mus[0];
00200   }  
00202   void free_stat_law(){
00203     PhasedMarkov::free_stat_laws();
00204     _Mu = NULL;
00205   }
00207   const double * stat_law() const{
00208     return PhasedMarkov::stat_law(0);
00209   }
00210   //--------------------------------------- 
00212   virtual int compute_rank(); 
00213   
00215   void compute_power();
00216    
00218   int free_power();
00219 
00221 
00227   // double proba_step( const string & w1, const string & w2, int step ) const;
00229 
00234   //double proba_step( const vector<short> & w1, const vector<short> & w2, int step ) const;
00235 
00237 
00243   double proba_step( long w1, long w2, int step ){
00244     compute_rank();
00245     compute_power();
00246       if (step<=_rank)
00247         return(_PowPi[step-1][w1][w2]);
00248       else 
00249         return(_Mu[w2]);
00250   }
00251    
00252   //---------------------------------------
00254   bool isPi() const { return(_Pi != NULL);};
00256   bool isPow() const { return(_PowPi != NULL);};
00258   bool isMu()  const { return(_Mu != NULL);};
00259 
00261 
00264   double & operator() (int i){ 
00265     return(_Pi[i]); 
00266   }
00268 
00271   double Mu(int i) const { 
00272     return(_Mu[i]); 
00273   }
00274 
00275 protected :
00276   
00278   double *_Pi;
00279  
00281   double *_Mu; 
00282   
00284   double ***_PowPi;
00285 }; 
00286 #endif/*SEQPP_MARKOV_H*/
00287 



Download seq++ 4.0.0
Download previous versions
Statistique & Genome Home


Generated on Wed Mar 23 09:25:57 2005 for seqpp by doxygen 1.3.9.1