Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

trie/trie_manipulators/sequence/CandGenInfreqRemoveNopruneMerge.hpp

Go to the documentation of this file.
00001 #ifndef CandGenInfreqRemoveNopruneMerge_HPP
00002 #define CandGenInfreqRemoveNopruneMerge_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include "common/log.h"
00007 #include "apriori/bodon/trie/trie_manipulators/sequence/CandidateGeneratorNoprune.hpp"
00008 #include <vector>
00009 //#include <cstdio>
00010 //#include <iterator>   //for test
00011 
00012 
00013 
00014 
00015 namespace Bodon
00016 {
00017 namespace sequence
00018 {
00019    template <class DF_D, class TRIE>
00020    class CandGenInfreqRemoveNopruneMerge : 
00021          public CandidateGeneratorNoprune<DF_D, TRIE>
00022    {
00023       protected:
00024          unsigned int nr_of_deleted;
00025          unsigned int total_nr_of_deleted;
00026       public:
00027          CandGenInfreqRemoveNopruneMerge( TRIE& main_trie, DF_D& df_decoder ) : 
00028             CandidateGeneratorNoprune<DF_D, TRIE>(main_trie, df_decoder), 
00029             total_nr_of_deleted(0){}
00030 
00031 
00037          void generateCandidate(unsigned int candidate_size);
00038       
00039          void deleteInfrequent( const counter_t min_supp, 
00040                                 unsigned int candidate_size );
00041          void afterWorkDel();
00042       protected:
00043 
00045          void delete_infrequent_subtrie( TRIE* subtrie, 
00046                                          const counter_t min_supp,
00047                                          unsigned int step_to_cand_par );
00048 
00049       public:
00050          // No public members
00051    };
00052 
00053 
00054    template <class DF_D, class TRIE>
00055    void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE>::
00056    generateCandidate(const unsigned int candidate_size)
00057    {
00058       if(candidate_size == 3)
00059       {
00060          nr_of_new_candidates = 0;
00061 /*       if(NEE)
00062          {
00063             std::vector<item_t> NEEsum;
00064             generateCandidateFindParentNEE( &main_trie, NEEsum,
00065                                             candidate_size -2 );
00066                                             }
00067                                             else*/
00068             generateCandidateFindParent( &main_trie, 
00069                                          candidate_size -2 );
00070          log_dbg(0,"Number of newly generated candidates: %d", nr_of_new_candidates);
00071 #if DEBUG_LEVEL >= LEVEL_DBG
00072             nr_of_all_candidates += nr_of_new_candidates;
00073 #endif
00074       }
00075       else
00076          log_dbg(0,"This algorithm does not generate any candidate in this phase.");
00077 
00078    }
00079 
00080    template <class DF_D, class TRIE>
00081    void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE>::
00082    deleteInfrequent( const counter_t min_supp, unsigned int candidate_size )
00083    {
00084       assert(candidate_size > 1);
00085       nr_of_deleted = 0;
00086       nr_of_new_candidates = 0;
00087       delete_infrequent_subtrie( &main_trie, min_supp, 
00088                                  candidate_size - 1 );
00089       log_dbg(0,"Number of infrequent candidates: %d", nr_of_deleted);
00090       log_dbg(0,"Number of newly generated candidates (in del. phase!): %d", 
00091               nr_of_new_candidates);
00092 #if DEBUG_LEVEL >= LEVEL_DBG
00093       nr_of_all_candidates += nr_of_new_candidates;
00094       total_nr_of_deleted += nr_of_deleted;
00095 #endif
00096    }
00097 
00098    template <class DF_D, class TRIE>
00099    void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE>::
00100    afterWorkDel()
00101    {
00102       log_dbg(0,"The total number of generated candidates (in del. p.): %d", 
00103               nr_of_all_candidates);
00104       log_dbg(0,"The total number of infrequent candidates: %d", 
00105               total_nr_of_deleted);
00106    }
00107 
00108    template <class DF_D, class TRIE>
00109    void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE>::
00110    delete_infrequent_subtrie( TRIE* subtrie, const counter_t min_supp,
00111                               unsigned int step_to_cand_par)
00112    {
00113       typename TRIE::iterator itEdge( subtrie->edgelist.begin() );
00114       if(step_to_cand_par)
00115       {
00116          --step_to_cand_par;
00117          while( itEdge != subtrie->edgelist.end() )
00118          {
00119             df_decoder.pushItem( (*itEdge).first );
00120             delete_infrequent_subtrie( static_cast<TRIE*>((*itEdge).second), min_supp,
00121                                        step_to_cand_par);
00122             df_decoder.popItem();
00123             if( static_cast<TRIE*>((*itEdge).second)->edgelist.empty() )
00124             {
00125                delete static_cast<TRIE*>((*itEdge).second);
00126                itEdge = subtrie->edgelist.erase(itEdge);
00127             }
00128             else ++itEdge;
00129          }
00130       }
00131       else
00132       {
00133          while( itEdge != subtrie->edgelist.end() )
00134          {
00135             if( static_cast<TRIE*>((*itEdge).second)->getCounter() < min_supp )
00136             {
00137 #if DEBUG_LEVEL >= LEVEL_DBG
00138                   ++nr_of_deleted;
00139 #endif
00140                delete static_cast<TRIE*>((*itEdge).second);
00141                itEdge = subtrie->edgelist.erase(itEdge);
00142             }
00143             else
00144                ++itEdge;
00145          }
00146          generateCandidateAtParent(subtrie);
00147 #if DEBUG_LEVEL >= LEVEL_DBG
00148          for( typename TRIE::iterator it( subtrie->edgelist.begin() );
00149               it != subtrie->edgelist.end(); ++it)
00150             nr_of_new_candidates += 
00151                static_cast<TRIE*>((*it).second)->edgelist.size();
00152 #endif
00153       }
00154    }
00155 }
00156 }
00157 #endif

Generated on Sun Sep 17 17:50:38 2006 for FIM environment by  doxygen 1.4.4