-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpcomp_issues.py
More file actions
157 lines (123 loc) · 4.28 KB
/
Copy pathpcomp_issues.py
File metadata and controls
157 lines (123 loc) · 4.28 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# ACT-R tutorial unit7 task for investigating production
# compilation modeling issues.
import actr
actr.load_act_r_model("ACT-R:tutorial;unit7;production-compilation-issues-model.lisp")
val1 = ''
val2 = ''
responses = []
start_time = 0
times = []
exp_length = 0
task_over = True
task_state = None
window = None
result_matrix = [[["win","lose","draw","lose"],["win","lose","draw","lose"],["win","lose","draw","lose"],["lose","draw","win","lose"]],
[["win","lose","draw","lose"],["win","lose","draw","lose"],["lose","draw","win","lose"],["lose","draw","win","lose"]],
[["win","lose","draw","lose"],["win","lose","draw","lose"],["lose","draw","win","lose"],["lose","draw","win","lose"]],
[["win","lose","draw","lose"],["lose","draw","win","lose"],["lose","draw","win","lose"],["lose","draw","win","lose"]]]
def convert_key_to_index(key):
if key.lower() == 's':
return 0
if key.lower() == 'd':
return 1
if key.lower() == 'f':
return 2
else:
return 3
def respond_to_key_press (model,key):
global responses,task_over,times
if not(task_over):
if task_state == 'trial':
ri = convert_key_to_index(key)
r = result_matrix[val1][val2][ri]
responses.append(r)
times.append(actr.get_time() - start_time)
present_feedback(r)
elif key.lower() == 'space':
if len(responses) == exp_length:
task_over = True
else:
present_next_trial()
def present_feedback(result):
global task_state
task_state = 'feedback'
actr.clear_exp_window(window)
actr.add_text_to_exp_window(window, result, x=50, y=100)
def present_next_trial():
global task_state,start_time,val1,val2
task_state = 'trial'
actr.clear_exp_window(window)
val1 = actr.random(4)
val2 = actr.random(4)
actr.add_text_to_exp_window(window, str(val1), x=10, y=50)
actr.add_text_to_exp_window(window, str(val2), x=110, y=50)
start_time = actr.get_time()
def game_over():
return task_over
def trials(n=150,reset=True,output=True):
global responses,task_over,exp_length,window
if reset:
actr.reset()
window = actr.open_exp_window("Compilation task",visible=False)
times = []
responses = []
task_over = False
exp_length = n
present_next_trial()
actr.install_device(window)
actr.add_command('compilation-issues-response',respond_to_key_press,"Compilation issues key press response monitor")
actr.monitor_command('output-key','compilation-issues-response')
# Just run a long time to have the model perform the task
actr.run(20000)
actr.remove_command_monitor('output-key','compilation-issues-response')
actr.remove_command ('compilation-issues-response')
return analyze_results(output)
def game(n,show_games=False):
scores = [0]*15
times = [0]*15
for i in range(n):
r = trials(150,True,show_games)
scores = list(map(lambda x,y: x + y,scores,r[0]))
times = list(map(lambda x,y: x + y,times,r[1]))
print("Average Score of %d trials"%n)
for x in scores:
print("%4.2f "%(x / n),end="")
print()
print("Average Response times")
for x in times:
print("%4.2f "%(x / n / 1000.0),end="")
print()
def analyze_results(output):
global responses,times
r=[]
t=[]
if output:
print("Score")
while len(responses) > 0:
s = 0
c = 0
for i in range(min(10,len(responses))):
res = responses.pop(0)
if res == 'win':
s += 1
if res == 'lose':
s -= 1
c += 1
if output:
print(" %2d"%s,end="")
r.append(s)
if output:
print()
print("Average response times")
while len(times) > 0:
s = 0
c = 0
for i in range(min(10,len(times))):
s += times.pop(0)
c += 1
if output:
print("%4.2f "%(s / c / 1000.0),end="")
t.append(s/c)
if output:
print()
return[r,t]