00001 #ifndef VALUEITERATION_H
00002 #define VALUEITERATION_H
00003
00004 #include <qthread.h>
00005 #include "SimulationMainWindow.h"
00006 #include "NNetwork.h"
00007
00008
00012 class ValueIterationThread : public QObject, public QThread
00013 {
00014 Q_OBJECT
00015
00016 public:
00017 ValueIterationThread(int _x, int _y, double _r, int _g, int _iHidden, int _iHiddenNeurons);
00018 ~ValueIterationThread();
00019 void run();
00020 void setModusFromExtern (char _x);
00021 void setSpeed (int _g);
00022 char getModus ();
00023 void unlockMutex();
00024 void setFeedback(int _row, int _col, double _up, double _down, double _left, double _right);
00025 void setGamma (double _ra);
00026 void deactivateNet();
00027 void activateNet();
00028 void setViValue (int _row, int _col, double _value);
00029 void setNetworkParameters (int _max_epochs, int _iterations_between_report, double _desired_error, double _dEta, bool _auto_error_adjust, double _activation_stepness_hidden, double _activation_stepness_output, int _activation_function_hidden, int _activation_function_output);
00030
00031
00032 void setNetFeedback(int _row, int _col, int _up, int _down, int _left, int _right);
00033 void setTrainRandomValues(int _trainRandomValues);
00034
00035 private:
00036 double gamma;
00037 int iteration;
00038
00039
00040 void printMatrix();
00041 int getRandomAction();
00042 int newX(int action, int xOld);
00043 int newY(int action, int yOld);
00044 long double evaluate(int action, int _x, int _y);
00045 void setValues();
00046 void learn(int _speed, long double _rate);
00047 void setModus (char _x);
00048 int trainRandomValues;
00049 int *randomStates;
00050 bool auto_adjust_error;
00051
00052
00053 int getBestDirection(int x, int y);
00054 bool testBorders(int action, int _x, int _y);
00055
00056
00057 char in, in_ext;
00058 int scalX, scalY;
00059 int steps, speed;
00060 bool explored;
00061 QMutex *printMutex, *inputMutex;
00062
00063
00064 Network *network;
00065 bool netOn, calculatetrainValues;
00066 int iHiddenUnits, iHiddenLayers;
00067 NETWORKTRAININGRESULTS *network_training_result;
00068
00069 void initNet();
00070 void calculateTrainingValues();
00071 void coachNet();
00072
00073 bool skipNextPrintMatrix;
00074 int maxReward, minReward;
00075
00076
00077 signals:
00078 void emitValue(int _row, int _column, double _v, int _bestdirection);
00079 void debugOutput (QString _d);
00080 void emitNewNetworkError (double _newError);
00081 };
00082
00083
00084 #endif