Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
PosLattice.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 POSLATTICE_H
00032 #define POSLATTICE_H
00033 
00034 // ---------------------------- Internal Headers ---------------------------- //
00035 
00036 #include "Evaluator.h"
00037 #include "ItemsetLevel.h"
00038 #include "Lattice.h"
00039 #include "BinaryMatrix.h"
00040 
00048 class PosLattice: public Lattice
00049 {
00050     protected:
00051         // We need this to associate with each itemset
00052         struct assoc
00053         {
00054             unsigned int count;
00055             //unsigned int lowerBound;
00056             unsigned int upperBound;
00057 
00058             // This is if we could *potentially* be on the positive border
00059             bool positiveBorder;
00060         };
00061 
00062         // This is the ordered vector of the sets
00063         vector<ItemsetLevel<struct assoc> > levels;
00064 
00065         // This is the truth matrix
00066         BinaryMatrix* bm;
00067 
00068         // This is the evaluation buffer
00069         vector<Itemset*> cBuffer;
00070 
00071         // The evaluator
00072         Evaluator* evaluator;
00073 
00074         // Whether or not we have to worry about things coming in order
00075         bool order;
00076 
00077         // The target level for generating candidates
00078         unsigned int targetCandidate;
00079 
00080         // The lower level for generating candidates
00081         unsigned int lowerCandidate;
00082 
00083         // The target level
00084         unsigned int kCandidate;
00085 
00086         // The rotor for generating candidates
00087         vector<unsigned int> candidateRotor;
00088 
00089         // The next candidate
00090         Itemset* nextCandidate;
00091 
00092         // The position in the buffer
00093         unsigned int cBufferPos;
00094 
00095         // The itemsets in the buffer that need to be evaluated in addition
00096         // to being counted
00097         vector<Itemset*> eBuffer;
00098 
00099         // The possition in the ebuffer
00100         unsigned int eBufferPos;
00101 
00102         // The position on the positive border
00103         unsigned int borderPos;
00104 
00105         // The level at which we are getting positive borders
00106         unsigned int borderLevel;
00107 
00108         // The number of successful itemsets at each level
00109         vector<unsigned int> successful;
00110 
00111         // The maximum level we could attain during a certain analysis
00112         unsigned int maxlev;
00113 
00114         // Helper methods
00115 
00116         // Candidiate stuff
00117         virtual void generateCandidatesNonzero();
00118         virtual void generateCandidatesZero();
00119         virtual void candidateRotate();
00120         virtual void candidateRotateZero();
00121         virtual void candidateRotorStart(unsigned int pos);
00122         virtual void candidateRotorStartZero(unsigned int pos);
00123         virtual bool testCandidateRotor(unsigned int pos);
00124         virtual bool testCandidateRotorZero(unsigned int pos);
00125         virtual void createCandidate();
00126         virtual void candidateTick(unsigned int pos);
00127         virtual bool badCandidateRotor(unsigned int pos) const;
00128         virtual bool createCandidateRotate(vector<unsigned int>& rotorPool,
00129             vector<unsigned int>& isRotor);
00130         virtual bool testCreateCandidateRotor(vector<unsigned int>& isRotor,
00131             vector<unsigned int>& rotorPool, unsigned int pos, bool& success);
00132         virtual bool createCandidateRotorStart(vector<unsigned int>& isRotor,
00133             vector<unsigned int>& rotorPool, unsigned int pos);
00134 
00135         // Evaluation stuff
00136         virtual void countSubsets(Itemset* is);
00137         virtual void flushCountBuffer();
00138         virtual void countSets(const vector<Itemset*>& sets, unsigned int size);
00139         virtual void getRowSetCounts(const Itemset* is,
00140             vector<unsigned int>& counts) /*const*/;
00141         virtual void makeNotPositiveSubsets(const Itemset* is);
00142         virtual int generateSupport(const Itemset& pos, const Itemset& neg,
00143             unsigned int start) /*const*/;
00144         virtual void generateSupports(const Itemset& is, const Itemset& pos,
00145             const Itemset& neg, vector<unsigned int>& counts) /*const*/;
00146 
00147     public:
00148         PosLattice(BinaryMatrix* bm = NULL, unsigned int bufferSize = 1000,
00149             Evaluator* evaluator = NULL, bool order = false);
00150         PosLattice(const PosLattice& src);
00151         virtual ~PosLattice();
00152         virtual PosLattice& operator =(const PosLattice& rhs);
00153         virtual void setBinaryMatrix(BinaryMatrix* bm);
00154         virtual void generateCandidates(unsigned int level);
00155         virtual void generateCandidates(unsigned int level, unsigned int k);
00156         virtual bool hasNextCandidate() const;
00157         virtual Itemset* getNextCandidate();
00158         virtual void evaluateItemset(Itemset* is);
00159         virtual void flushEvaluationBuffer();
00160         virtual unsigned int getUpperBound() const;
00161         virtual void setEvaluator(Evaluator* evaluator);
00162         virtual void setBufferSize(unsigned int bufferSize);
00163         virtual unsigned int analyzeLevel(unsigned int level);
00164         virtual unsigned int analyzeLevel(unsigned int level, double& status);
00165         virtual unsigned int analyzeLevel(unsigned int level, unsigned int k);
00166         virtual unsigned int analyzeLevel(unsigned int level, unsigned int k,
00167             double& status);
00168         virtual bool isEmpty(unsigned int level) const;
00169         virtual unsigned int getSize() const;
00170         virtual unsigned int getSize(unsigned int level) const;
00171         virtual unsigned int getSuccessful(unsigned int level) const;
00172         virtual const Itemset* getItemset(unsigned int level,
00173             unsigned int index) const;
00174         virtual const Itemset* getItemset(unsigned int level,
00175             unsigned int index, unsigned int& upperBound) const;
00176         virtual void generatePositiveBorder(unsigned int level);
00177         virtual bool hasNextPositiveBorder() const;
00178         virtual const Itemset* getNextPositiveBorder();
00179         virtual void destroy();
00180         virtual unsigned int getWidth() const;
00181 };
00182 
00183 #endif
 All Classes Functions Variables Typedefs Friends