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
#ifndef CMAC_H
#define CMAC_H
#include <cmath>
#include "FuncApprox.h"
#include "tiles2.h"
#define RL_MEMORY_SIZE 1048576
#define RL_MAX_NONZERO_TRACES 100000
#define RL_MAX_NUM_TILINGS 6000
class CMAC: public FunctionApproximator{
protected:
int tiles[MAX_ACTIONS][RL_MAX_NUM_TILINGS];
double minimumTrace;
int nonzeroTraces[RL_MAX_NONZERO_TRACES];
int numNonzeroTraces;
int nonzeroTracesInverse[RL_MEMORY_SIZE];
double ranges[MAX_STATE_VARS];
double minValues[MAX_STATE_VARS];
double resolutions[MAX_STATE_VARS];
double weights[RL_MEMORY_SIZE];
double traces [RL_MEMORY_SIZE];
int numTilings;
collision_table *colTab;
void clearTrace(int f);
void clearExistentTrace(int f, int loc);
void setTrace(int f, double newTraceValue);
void updateTrace(int f, double deltaTraceValue);
void increaseMinTrace();
void reset();
void loadTiles();
double getRange(int i);
double getMinValue(int i);
double getResolution(int i);
public:
CMAC(int numF, int numA, double r[], double m[], double res[]);
void copyWeights(CMAC*);
void setState(double s[]);
void updateWeights(double delta, double alpha);
void decayTraces(double decayRate);
void read (char *fileName);
void write(char *fileName);
//Not implemented by CMAC
int getNumWeights();
void getWeights(double w[]);
void setWeights(double w[]);
double computeQ(int action);
void clearTraces(int action);
void updateTraces(int action);
};
#endif