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

SparseBitmatrix_create.hpp

Go to the documentation of this file.
00001 
00006 #ifndef __SPARSEBITMATRIX_CREATE_HPP_
00007 #define __SPARSEBITMATRIX_CREATE_HPP_ t
00008 
00009 // #include "SparseBitmatrix.hpp"
00010 //#include "eclat/SparseBitmatrix_singleblock.hpp"
00011 #include "common/debug.hpp"
00012 
00013 // #include "io/input/transaction_reader/TransactionReader.hpp"
00014 // #include "common.hpp"
00015 
00016 #include <vector>
00017 
00018 typedef std::vector<std::pair<counter_t, item_t> > CounterItemPairs;
00019 
00026 template <class TRANSACTION_READER>
00027 SparseBitmatrix* createSparseItemTransactionIncidenceMatrix(TRANSACTION_READER& tdb, CounterItemPairs& freqItems) {
00028   SparseBitmatrix* iti = NULL;
00029 
00030   // 0. get frequencies of items in a simple array:
00031   int numItems = freqItems.size();
00032   int* itemFrequencies = new int[numItems];
00033   CounterItemPairs::iterator it_freqItems;
00034   int i = 0;
00035   for( it_freqItems = freqItems.begin(); it_freqItems != freqItems.end(); ++it_freqItems )
00036     itemFrequencies[i++] = it_freqItems->first; 
00037   // [lst 2005/05/04] this is correct as the index is the recoded item ID.
00038   // It should *NOT* be itemFrequencies[it_freqItems->second] = it_freqItems->first; 
00039 
00040   // 1. create matrix:
00041   iti = new SparseBitmatrix(numItems, itemFrequencies);
00042   // [lst 2005/05/04] We do not use custom row labels via 
00043   //   iti = new SparseBitmatrix(numItems, tdb->freqItems, tdb->encoding->itemByCode);
00044   // as the recoding is handeled by the I/O framework.  
00045   /*
00046   int** rows = iti->rows;
00047   */
00048 
00049   // 3. fill matrix:
00050   tdb.rewind();
00051   std::vector<item_t> transaction;
00052   std::vector<item_t>::iterator it_transaction;
00053   i = 0;
00054   while(tdb.nextTransactionBIS(transaction))
00055   {      
00056     for(it_transaction = transaction.begin(); it_transaction != transaction.end(); ++it_transaction) {
00057       int item = *it_transaction;
00058       iti->push_back(item, i);
00059     }
00060     i++;
00061   }
00062 
00063   delete[] itemFrequencies;
00064 
00065   return iti;
00066 }
00067 
00068 
00069 #endif

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