Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ViewSubsampler.h

Go to the documentation of this file.
00001 
00035 #ifndef __VIEW_SUBSAMPLER_H__
00036 #define __VIEW_SUBSAMPLER_H__
00037 
00038 #include <DAG.h>
00039 #include <DAGDatabase.h> //for MatchInfo
00040 
00041 class LockFile
00042 {
00043         int fd; // lock file's descriptor
00044         String m_strFileName;
00045         bool m_bLocked; // 'true' if the lock creation was successful
00046         
00047 public:
00048         LockFile() { m_bLocked = false; }
00049         virtual ~LockFile() { Unlock(); }
00050         
00051         bool Lock(const char* szLockFileName, unsigned int nSleepTime);
00052         void Unlock();
00053 };
00054 
00055 struct VIEWWEIGHT
00056 {
00057         int nViewNumber;
00058         int nViewRankPos;
00059         double dVoteWeight;
00060         
00061         VIEWWEIGHT() { nViewNumber = nViewRankPos = 0; dVoteWeight = 0.0; }
00062 };
00063 
00064 struct OBJVIEWWEIGHT : public VIEWWEIGHT
00065 {
00066         String strObjName;
00067         
00068         void Set(String objname, const VIEWWEIGHT& vw)
00069         {
00070                 strObjName = objname;
00071                 nViewNumber = vw.nViewNumber;
00072                 nViewRankPos = vw.nViewRankPos;
00073                 dVoteWeight = vw.dVoteWeight;
00074         }
00075 };
00076 
00077 typedef SmartArray<VIEWWEIGHT> VWArray;
00078 typedef leda_d_array<leda_string, VWArray> ObjViewArray;
00079 
00080 class ViewSubsampler
00081 {
00082         struct Record
00083         {
00084                 int nIndexedWithKBest;
00085                 String strObjName;
00086                 VWArray bmviews; //<! Badly matched views
00087                 
00088                 Record() { nIndexedWithKBest = 0; }
00089                 Record(const Record& rhs) { operator=(rhs); }
00090                 
00091                 Record& operator=(const Record& rhs)
00092                 {
00093                         nIndexedWithKBest = rhs.nIndexedWithKBest;
00094                         strObjName = rhs.strObjName;
00095                         bmviews = rhs.bmviews;
00096                         return *this;
00097                 }
00098                 
00099                 istream& Read(istream& is)
00100                 {
00101                         is.read((char*)&nIndexedWithKBest, sizeof(nIndexedWithKBest));
00102                         strObjName.Read(is);
00103                         return bmviews.Read(is);
00104                 }
00105                 
00106                 ostream& Write(ostream& os) const
00107                 {
00108                         os.write((char*)&nIndexedWithKBest, sizeof(nIndexedWithKBest));
00109                         strObjName.Write(os);
00110                         return bmviews.Write(os);
00111                 }               
00112         };
00113         
00114         leda_list<Record> m_viewVotes;
00115         ObjViewArray m_rankedObjViews;
00116         
00117 public:
00118         
00119     void AddViewWeights(int nViewsPerObject, const DAG* pQueryDag,
00120                 const leda_array<MatchInfo>& matchList, const SmartArray<int>& neigViews, int kBest);
00121                 
00122         void SaveViewWeights(const char* szDataFileName);
00123 
00124         bool RetrieveViewWeights(const char* szDataFileName, int nViewsPerObject, bool bRankByObject);
00125         
00126         VIEWWEIGHT GetViewRank(String strObjName, int nViewNumber) const
00127         {
00128                 return m_rankedObjViews[(const char*)strObjName][nViewNumber - 1];
00129         }
00130         
00131         double CompVoteWeight(int nPos, int kBest) const;
00132         static SmartArray<int> RandomSubsampling(int nCurViewNum, int nNewViewNum);
00133 };
00134 
00135 #endif //__VIEW_SUBSAMPLER_H__
00136 

Generated on Sat Nov 13 11:21:26 2004 for Noisy DAG Matcher by doxygen1.2.18