-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathController.py
More file actions
40 lines (33 loc) · 1.4 KB
/
Copy pathController.py
File metadata and controls
40 lines (33 loc) · 1.4 KB
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
from pybrain.rl.learners.valuebased.interface import ActionValueTable
from scipy import where
from random import choice
class Match3ActionValueTable(ActionValueTable):
#ActionValueTable inherts from Table and ActionValueInterface
#A Table is a Module
""" A special table that is used for Value Estimation methods
in Reinforcement Learning. This table is used for value-based
TD algorithms like Q or SARSA.
"""
def getMaxAction(self,state):
#state is environment
'''
Return the action with the maximal value for the given state.
This is a slightly modified form of ActionValueTable.getMaxAction.
Method inherited from Pybrain.ActionValueTable
'''
values = self.params.reshape(self.numRows, self.numColumns)[int(state), :].flatten()
self.maxvalue = max(values)
action = where(values == self.maxvalue)[0]
action = choice(action)
return action
def getUnexploredAction(self,state,value=1.0,default=[0]):
#state is environment
'''
Return an action with a value equal to the given one
'''
values = self.params.reshape(self.numRows, self.numColumns)[int(state), :].flatten()
action = where(values == value)[0]
if default[0] in action or len(action) == 0:
return default[0]
action = choice(action)
return action