-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhoo.cc
88 lines (70 loc) · 1.35 KB
/
hoo.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
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Code by Chris Mansley
*/
#include <iostream>
#include <cmath>
#include <limits>
#include "hoo.hh"
#include "node.hh"
/*
*
*/
HOO::HOO(Domain *d, Chopper *c) : domain(d), chopper(c), totalSamples(0)
{
/* Initialize random elements */
rng = gsl_rng_alloc(gsl_rng_taus);
gsl_rng_set(rng, rand());
/* Number of action dimensions */
numDim = domain->getActionDimension();
/* Initialize root of tree */
tree = new Node(this);
tree->rangeInit(chopper->minActionZero(), chopper->maxActionOne());
/* Initialize parameters using advice from paper */
v1 = sqrt(numDim)/2;
rho = 1/pow(2,numDim);
}
HOO::~HOO()
{
/* Delete all memory recursivly? */
tree->clear();
/* Delete root of tree */
delete tree;
/* Remove random number generator */
gsl_rng_free(rng);
}
/*
*
*/
void HOO::insertAction(Action a, double q)
{
/* Insert the action/value in tree*/
tree->insertValue(a, q);
totalSamples++;
/* Rebuild the B-values in the subtree */
tree->rebuildSubTree();
}
/*
*
*/
Action HOO::queryAction(bool greedy)
{
Action a;
tree->bestAction(a, greedy);
return a;
}
/*
*
*/
void HOO::clear()
{
tree->clear();
totalSamples = 0;
delete tree;
/* Initialize root of tree */
tree = new Node(this);
tree->rangeInit(chopper->minActionZero(), chopper->maxActionOne());
}
void HOO::print()
{
tree->print();
}