Reinforcement Learning Toolbox 2.0
last updated:
General
Documentation
Manual
Tutorial
Class Reference
Master Thesis
Examples
Related Papers
Downloads
Links
News
mailto:webmaster
Main Page     Class Hierarchy   Compound List   File List   Compound Members   File Members

cfeaturefunction.h

Go to the documentation of this file.
00001 // Copyright (C) 2003
00002 // Gerhard Neumann (gneumann@gmx.net)
00003 // Stephan Neumann (sneumann@gmx.net) 
00004 //                
00005 // This file is part of RL Toolbox.
00006 // http://www.igi.tugraz.at/ril_toolbox
00007 //
00008 // All rights reserved.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions
00012 // are met:
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 // 2. Redistributions in binary form must reproduce the above copyright
00016 //    notice, this list of conditions and the following disclaimer in the
00017 //    documentation and/or other materials provided with the distribution.
00018 // 3. The name of the author may not be used to endorse or promote products
00019 //    derived from this software without specific prior written permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00024 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00026 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00030 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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