00001 #ifndef LeafRepresentationSelector_HPP
00002 #define LeafRepresentationSelector_HPP
00003
00004 #include "io/input/transaction_reader/SortedTransactionReader.hpp"
00005 #include "io/codec/coder/Coder.hpp"
00006 #include "io/db_cache/BuildTreeDBCache.hpp"
00007 #include "util/Frequent2Filter.cpp"
00008
00009 #include "common/allocators.hpp"
00010
00011
00012 #include "apriori/bodon/trie/trie_manipulators/FrequentItemInserter.hpp"
00013 #include "apriori/bodon/trie/trie_manipulators/FrequentPairInserter.hpp"
00014 #include "apriori/bodon/trie/trie_manipulators/FrequentPairInserterNoprune.hpp"
00015
00016 #include "apriori/bodon/trie/trie_manipulators/support_counter/SupportCounterMerge.hpp"
00017 #include "apriori/OneByOneSupportCounter.hpp"
00018
00019 #include "apriori/bodon/trie/trie_manipulators/CandidateGeneratorPrune.hpp"
00020 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/CandidateGeneratorPrune.hpp"
00021
00022 #include "apriori/bodon/trie/trie_manipulators/SimplePruner.hpp"
00023 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/SimplePruner.hpp"
00024
00025 #include "apriori/bodon/trie/trie_manipulators/IntersectProPruner.hpp"
00026 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/IntersectProPruner.hpp"
00027
00028 #include "apriori/bodon/trie/trie_manipulators/CandGenInfreqRemoveNopruneMerge.hpp"
00029 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/CandGenInfreqRemoveNopruneMerge.hpp"
00030
00031 #include "apriori/bodon/trie/trie_manipulators/InfreqRemover.hpp"
00032 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/InfreqRemover.hpp"
00033
00034 #include "apriori/Apriori.hpp"
00035
00036
00037
00038 template <class TRIE, class LEAF_WC, class LEAF_ALLOCATOR, class T_R, class DF_D>
00039 class LeafRepresentationSelector
00040 {
00041 public:
00042 LeafRepresentationSelector(
00043 counter_t min_supp, char* input_file,
00044 counter_t nr_of_transactions,
00045 std::vector< std::pair<counter_t, item_t> >& freq_items_with_counters,
00046 T_R& tr_reader, DF_D& df_decoder);
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 template <class TRIE, class LEAF_WC, class LEAF_ALLOCATOR, class T_R, class DF_D>
00060 LeafRepresentationSelector<TRIE, LEAF_WC, LEAF_ALLOCATOR, T_R, DF_D>::
00061 LeafRepresentationSelector(
00062 counter_t min_supp, char* input_file,
00063 counter_t nr_of_transactions,
00064 std::vector< std::pair<counter_t, item_t> >& freq_items_with_counters,
00065 T_R& tr_reader, DF_D& df_decoder)
00066 {
00067 typedef typename bracz::BuildTreeDBCache< SortedTransactionReader<Coder<T_R, DF_D> >,
00068 std::vector<item_t>, bracz::EndPatriciaBuildTree<true> > S_C;
00069
00070
00071 typename S_C::params_t par_c;
00072 par_c.file_name = input_file;
00073 par_c.mode=FileReprBase::READ;
00074 par_c.largest_item = tr_reader.getLargestItem();
00075 par_c.decoder = &df_decoder;
00076 par_c.freq_items_with_counters = &freq_items_with_counters;
00077 par_c.codemode = ASC;
00078 log_status(0,"Doing sorted codec.");
00079 S_C sorted_coder(&par_c);
00080
00081 std::vector< std::pair<counter_t, std::pair<item_t, item_t> > >
00082 freq_pairs_with_counters;
00083 Frequent2Filter<S_C> fr_2_filter(
00084 &sorted_coder );
00085 log_status(0,"Finding frequent pairs.")
00086 fr_2_filter.findFrequentPairs(freq_pairs_with_counters, min_supp);
00087
00088 TRIE main_trie;
00089 LEAF_ALLOCATOR s_alloc;
00090 typedef Bodon::FrequentItemInserter<DF_D, TRIE, true> FII;
00091 FII fii(main_trie, df_decoder);
00092 typedef Bodon::SupportCounterMerge<TRIE> SUPP_C_BASE;
00093 typedef OneByOneSupportCounter<TRIE, S_C, SUPP_C_BASE> SUPP_C;
00094
00095
00096 log_info(0,"Complete pruning is disabled.");
00097 typedef Bodon::FrequentPairInserterNoprune<DF_D, TRIE, LEAF_WC, LEAF_ALLOCATOR, true> FPI;
00098 typedef Bodon::inhomogeneous_trie::CandGenInfreqRemoveNopruneMerge<DF_D, TRIE, LEAF_WC, LEAF_ALLOCATOR, true > CGIR;
00099 CGIR infrequent_remover(main_trie, df_decoder, s_alloc);
00100 typedef Apriori<S_C, DF_D, TRIE, LEAF_ALLOCATOR, FII, FPI, CGIR, CGIR, SUPP_C> A;
00101 A apriori(main_trie, s_alloc, infrequent_remover, sorted_coder, df_decoder, fii);
00102 log_status(0,"Finding frequent itemsets.")
00103 apriori.findFrequentItemsets(
00104 nr_of_transactions, *par_c.freq_counters,
00105 freq_pairs_with_counters, min_supp );
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #endif