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/inhomogeneous_trie/trie_manipulators/sequence/CandidateGeneratorNoprune.hpp"
00008 #include <vector>
00009
00010
00011
00012
00013
00014
00015 namespace Bodon
00016 {
00017 namespace sequence
00018 {
00019 namespace inhomogeneous_trie
00020 {
00021 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR>
00022 class CandGenInfreqRemoveNopruneMerge :
00023 public CandidateGeneratorNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>
00024 {
00025 private:
00026 typedef CandidateGeneratorNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR> PARENT;
00027 protected:
00028 unsigned int nr_of_deleted;
00029 unsigned int total_nr_of_deleted;
00030 public:
00031 CandGenInfreqRemoveNopruneMerge( TRIE& main_trie, DF_D& df_decoder,
00032 LEAF_ALLOCATOR& s_alloc ) :
00033 CandidateGeneratorNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>(
00034 main_trie, df_decoder, s_alloc),
00035 total_nr_of_deleted(0){}
00036
00037
00043 void generateCandidate(unsigned int candidate_size);
00044
00045 void deleteInfrequent( const counter_t min_supp,
00046 unsigned int candidate_size );
00047 void afterWorkDel();
00048 protected:
00049
00051 void delete_infrequent_subtrie( TRIE* subtrie,
00052 const counter_t min_supp,
00053 unsigned int step_to_cand_par );
00054
00055
00056 public:
00057
00058 };
00059
00060
00061 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR>
00062 void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::
00063 generateCandidate(const unsigned int candidate_size)
00064 {
00065 if(candidate_size == 3)
00066 {
00067 PARENT::nr_of_new_candidates = 0;
00068 generateCandidateFindParent( &this->main_trie,
00069 candidate_size -2 );
00070 log_dbg(0,"Number of newly generated candidates: %d", PARENT::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, class LEAF, class LEAF_ALLOCATOR>
00081 void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::
00082 deleteInfrequent( const counter_t min_supp, unsigned int candidate_size )
00083 {
00084 assert(candidate_size > 1);
00085 nr_of_deleted = 0;
00086 PARENT::nr_of_new_candidates = 0;
00087 delete_infrequent_subtrie( &this->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 PARENT::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, class LEAF, class LEAF_ALLOCATOR>
00099 void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::
00100 afterWorkDel()
00101 {
00102 log_dbg(0,"The total number of generated candidates (in del. p.): %d",
00103 PARENT::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, class LEAF, class LEAF_ALLOCATOR>
00109 void CandGenInfreqRemoveNopruneMerge<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::
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 PARENT::df_decoder.pushItem( (*itEdge).first );
00120 delete_infrequent_subtrie( static_cast<TRIE*>((*itEdge).second), min_supp,
00121 step_to_cand_par);
00122 PARENT::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<LEAF*>((*itEdge).second)->getCounter() < min_supp )
00136 {
00137 #if DEBUG_LEVEL >= LEVEL_DBG
00138 ++nr_of_deleted;
00139 #endif
00140 PARENT::s_alloc.free(static_cast<LEAF*>((*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 }
00158 #endif