/
ReinforcementSounds.h
106 lines (69 loc) · 2.36 KB
/
ReinforcementSounds.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
#ifndef whiteice__ReinforcementSounds_h
#define whiteice__ReinforcementSounds_h
#include "DataSource.h"
#include <dinrhiw.h>
#include "SDLSoundSynthesis.h"
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
namespace whiteice
{
namespace resonanz
{
template <typename T>
class ReinforcementSounds : public whiteice::RIFL_abstract2<T>
{
public:
ReinforcementSounds(const DataSource* dev,
const whiteice::HMM& hmm,
const whiteice::KMeans< T >& clusters,
const whiteice::bayesian_nnetwork<T>& rmodel,
SoundSynthesis* synth,
const unsigned int PLAYTIME,
const std::vector<double>& target,
const std::vector<double>& targetVar);
~ReinforcementSounds();
bool getSoundIsActive();
// 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);
protected:
const DataSource* dev;
whiteice::HMM hmm;
whiteice::KMeans< T > clusters;
whiteice::bayesian_nnetwork<T> rmodel;
std::vector<std::string> pictures;
unsigned int PLAYTIME;
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;
virtual bool getState(whiteice::math::vertex<T>& state);
virtual bool performAction(const whiteice::math::vertex<T>& action,
whiteice::math::vertex<T>& newstate,
T& reinforcement);
SoundSynthesis* synth;
std::list<T> distances;
std::list< whiteice::math::vertex<T> > actionQueue;
std::mutex actionMutex;
std::condition_variable actionQueue_cond;
std::list< whiteice::math::vertex<T> > performedActionsQueue;
std::mutex performedActionsMutex;
std::condition_variable performedActionsQueue_cond;
volatile bool running;
std::thread* audio_thread;
std::mutex audio_mutex;
void audioLoop();
};
extern template class ReinforcementSounds< whiteice::math::blas_real<float> >;
extern template class ReinforcementSounds< whiteice::math::blas_real<double> >;
};
};
#endif