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

StatSupportCounterMerge.hpp

Go to the documentation of this file.
00001 #ifndef StatSupportCounterMerge_HPP
00002 #define StatSupportCounterMerge_HPP
00003 
00004 #include "common.hpp"
00005 #include <vector>
00006 #include "apriori/bodon/Leaf.hpp"
00007 //#include <cstdio>
00008 //#include <iterator>   //for test
00009 
00010 
00011 
00012 
00013 namespace Bodon
00014 {
00015    template <class TRIE, unsigned int THRESHOLD>
00016    class StatSupportCounterMerge
00017    {
00018       public:
00019          StatSupportCounterMerge( ){}
00020          ~StatSupportCounterMerge( );
00023          void findCandidates( TRIE* subtrie,
00024             std::vector<item_t>::const_iterator it_basket_upper_bound,
00025             std::vector<item_t>::const_iterator it_basket, 
00026             item_t step_to_candidate,
00027             const counter_t counter_incr );
00028       private:
00029          vector<unsigned int> trans_step_distribution;
00030          vector<unsigned int> edgelist_step_distribution;
00031 
00032    };
00033 
00034    template <class TRIE, unsigned int THRESHOLD> void 
00035    StatSupportCounterMerge<TRIE, THRESHOLD>::findCandidates( 
00036       TRIE* subtrie, std::vector<item_t>::const_iterator it_basket_upper_bound,
00037       std::vector<item_t>::const_iterator it_basket, 
00038       item_t step_to_candidate, const counter_t counter_incr )
00039    {
00040       unsigned int trans_step=0, edgelis_step=0;
00041       --step_to_candidate;
00042       typename TRIE::iterator it_edge(subtrie->edgelist.begin());
00043       while( it_edge != subtrie->edgelist.end() && 
00044              it_basket != it_basket_upper_bound )
00045       {
00046          if( (*it_edge).first < *it_basket)
00047          { 
00048             ++it_edge;
00049             ++edgelis_step;
00050          }
00051          else if( (*it_edge).first > *it_basket)
00052          { 
00053             ++it_basket;
00054             ++trans_step;
00055          }
00056          else
00057          {
00058             if(trans_step >= trans_step_distribution.size())
00059                trans_step_distribution.resize(trans_step + 1, 0);
00060             ++trans_step_distribution[trans_step];
00061             trans_step=1;
00062             if(edgelis_step >= edgelist_step_distribution.size())
00063                edgelist_step_distribution.resize(edgelis_step + 1, 0);
00064             ++edgelist_step_distribution[edgelis_step];
00065             edgelis_step=1;
00066 
00067             ++it_basket;
00068             if( step_to_candidate ) 
00069                findCandidates( static_cast<TRIE*>((*it_edge).second),
00070                                it_basket_upper_bound + 1, it_basket, 
00071                                step_to_candidate, counter_incr);
00072             else
00073                static_cast<Leaf*>((*it_edge).second)
00074                   ->increaseCounter( counter_incr);
00075             ++it_edge;
00076          }
00077       }
00078    }
00079    template <class TRIE, unsigned int THRESHOLD> 
00080    StatSupportCounterMerge<TRIE, THRESHOLD>::
00081    ~StatSupportCounterMerge()
00082    {
00083       unsigned int index, sum_of_matches=0, part_sum_of_matches=0;
00084       
00085       std::cout<<"The distribution of the steps between matches in the transactions:"<<std::endl;
00086       for(index=0; index <= trans_step_distribution.size(); ++index) 
00087       {
00088          std::cout<<index<<" "<<trans_step_distribution[index]<<std::endl;
00089          sum_of_matches += trans_step_distribution[index];
00090          if(index < THRESHOLD)
00091             part_sum_of_matches += trans_step_distribution[index];
00092       }
00093       std::cout<<"The sum of matches: "<<sum_of_matches<<std::endl;
00094       std::cout<<"The sum of matches within "<<THRESHOLD<< " steps: "<<part_sum_of_matches<<std::endl;
00095       std::cout<<"This threshold equals to the "<<static_cast<double>(part_sum_of_matches)/sum_of_matches<< "-quantile."<<std::endl;
00096 /*      std::cout<<"The distribution of the steps between matches in the edgelists:"<<std::endl;
00097       for(index=0; index <= edgelist_step_distribution.size(); ++index) 
00098       std::cout<<index<<": "<<edgelist_step_distribution[index]<<std::endl;*/
00099    }
00100 }
00101 #endif

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