-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgaussian.cc
76 lines (62 loc) · 1.59 KB
/
gaussian.cc
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
/* Implementation dependencies */
#include <iostream>
#include <algorithm>
#include <cmath>
#include "gaussian.hh"
/*!
*
*/
Gaussian::Gaussian()
{
/* Initialize our initial state */
initialState.resize(stateDimension);
std::fill(initialState.begin(), initialState.end(), 0.0);
/* Create max and min state range */
maxStateRange.resize(stateDimension);
minStateRange.resize(stateDimension);
std::fill(minStateRange.begin(), minStateRange.end(), 0.0);
std::fill(maxStateRange.begin(), maxStateRange.end(), 0.0);
/* Create max and min action range */
maxActionRange.resize(actionDimension);
minActionRange.resize(actionDimension);
maxActionRange[0] = 1;
minActionRange[0] = 0;
maxActionRange[1] = 1;
minActionRange[1] = 0;
/* Create params */
mu.resize(actionDimension);
diag.resize(actionDimension);
mu[0] = 0.5;
mu[1] = 0.5;
diag[0] = 0.001;
diag[1] = 0.01;
}
/*!
*
*/
SARS *Gaussian::step(State s, Action a)
{
SARS *sars = new SARS(stateDimension, actionDimension);
sars->s = s;
sars->a = a;
sars->s_prime = s;
double det = 1.0;
for(unsigned int i=0; i<diag.size(); i++) {
det *= diag[i];
}
double temp = 0.0;
for(unsigned int i=0; i<diag.size(); i++) {
temp += (a[i] - mu[i]) * 1 / diag[i] * (a[i] - mu[i]);
}
//double reward = 1 / (pow((2*M_PI), actionDimension/2) * sqrt(det)) * exp(-0.5*temp);
double reward = exp(-0.5*temp);
reward += gsl_ran_flat(rng, -0.05, 0.05);
if(reward < 0.0) {
reward = 0.0;
} else if(reward > 1.0) {
reward = 1.0;
}
sars->reward = reward;
sars->terminal = false;
return sars;
}