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

IndexedReal.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  *
00003  * Original source copyright (c) 2000, Carnegie Mellon University.  
00004  * See copyright.cmu for details.
00005  * Modifications copyright (c) 2002, University of Massachusetts.
00006  * See copyright.umass for details.
00007  *
00008  *==========================================================================
00009  */
00010 
00011 
00012 #ifndef _INDEXEDREAL_HPP
00013 #define _INDEXEDREAL_HPP
00014 
00015 #include "common_headers.hpp"
00016 #include <algorithm>
00017 
00018 namespace lemur 
00019 {
00020   namespace api 
00021   {
00022     
00024 
00037     // CLASSES: IndexedReal, IndexedRealVector (C. Zhai, 12/1/2000)
00038     // Normalize and LogToPosterior (added dmf, 09/2002)
00039 
00040     struct IndexedReal {
00041       int ind;
00042       double val;
00043     };
00044 
00047     class IndexedRealVector : public vector<IndexedReal> {
00048     public:
00049   
00050       IndexedRealVector() : vector<IndexedReal>() {}
00051       IndexedRealVector(int size) : vector<IndexedReal>(size) {}
00052       virtual ~IndexedRealVector() {}
00053       virtual iterator FindByIndex(int index);
00054 
00056       // return true iff the entry already exists.
00057       virtual bool IncreaseValueFor(int index, double value);
00058 
00060       virtual void PushValue(int index, double value);
00061 
00063       virtual void Sort(bool descending = true);
00064 
00066       virtual void NormalizeValues();
00067 
00070       virtual void LogToPosterior();
00071 
00072 
00073     private:
00074 
00077 
00078       class IndexedRealAscending {
00079       public:
00080         bool operator()(const IndexedReal & a, const IndexedReal & b) {
00081           if (a.val != b.val)
00082             return a.val < b.val;  // based on the real value
00083           return a.ind < b.ind;
00084         }
00085       };
00086 
00087       class IndexedRealDescending { 
00088       public: 
00089         bool operator()(const IndexedReal & a, const IndexedReal & b) {
00090           if (a.val != b.val)
00091             return a.val > b.val;  // based on the real value
00092           return a.ind > b.ind;
00093         }
00094       };
00095 
00096       static IndexedRealAscending ascendOrder;
00097       static IndexedRealDescending descendOrder;
00098 
00099     };
00100   }
00101 }
00102 #endif //_INDEXEDREAL_HPP

Generated on Tue Jun 15 11:02:54 2010 for Lemur by doxygen 1.3.4