SparseTable.h
Go to the documentation of this file.
00001 // written by png shao wei
00002 #ifndef SparseTable_H
00003 #define SparseTable_H
00004 
00005 #include <vector>
00006 #include <list>
00007 #include <algorithm>
00008 #include <iostream>
00009 #include <map>
00010 #include <assert.h>
00011 #include <sstream>
00012 #include "MObject.h"
00013 #include "SparseEntry.h"
00014 
00015 
00016 #define STATEFUNCTION 0
00017 #define OBSERVFUNCTION 1
00018 #define REWARDFUNCTION 2
00019 #define BELIEFFUNCTION 3
00020 #define TERMINALFUNCTION 4
00021 
00022 //#include <list>
00023 
00024 using namespace std;
00025 
00026 class SparseRow : public MObject
00027 {
00028     public:
00029         vector<SparseEntry> entries; 
00030         void sortEntries();
00031         double sumProbability();
00032         void removeZeroEntries();
00033         void removeRedundantEntries();
00034         static bool onlyZeroUI(SparseEntry e);
00035 };
00036 
00037 class SparseTable : public MObject
00038 {
00039     public:
00040         SparseTable(vector<string> cIheader, vector<string> uIheader, vector<int> numCIValues, vector<int> numUIvalues);        
00041         SparseTable(SparseTable& B);
00042         ~SparseTable();
00043 
00044         // Field variables
00045         vector<string> cIheader;
00046         vector<string> uIheader;
00047         vector<int> numCIValues; //do not mutate this two arrays, if not hashing will be wrong
00048         vector<int> numUIValues;
00049 
00050         void convertForUse();
00051         void sortEntries();
00052         void removeRedundant();
00053 
00054         void swapSparseColumns(int i, int j);
00055         vector<string> findIntersectingCI(SharedPointer<SparseTable> st);
00056         unsigned int findPosition(string word);
00057         bool containsCI(string word);
00058 
00059         // methods for creating sparse tables in the functions
00060         void add(vector<int> CI, SparseEntry se);
00061 
00062         bool errorInProbabilities(vector<vector<int> >& commonIndices, vector<double>& probs);
00063         bool checkNoMissingEntries(vector<int>& commonIndex);   //return index of first row with missing entry
00064         void swapCIHeaders(int i, int j);
00065 
00066         void write(std::ostream& out);
00067         string getInfo();
00068 
00069         // return a new Sparse Table from the two Sparse Tables
00070         static SharedPointer<SparseTable> join(SparseTable& A, SparseTable& B, int whichFunction);
00071         static SparseEntry mergeSparseEntry(SparseEntry& A, SparseEntry& B, int numCommonIndexes);
00072         
00073         static SharedPointer<SparseTable> joinHeader(SparseTable& A, SparseTable& B, int& numCommonIndexes);
00074         
00075 
00076         int getCIPosition(string str);
00077         SharedPointer<SparseTable> removeUnmatchedCI(int cIIndex, int uIIndex);
00078 
00079         //iterator and accessor functions
00080         void resetIterator();
00081         vector<int> getIterBegin();     //return the first CI
00082         bool getNextCI(vector<int>& CI);
00083         bool getNext(SparseEntry& se);
00084         vector<int> getIterPosition();  //return iterator position in common index form
00085         vector<SparseEntry>& getSparseEntries(vector<int> commonIndex);
00086         int size();
00087 
00088 
00089     private:
00090         SparseRow* table; //array of SparseRow
00091         int* mapIn; //array for mapping of common index ordering, from external ordering to internal ordering 
00092         int* mapOut; //array for mapping of common index ordering, from internal ordering to external ordering 
00093         size_t numOfRows;
00094         vector<int> position;   //iterator position;
00095         int rowPosition;
00096 
00097         int getTableIndex(vector<int>); //get index in table given the common indices
00098         vector<int> getCommonIndex(int);        //get common index given table index
00099 };
00100 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29