Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
TreeMiner.h
00001 /**************************************************************************
00002  * Copyright (c) 2007 Clifford Conley Owens III                           *
00003  *                                                                        *
00004  * This file is part of Biorithm.                                         *
00005  *                                                                        *
00006  * Biorithm is free software: you can redistribute it and/or modify       *
00007  * it under the terms of the GNU General Public License as published by   *
00008  * the Free Software Foundation, either version 3 of the License, or      *
00009  * (at your option) any later version.                                    *
00010  *                                                                        *
00011  * Biorithm is distributed in the hope that it will be useful,            *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00014  * GNU General Public License for more details.                           *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00018  *                                                                        *
00019  **************************************************************************/
00020 
00032 #ifndef TREEMINER_H
00033 #define TREEMINER_H
00034 
00035 // ---------------------------- Internal Headers ---------------------------- //
00036 
00037 #include "ItemSetTree.h"
00038 #include "LevelwiseMiner.h"
00039 
00040 // ------------------------------- Definitions ------------------------------ //
00041 
00042 struct assoc
00043 {
00044     int code;
00045     unsigned int count;
00046 };
00047 
00054 class TreeMiner: public LevelwiseMiner
00055 {
00056     typedef ItemSetTree<struct assoc> atree;
00057 
00058     protected:
00059         // The fraction of the rows that must comprise each bitpattern
00060         float balance;
00061 
00062         // The required number of occurances for each bitpattern
00063         unsigned int bpreq;
00064 
00065         // This is twice the required number of occurances for each bitpattern
00066         // it may seems redundant, but it is nice to not have to compute this
00067         // value, as it is useful in early termination
00068         unsigned int bpreq2;
00069 
00070         // The fraction of bitpatterns that must succeed
00071         float support;
00072 
00073         // The buffer of combinations.  Prevents using too much memory.
00074         vector<ItemSet*> buffer;
00075 
00076         // The buffer size
00077         unsigned int buffer_size;
00078 
00079         // The previously mined item sets
00080         atree tree;
00081 
00082         // The current status
00083         unsigned int current;
00084 
00085         // The current level
00086         unsigned int level;
00087 
00088         // The level 1 position
00089         unsigned int level1pos;
00090 
00091         // Helper methods
00092         void analyzeHelper();
00093         virtual bool analyzeLevel(unsigned int level);
00094         virtual void countTable(unsigned int length);
00095         virtual void pruneItemSets(const vector<unsigned int>& tallies,
00096             unsigned int length);
00097         virtual unsigned int handlePrinting();
00098         virtual unsigned int generateCandidates(atree::ConstIterator& iter,
00099             atree::ConstIterator& jter);
00100         virtual bool hasMatches(const ItemSet& i, const ItemSet& j) const;
00101         virtual struct assoc getval(const ItemSet& is) const;
00102         virtual void setcode(const ItemSet& is, int code);
00103         virtual void setcode(int code);
00104         virtual void analyzeItemSet(const ItemSet& is,
00105             const ItemSet& ispos, const ItemSet& isneg, unsigned int& penalty,
00106             unsigned int& success) const;
00107         virtual void analyzeItemSet(const ItemSet& is, unsigned int& penalty,
00108         unsigned int& success) const;
00109         int gensupp(const ItemSet& ispos, const ItemSet& isneg,
00110             unsigned int start) const;
00111 
00112     public:
00113         TreeMiner(float balance = 0.5, float support = 1.0,
00114             unsigned int buffer_size = 1000);
00115         TreeMiner(const TreeMiner& src);
00116         virtual ~TreeMiner();
00117         virtual TreeMiner& operator =(const TreeMiner& rhs);
00118 };
00119 
00120 #endif
 All Classes Functions Variables Typedefs Friends