classicreinforce.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CLASSICREINFORCE_H
00020 #define __CLASSICREINFORCE_H
00021
00022 #include <selforg/abstractcontroller.h>
00023
00024 #include <assert.h>
00025 #include <cmath>
00026
00027 #include <selforg/matrix.h>
00028 #include <selforg/noisegenerator.h>
00029 #include <selforg/qlearning.h>
00030
00031 typedef struct ClassicReinforceConf {
00032 unsigned short buffersize;
00033 int numContext;
00034 int reinforce_interval;
00035
00036 QLearning* qlearning;
00037 } ClassicReinforceConf;
00038
00039
00040
00041
00042
00043 class ClassicReinforce : public AbstractController {
00044
00045 public:
00046 ClassicReinforce(const ClassicReinforceConf& conf = getDefaultConf());
00047 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00048
00049 virtual ~ClassicReinforce();
00050
00051
00052 virtual int getSensorNumber() const { return number_sensors; }
00053
00054 virtual int getMotorNumber() const { return number_motors; }
00055
00056
00057
00058 virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00059
00060
00061 virtual void stepNoLearning(const sensor* , int number_sensors,
00062 motor* , int number_motors);
00063
00064
00065
00066
00067
00068
00069 void setManualControl(bool mControl, int action_ = 0);
00070
00071
00072
00073 virtual void notifyOnChange(const paramkey& key);
00074
00075
00076
00077 virtual bool store(FILE* f) const;
00078
00079 virtual bool restore(FILE* f);
00080
00081
00082 virtual std::list<iparamkey> getInternalParamNames() const;
00083 virtual std::list<iparamval> getInternalParams() const;
00084 virtual std::list<ILayer> getStructuralLayers() const;
00085 virtual std::list<IConnection> getStructuralConnections() const;
00086
00087 static ClassicReinforceConf getDefaultConf(){
00088 ClassicReinforceConf c;
00089 c.buffersize=10;
00090 c.numContext=0;
00091 c.reinforce_interval=10;
00092 c.qlearning=0;
00093 return c;
00094 }
00095
00096
00097 protected:
00098 unsigned short number_sensors;
00099 unsigned short number_motors;
00100
00101
00102 unsigned short buffersize;
00103 matrix::Matrix* x_buffer;
00104 matrix::Matrix* y_buffer;
00105 matrix::Matrix* x_context_buffer;
00106
00107 bool manualControl;
00108
00109 int action;
00110 int oldaction;
00111 int state;
00112 double reward;
00113 double oldreward;
00114
00115 ClassicReinforceConf conf;
00116 bool initialised;
00117 int t;
00118 int managementInterval;
00119
00120
00121 virtual int getStateNumber() = 0;
00122
00123
00124 virtual int calcState() = 0;
00125
00126
00127 virtual int getActionNumber() = 0;
00128
00129 virtual matrix::Matrix calcMotor(int action) = 0;
00130
00131
00132 virtual double calcReinforcement() = 0;
00133
00134
00135 void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay = 0);
00136
00137
00138 virtual void fillSensorBuffer(const sensor* x_, int number_sensors);
00139
00140 virtual void fillMotorBuffer(const motor* y_, int number_motors);
00141
00142
00143 virtual void management();
00144
00145 };
00146
00147 #endif