/
ReinforcementPictures.h
124 lines (81 loc) · 3.02 KB
/
ReinforcementPictures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef whiteice_ReinforcementPictures_h
#define whiteice_ReinforcementPictures_h
#include "ts_measure.h"
#include "DataSource.h"
#include <dinrhiw.h>
#include <vector>
#include <thread>
#include <mutex>
#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
namespace whiteice
{
template <typename T>
class ReinforcementPictures : public whiteice::RIFL_abstract<T>
{
public:
ReinforcementPictures(const DataSource* dev,
const whiteice::HMM& hmm,
const whiteice::KMeans< T >& clusters,
const whiteice::bayesian_nnetwork<T>& rmodel,
const std::vector<std::string>& pictures,
const unsigned int DISPLAYTIME,
const std::vector<double>& target,
const std::vector<double>& targetVar);
~ReinforcementPictures();
bool getKeypress();
bool getESCKeypress();
bool getDisplayIsRunning();
bool getInitialized(); // return true when we are in main display loop and all things are set properly
// if set true use reinforcement model (nnetwork<T>) as reinforcement values..
void setReinforcementModel(bool useModel);
// sets random mode (if true) instead of showing the best pic,
// displays randomly chosen pic while doing all the calculations etc.
void setRandom(bool r);
// sets message that will be shown on the screen
void setMessage(const std::string& msg);
protected:
const DataSource* dev;
whiteice::HMM hmm;
whiteice::KMeans< T > clusters;
whiteice::bayesian_nnetwork<T> rmodel;
std::vector<std::string> pictures;
unsigned int DISPLAYTIME;
unsigned int currentHMMstate;
// if true use rmodel, otherwise minimize distance ~ ||newstate - target||^2
bool useReinforcementModel;
std::vector<double> target;
std::vector<double> targetVar;
bool random; // random mode for comparing effects to user
whiteice::RNG<T> rng;
std::string fontname;
std::string message;
virtual bool getState(whiteice::math::vertex<T>& state);
virtual bool performAction(const unsigned int action,
whiteice::math::vertex<T>& newstate,
T& reinforcement);
virtual bool getActionFeature(const unsigned int action,
whiteice::math::vertex<T>& feature) const;
// helper function to create feature vector f (mini pic) from image
void calculateFeatureVector(SDL_Surface* pic,
whiteice::math::vertex<T>& f) const;
std::vector< whiteice::math::vertex<T> > actionFeatures;
std::list<T> distances;
std::list<unsigned int> actionQueue;
std::mutex actionMutex;
std::list<unsigned int> performedActionsQueue;
std::mutex performedActionsMutex;
volatile bool running;
std::thread* display_thread;
std::mutex display_mutex;
unsigned int keypresses;
unsigned int esc_keypresses;
bool initialized;
void displayLoop();
};
extern template class ReinforcementPictures< math::blas_real<float> >;
extern template class ReinforcementPictures< math::blas_real<double> >;
};
#endif