Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrandom.py
More file actions
Latest commit
71 lines (60 loc) · 2.76 KB
/
Copy pathrandom.py
File metadata and controls
71 lines (60 loc) · 2.76 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
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
from .baseimportOuterLoopController
fromrandomimportchoice
importcolorama
fromcoloramaimportFore, Back, Style
colorama.init(autoreset=True)
classRandom(OuterLoopController):
defnew_student(self, student_id, action_space=None, outer_loop_args=None):
'''
Initializes the controller to train a new agent.
'''
super().new_student(student_id, action_space, outer_loop_args)
self.reuse_problems=False
ifouter_loop_argsisnotNoneand'reuse_problems'inouter_loop_args:
self.reuse_problems=outer_loop_args['reuse_problems']
defupdate(self,step,reward,action_type):
'''
Called after every step in the problem to track performance,
which many policies use for deciding what problem to assign.
For the random controller, this just prints out and saves
the step type and correctness for debugging purposes.
'''
# Identify whether the agent is correct (positive reward when
# evaluating the agent's correctness) or incorrect (negative
# reward, or positive reward when the agent is asking for a
# hint).
if(action_type=="ATTEMPT"):
correctness=Back.GREEN+"correct"ifreward>0elseBack.RED+"incorrect"
else:
correctness=Back.BLUE+"example"
# Print out information about performance
print(Fore.CYAN+"RL_CONTROLLER UPDATE:",step, reward,correctness)
defnext_problem(self,student=None):
'''
Called when the apprentice learner agent needs a new
problem. Returns a dictionary that should
either be empty (signals the policy is done tutoring),
or have at least the key "question_file" indicating
which question the agent should do.
'''
if(len(self.action_space) >0):
# The random controller assigns every problem in the
# action space once, in random order.
nxt=choice(self.action_space)
ifnotself.reuse_problems:
self.action_space.remove(nxt)
returnnxt
elif(len(self.test_set) >0):
# Once there are no more problems in the action space,
# we have the agent solve the problems in the test_set.
nxt=self.test_set.pop(0)
# The line below tells the program that the agent shouldn't
# learn from its encounters in the current problem. If the
# agent asks for a hint, the step will be marked incorrect,
# but the result will be filled in to allow the agent to
# continue.
nxt["test_mode"] =True
returnnxt
else:
# Signal that the policy is done tutoring.
returnNone