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 00016 00029 // CLASSES: IndexedReal, IndexedRealVector (C. Zhai, 12/1/2000) 00030 // Normalize and LogToPosterior (added dmf, 09/2002) 00031 00032 #include "common_headers.hpp" 00033 #include <algorithm> 00034 00035 struct IndexedReal { 00036 int ind; 00037 double val; 00038 }; 00039 00040 00041 class IndexedRealVector : public vector<IndexedReal> { 00042 public: 00043 00044 IndexedRealVector() : vector<IndexedReal>() {} 00045 IndexedRealVector(int size) : vector<IndexedReal>(size) {} 00046 virtual ~IndexedRealVector() {} 00047 virtual iterator FindByIndex(int index); 00048 00050 // return true iff the entry already exists. 00051 virtual bool IncreaseValueFor(int index, double value); 00052 00054 virtual void PushValue(int index, double value); 00055 00057 virtual void Sort(bool descending = true); 00058 00060 virtual void NormalizeValues(); 00061 00064 virtual void LogToPosterior(); 00065 00066 00067 private: 00068 00071 00072 class IndexedRealAscending { 00073 public: 00074 bool operator()(const IndexedReal & a, const IndexedReal & b) { 00075 return a.val < b.val; // based on the real value 00076 } 00077 }; 00078 00079 class IndexedRealDescending { 00080 public: 00081 bool operator()(const IndexedReal & a, const IndexedReal & b) { 00082 return a.val > b.val; // based on the real value 00083 } 00084 }; 00085 00086 static IndexedRealAscending ascendOrder; 00087 static IndexedRealDescending descendOrder; 00088 00089 }; 00090 00091 00092 00093 #endif //_INDEXEDREAL_HPP 00094 00095 00096 00097 00098