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

cparameters.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 
00033 #ifndef C_PARAMETERS__H
00034 #define C_PARAMETERS__H
00035 
00036 #include <time.h>
00037 #include <stdio.h>
00038 
00039 #include <map>
00040 #include <list>
00041 #include <string>
00042 #include <iostream>
00043 #include <utility>
00044 
00045 #define LINEAR 1
00046 #define SQUARE 2
00047 #define LOG     3
00048 #define FRACT 4
00049 #define FRACTSQUARE 5
00050 #define FRACTLOG 6
00051 #define EXP 7
00052 
00053 using namespace std;
00054 
00055 class CAdaptiveParameterCalculator;
00056 
00057 
00059 
00074 class CParameters
00075 {
00076 protected:
00077         std::map<string, double> *parameters;
00078         std::map<string, bool> *isAdaptive;
00079 public:
00081         CParameters();
00082 
00084         CParameters(CParameters &copy);
00085 
00086         virtual ~CParameters();
00087 
00088         bool containsParameters(CParameters *parameters);
00089                 
00090         void loadParameters(FILE *stream);
00091         void saveParameters(FILE *stream);
00092 
00093         void loadParametersStream(istream *stream);
00094         void saveParametersStream(ostream *stream);
00095 
00097 
00100         void saveParametersXML(FILE *stream);
00102         void loadParametersXML(FILE *stream);
00103 
00105 
00108         virtual void addParameter(string name, double value);
00109 
00111         virtual void addParameters(CParameters *parameters);
00112 
00114         virtual void removeParameter(string name);
00115 
00117 
00120         virtual double getParameter(string name);
00121         
00123 
00126         virtual void setParameter(string name, double value);
00127         
00129         virtual void setParameters(CParameters *parameters);
00130 
00132         double getParameterFromIndex(unsigned int index);
00134         string getParameterName(unsigned int index);
00136         void setParameterWithIndex(unsigned int index, double value);
00137 
00139         int getParameterIndex(string name);
00140 
00141         int getNumParameters();
00142 
00143         void setAsAdaptiveParameter(string parameter, bool adaptive);
00144         bool isAdaptiveParameter(string parameter);
00145         
00147         virtual bool operator == (CParameters &parameters);
00149         bool operator < (CParameters &paramters);
00150 };
00151 
00153 
00161 class CParameterObject : public CParameters
00162 {
00163 protected:
00165         void parametersChanged();
00166         
00167 
00168         typedef std::pair<CParameterObject *, string> paramPair;
00169         
00170 //      std::map<string, CAdaptiveParameterCalculator *> *adaptiveParameters;
00171 
00172         std::list<paramPair> *parameterObjects;
00173 public:
00174         CParameterObject();
00175         virtual ~CParameterObject();
00176 
00178         virtual void onParametersChanged() {};
00179 
00181         virtual void setParameter(string name, double value);
00183         virtual void setParameters(CParameters *parameters);
00184 
00186 
00189         virtual void addParameters(CParameterObject *parameters, string prefix = "");
00190 
00192 
00195         //virtual void resetParameterCalculators();
00196 
00198 
00201         virtual double getParameter(string name);
00202 
00204 
00208         //virtual void addAdaptiveParameter(string name, CAdaptiveParameterCalculator *paramCalc);
00210 
00213         //virtual void removeAdaptiveParameter(string name);
00214 
00216         virtual bool operator == (CParameters &parameters);
00217 };
00218 
00220 
00235 class CAdaptiveParameterCalculator : virtual public CParameterObject
00236 {
00237 protected:
00239 //      double targetValue;
00240 
00242 
00245         int functionKind;
00246 
00247         CParameters *targetObject;
00248         string targetParameter;
00249 public:
00250         CAdaptiveParameterCalculator(CParameters *targetObject, string targetParameter, int functionKind);
00251         virtual ~CAdaptiveParameterCalculator();
00252 
00254         virtual void setParameterValue(double value);
00255 
00257 
00260         virtual void resetCalculator() = 0;
00262         virtual void onParametersChanged();
00263 
00264 };
00265 
00267 
00289 class CAdaptiveParameterBoundedValuesCalculator : public CAdaptiveParameterCalculator
00290 {
00291 protected:
00292         double targetMin;
00293         double targetMax;
00294 
00295         double targetScale;
00296 
00297         double paramOffset;
00298         double paramScale;
00299 
00300         bool invertTarget;
00301 
00302 public:
00303         CAdaptiveParameterBoundedValuesCalculator(CParameters *targetObject, string targetParameter, int functionKind, double paramOffset, double paramScale, double targetMin, double targetMax);
00304         virtual ~CAdaptiveParameterBoundedValuesCalculator();
00305 
00307 //      virtual void resetCalculator();
00309         virtual void onParametersChanged();
00310 
00312 
00318         virtual void setParameterValue(double value);
00319 
00320 };
00321 
00323 
00341 class CAdaptiveParameterUnBoundedValuesCalculator : public CAdaptiveParameterCalculator
00342 {
00343 protected:
00344         double targetOffset;
00345         double targetScale;
00346 
00347         double paramOffset;
00348         double paramScale;
00349 
00350         double paramLimit;
00351 
00352 public:
00353         CAdaptiveParameterUnBoundedValuesCalculator(CParameters *targetObject, string targetParameter, int functionKind, double param0, double paramScale, double targetOffset, double targetScale);
00354         virtual ~CAdaptiveParameterUnBoundedValuesCalculator();
00355 
00357         virtual void onParametersChanged();
00358 
00360 
00365         virtual void setParameterValue(double value);
00366 };
00367 
00368 
00369 #endif