00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef C_FEATUREFUNCTION_H
00033 #define C_FEATUREFUNCTION_H
00034
00035 #include <stdio.h>
00036 #include <list>
00037 #include <map>
00038
00040
00042 class CFeature
00043 {
00044 public:
00045 CFeature();
00046 CFeature(unsigned int Index, double factor);
00047
00048 ~CFeature();
00049
00050
00051 unsigned int featureIndex;
00052 double factor;
00053 };
00054
00056
00063 class CFeatureList : protected std::list<CFeature *>
00064 {
00065 protected:
00066 std::list<CFeature *> *freeResources;
00067 std::list<CFeature *> *allResources;
00068 std::map<int, CFeature *> *featureMap;
00069 bool isSorted;
00070 bool sortAbs;
00071
00073
00076 CFeature *getFreeFeatureResource();
00077
00079 void sortFeature(CFeature *feature);
00080
00081
00082 public:
00083 typedef CFeatureList::iterator iterator;
00084 typedef CFeatureList::reverse_iterator reverse_iterator;
00085
00087
00090 CFeatureList(int initMemSize = 0, bool isSorted = false, bool sortAbs = false);
00091 ~CFeatureList();
00092
00094 CFeatureList::iterator getFeaturePos(unsigned int feature);
00095
00097
00101 void add(CFeature *feature);
00103 void add(CFeatureList *featureList, double factor = 1.0);
00105
00108 void set(int feature, double factor);
00109
00111 void multFactor(double factor);
00112
00114
00117 double multFeatureList(CFeatureList *featureList);
00118
00120 void addIndexOffset(int Offset);
00121
00123
00127 void update(int feature, double factor);
00128
00130 double getFeatureFactor(int featureIndex);
00132
00135 CFeature* getFeature(int featureIndex);
00136
00138 void remove(CFeature *feature);
00139 void remove(int feature);
00140
00142
00145 void clear();
00147 void clearAndDelete();
00148
00150 void saveASCII(FILE *stream);
00152 void loadASCII(FILE *stream);
00153
00155 void normalize();
00156
00158 double getLength();
00159
00160
00161 CFeatureList::iterator begin();
00162 CFeatureList::iterator end();
00163 CFeatureList::reverse_iterator rbegin();
00164 CFeatureList::reverse_iterator rend();
00165
00166 int size() {return std::list<CFeature *>::size();}
00167 };
00168
00169
00171
00173 class CFeatureFunction
00174 {
00175 protected:
00177 unsigned int numFeatures;
00179 double *features;
00180
00181 bool externFeatures;
00182
00183 public:
00185 CFeatureFunction(unsigned int numFeatures);
00186 CFeatureFunction(unsigned int numFeatures, double *features);
00187
00188 virtual ~CFeatureFunction();
00189
00191
00194 void randomInit(double min = -1.0, double max = 1.0);
00195
00196 void init(double value);
00197
00199
00201 void setFeature(CFeature *update, double value);
00203 void setFeature(unsigned int featureIndex, double value);
00205
00208 void setFeatureList(CFeatureList *updateList, double value);
00209
00211 void updateFeature(int feature, double difference);
00213
00215 void updateFeature(CFeature *update, double difference);
00217
00219 void updateFeatureList(CFeatureList *updateList, double value);
00220
00222 virtual double getFeature(unsigned int featureIndex);
00223
00225
00227 virtual double getFeatureList(CFeatureList *featureList);
00228
00229 virtual void saveFeatures(FILE *stream);
00230 virtual void loadFeatures(FILE *stream);
00231 virtual void printFeatures();
00232
00233 virtual unsigned int getNumFeatures();
00234
00235 void postProcessWeights(double mean, double std);
00236 };
00237
00238
00239 #endif
00240