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

Frequent2FilterOnline.cpp

Go to the documentation of this file.
00001 #ifndef Frequent2FilterOnline_CPP
00002 #define Frequent2FilterOnline_CPP
00003 
00008 #include "common.hpp"  
00009 #include <vector>
00010 //#include <iostream> //for tests
00011 
00016 template <class IT_R>
00017 class Frequent2FilterOnline
00018 {
00019    public:
00020       Frequent2FilterOnline<IT_R>(IT_R* it_r):
00021          it_r(it_r), largest_item(it_r->getLargestItem()) { }
00022 
00024       void findFrequentPairs(
00025          std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >& 
00026          freq_pairs_with_counters,
00027          counter_t min_supp);
00028 
00029 
00030    private:
00031       IT_R* it_r;
00032       const item_t largest_item;
00033 };
00034 
00042 template <class IT_R> inline void Frequent2FilterOnline<IT_R>::
00043 findFrequentPairs(
00044    std::vector< std::pair<counter_t, std::pair<item_t, item_t> > >& 
00045    freq_pairs_with_counters, counter_t min_supp)
00046 {
00047    std::vector< std::vector< std::pair<item_t, counter_t> > > temp_counter_array;
00048    temp_counter_array.reserve(largest_item);
00049    temp_counter_array.resize(largest_item);
00050 
00051    freq_pairs_with_counters.clear();
00052    it_r->rewind();
00053 
00054    std::vector<item_t> transaction;
00055    std::vector<item_t>::iterator it1, it2;
00056    std::vector< std::pair<item_t, counter_t> >::iterator it_row;
00057    counter_t counter;
00059    while( (counter = it_r->nextTransactionBIS( transaction )) != 0 )
00060    {      
00061       if( transaction.size() > 1)
00062       {
00063          for( it1 = transaction.begin(); it1 != transaction.end() - 1; ++it1)
00064          {
00065             it_row = temp_counter_array[*it1].begin();
00066             for( it2 = it1+1; it2 != transaction.end(); ++it2)
00067             {
00068                while( it_row != temp_counter_array[*it1].end() 
00069                       && (*it_row).first < *it2 )
00070                   ++it_row;
00071                if( it_row != temp_counter_array[*it1].end() &&
00072                   (*it_row).first == *it2)
00073                {
00074                   (*it_row).second += counter;
00075                   ++it_row;
00076                }
00077                else
00078                {
00079                   it_row = temp_counter_array[*it1].insert(
00080                      it_row, std::pair<item_t, counter_t>(*it2, counter) );
00081                   ++it_row;
00082                }
00083             }
00084          }
00085       }
00086    }
00088    item_t index1;
00089    std::pair<item_t, item_t> temp_pair;
00090    std::pair< counter_t, std::pair<item_t, item_t> > temp_pair2;
00091    for( index1 = 0; index1 < largest_item ; ++index1 )
00092    {
00093       for( it_row = temp_counter_array[index1].begin(); 
00094            it_row != temp_counter_array[index1].end(); ++it_row )
00095       {
00096          if( (*it_row).second >= min_supp )
00097          {
00098             temp_pair.first = index1;
00099             temp_pair.second = (*it_row).first;
00100             temp_pair2.first = (*it_row).second;
00101             temp_pair2.second = temp_pair;
00102             freq_pairs_with_counters.push_back(temp_pair2);
00103          }
00104       }
00105       temp_counter_array[index1].clear();
00106       std::vector< std::pair<item_t, counter_t> >().swap(temp_counter_array[index1]);   
00107       // temp_counter_array[index1] will never be used again!
00108    }
00109 }
00110 
00111 #endif

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