Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
HPosMiner.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 
00031 #ifndef HPOSMINER_H
00032 #define HPOSMINER_H
00033 
00034 // ---------------------------- Internal Headers ---------------------------- //
00035 
00036 #include "HLevItemSetMap.h"
00037 #include "LevelwiseMiner.h"
00038 
00039 struct hassoc
00040 {
00041     int code;
00042     unsigned int count;
00043 };
00044 
00045 typedef map<ItemSet, struct hassoc> i_hmap;
00046 typedef i_hmap::iterator hm_iter;
00047 typedef i_hmap::const_iterator hm_citer;
00048 
00055 class HPosMiner: public LevelwiseMiner
00056 {
00057     protected:
00058         // Used for giving status messages
00059         unsigned int current;
00060 
00061         // The fraction of the rows that must comprise each bitpattern
00062         float balance;
00063 
00064         // The required number of occurances for each bitpattern
00065         unsigned int bpreq;
00066 
00067         // This is twice the required number of occurances for each bitpattern
00068         // it may seems redundant, but it is nice to not have to compute this
00069         // value, as it is useful in early termination
00070         unsigned int bpreq2;
00071 
00072         // The fraction of bitpatterns that must succeed
00073         float support;
00074 
00075         // The buffer of combinations.  Prevents using too much memory.
00076         vector<ItemSet> buffer;
00077 
00078         // The buffer size
00079         unsigned int buffer_size;
00080 
00081         // The previously mined item sets
00082         LevItemSetMap<struct hassoc> keepSets;
00083 
00084         // Helper methods
00085         void analyzeHelper();
00086         virtual bool analyzeLevel(unsigned int level);
00087         virtual void analyzeFirstLevel();
00088         virtual void analyzeNewLevel(unsigned int level);
00089         virtual void countTable(unsigned int level, unsigned int length);
00090         virtual bool hasMatches(hm_citer i, hm_citer j, unsigned int level);
00091         virtual void pruneItemSets(const vector<unsigned int>& tallies,
00092             unsigned int level);
00093         virtual unsigned int handlePrinting(unsigned int level);
00094         virtual void analyzeItemSet(const ItemSet& is,
00095             const ItemSet& ispos, const ItemSet& isneg, unsigned int& penalty,
00096             unsigned int& success) const;
00097         virtual void analyzeItemSet(const ItemSet& is, unsigned int& penalty,
00098             unsigned int& success) const;
00099         int gensupp(const ItemSet& ispos, const ItemSet& isneg,
00100             unsigned int start) const;
00101         void setcode(const ItemSet& is, unsigned int code);
00102         void setcode(unsigned int code);
00103 
00104     public:
00105         HPosMiner(float balance = 0.5, float support = 1.0,
00106             unsigned int buffer_size = 1000);
00107         HPosMiner(const HPosMiner& src);
00108         virtual ~HPosMiner();
00109         virtual HPosMiner& operator =(const HPosMiner& rhs);
00110 };
00111 
00112 #endif
 All Classes Functions Variables Typedefs Friends