Go to the documentation of this file.00001
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
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
00045 vector<string> cIheader;
00046 vector<string> uIheader;
00047 vector<int> numCIValues;
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
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);
00064 void swapCIHeaders(int i, int j);
00065
00066 void write(std::ostream& out);
00067 string getInfo();
00068
00069
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
00080 void resetIterator();
00081 vector<int> getIterBegin();
00082 bool getNextCI(vector<int>& CI);
00083 bool getNext(SparseEntry& se);
00084 vector<int> getIterPosition();
00085 vector<SparseEntry>& getSparseEntries(vector<int> commonIndex);
00086 int size();
00087
00088
00089 private:
00090 SparseRow* table;
00091 int* mapIn;
00092 int* mapOut;
00093 size_t numOfRows;
00094 vector<int> position;
00095 int rowPosition;
00096
00097 int getTableIndex(vector<int>);
00098 vector<int> getCommonIndex(int);
00099 };
00100 #endif