00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00033 #ifndef SEQPP_VLM_TREE_H
00034 #define SEQPP_VLM_TREE_H
00035
00036 #include <seqpp/tree_t.h>
00037 #include <seqpp/SequenceSet.h>
00038 #include <seqpp/Coder.h>
00039
00047 class vlm_tree:public tree_t < vector<double> >
00048 {
00049 public:
00050 typedef tree_iterator < vector<double>, vector<double> &, vector<double> * >iterator;
00051 typedef tree_t < vector<double> > tree;
00052 typedef tree_node < vector<double> > node;
00053
00054
00060 vlm_tree (Coder & coder,
00061 int size, int maxdepth, vector<double> & init)
00062 :tree( size, init, maxdepth )
00063 {
00064 _size = size;
00065 _nbleaves = 0;
00066 _coder = &coder;
00067 _max_depth = maxdepth;
00068 _tmpcounts = new long[_size];
00069 };
00070
00076 vlm_tree (Coder & coder,
00077 int size, vector<double> & init, int maxdepth,
00078 const unsigned long * _count, int min_count = 3)
00079 :tree (size, init)
00080 {
00081 _size = size;
00082 _nbleaves = 0;
00083 _coder = &coder;
00084 _max_depth = maxdepth;
00085 _tmpcounts = new long[_size];
00086 iterator it = begin ();
00087 set_count( _count );
00088 filltree (size, init, 0, it, min_count);
00089 };
00090
00092 virtual ~vlm_tree(){
00093 delete[] _tmpcounts;
00094 }
00095
00103 long estimate_context ( const unsigned long * count, double cutoff );
00104
00109 double loglikelihood( const unsigned long * count );
00110
00114 int depth () const;
00115
00119 int nb_leaves() const{
00120 return _nbleaves;
00121 }
00122
00126 void tree_to_matrix( double* mat );
00127
00128
00129
00130
00137
00138
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 private:
00156 int _max_depth;
00157 int _size;
00158 int _nbleaves;
00159
00161 const unsigned long * _count;
00162
00163
00164 long *_tmpcounts;
00165 Coder * _coder;
00166
00167
00173 void filltree (int size, vector<double> & init, int depth,
00174 iterator & it, int min_count = 3);
00175
00181 void transitions ( iterator & it);
00182
00183
00189 bool estimate_context ( double &cutoff,
00190 vlm_tree::iterator & it);
00191
00198 void transitions( );
00199
00200
00207 long estimate_leaves( );
00208
00210 void set_count( const unsigned long * count ){
00211 _count = count;
00212 }
00213
00215 long path_code( iterator & it )
00216 {
00217 iterator tmpit( it );
00218 _coder->clear();
00219 while (!tmpit.on_root ())
00220 {
00221 _coder->push_back( tmpit.label () );
00222 tmpit.father ();
00223 }
00224 return _coder->_code;
00225 }
00226 };
00227 #endif