-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcausal_grammar_hallway.py
269 lines (268 loc) · 8.5 KB
/
causal_grammar_hallway.py
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
### HALLWAY GRAMMAR ###
#("node_type", "symbol_type", "symbol", probability, timeout, [children])
"""
abbreviated_hallway_grammar = [
("root", "fluent", "dooropen_on", .5, False, [
("leaf", "prev_fluent", "dooropen_on", .3, False, False),
("and", False, False, .7, False, [
("leaf", "prev_fluent", "dooropen_off", False, False, False),
("leaf", "event", "OpenDoor", False, False, False)
]
)
]
),
]
"""
# TODO: door and elevator weren't included in the experiments... can pull that data in
# NOTE: unsure of what to put in for probabilities -- using mostly False for now
### GRAMMAR FOR MINGTIAN'S HALLWAY -- NIPS 2012###
abbreviated_hallway_grammar = [
# LIGHT ON
("root", "fluent", "[LIGHT_ON]_on", .6, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "[LIGHT_ON]_on", False, False, False),
("leaf", "nonevent", "TOUCH_SWITCH_START", False, 10, False),
]
),
# ON CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "[LIGHT_ON]_off", False, False, False),
("leaf", "event", "TOUCH_SWITCH_START", False, 10, False),
]
)
]
),
# LIGHT OFF (LIGHT_ON_OFF)
("root", "fluent", "[LIGHT_ON]_off", .4, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "[LIGHT_ON]_off", False, False, False),
("leaf", "nonevent", "TOUCH_SWITCH_START", False, 10, False),
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "[LIGHT_ON]_on", False, False, False),
("leaf", "event", "TOUCH_SWITCH_START", False, 10, False),
]
)
]
),
# WATER STREAM ON
("root", "fluent", "WATER_STREAM_on", .4, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "WATER_STREAM_on", False, False, False),
("leaf", "nonevent", "[USE FOUNTAIN]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "WATER_STREAM_off", False, False, False),
("leaf", "event", "[USE FOUNTAIN]_START", False, 1, False),
]
)
]
),
# WATER STREAM OFF (WATERSTREAM_ON_OFF)
("root", "fluent", "WATER_STREAM_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "WATER_STREAM_off", False, False, False),
("leaf", "nonevent", "[USE FOUNTAIN]_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "WATER_STREAM_on", False, False, False),
("leaf", "event", "[USE FOUNTAIN]_END", False, 1, False)
]
)
]
),
# TRASH MORE
("root", "fluent", "TRASH_MORE_on", .4, False, [
# ON CAUSALLY (NEVER ON INERTIALLY)
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_MORE_on", False, False, False),
("leaf", "event", "[DROP TRASH]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_MORE_off", False, False, False),
("leaf", "event", "[DROP TRASH]_END", False, 1, False)
]
)
]
),
# TRASH MORE OFF (STAYS)
("root", "fluent", "TRASH_MORE_off", .6, False, [
# OFF INERTIALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_MORE_off", False, False, False),
("leaf", "nonevent", "[DROP TRASH]_END", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_MORE_on", False, False, False),
("leaf", "nonevent", "[DROP TRASH]_END", False, 1, False),
]
)
]
),
# TRASH LESS # NOTE: event described here never happens in XML
("root", "fluent", "TRASH_LESS_on", .4, False, [
# ON CAUSALLY (NEVER ON INERTIALLY)
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_LESS_on", False, False, False),
("leaf", "event", "[PICKUP TRASH]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_LESS_off", False, False, False),
("leaf", "event", "[PICKUP TRASH]_END", False, 1, False)
]
)
]
),
# TRASH LESS OFF (STAYS)
("root", "fluent", "TRASH_LESS_off", .6, False, [
# OFF INERTIALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_LESS_off", False, False, False),
("leaf", "nonevent", "[PICKUP TRASH]_END", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "TRASH_LESS_on", False, False, False),
("leaf", "nonevent", "[PICKUP TRASH]_END", False, 1, False),
]
)
]
),
# PHONE ACTIVE -- THIS IS NULL IN DB -- WHY? TODO -- maybe bad detections? -- probably ambiguity over whether or not the agent has a phone because i wasn't tracking agents
("root", "fluent", "PHONE_ACTIVE_on", .4, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_on", False, False, False),
("leaf", "nonevent", "[USE CELLPHONE]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_off", False, False, False),
("leaf", "event", "[USE CELLPHONE]_START", False, 1, False),
]
)
]
),
# PHONE STANDBY (PHONE_ACTIVE_OFF)
("root", "fluent", "PHONE_ACTIVE_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_off", False, False, False),
("leaf", "nonevent", "[USE CELLPHONE]_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_on", False, False, False),
("leaf", "event", "[USE CELLPHONE]_END", False, 1, False)
]
)
]
),
# AGENT THIRSTY
("root", "fluent", "AGENT_THIRST_on", .4, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "AGENT_THIRST_on", False, False, False),
("leaf", "nonevent", "[USE FOUNTAIN]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "AGENT_THIRST_off", False, False, False),
("leaf", "event", "[USE FOUNTAIN]_START", False, 1, False), # added to force the issue
# TODO: this is the timer one... unsure of how to put it... (not an action, but...)
]
)
]
),
# AGENT SATIATED (AGENT_THIRSTY_OFF)
("root", "fluent", "AGENT_THIRST_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "AGENT_THIRST_off", False, False, False),
# TODO: Timer for on causally
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "AGENT_THIRST_on", False, False, False),
("leaf", "event", "[USE FOUNTAIN]_END", False, 1, False)
]
)
]
),
# AGENT HAS TRASH # NOTE: EVENT [REMOVE TRASH] NEVER REALIZED!
# TODO: This is one of the ones that needs the "reset agent" feature
("root", "fluent", "AGENT_HAS_TRASH_on", False, False, [
# ON INERTIALLY
("and", False, False, .5, False, [
("leaf", "prev_fluent", "AGENT_HAS_TRASH_on", False, False, False),
("leaf", "nonevent", "[USE TRASH CAN]_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .5, False, [
("leaf", "prev_fluent", "AGENT_HAS_TRASH_off", False, False, False),
("leaf", "event", "[REMOVE TRASH]_START", False, 1, False),
]
)
]
),
# AGENT DOESN"T HAVE TRASH (AGENT_TRASH_OFF)
("root", "fluent", "AGENT_HAS_TRASH_off", False, False, [
# OFF INERTIALLY
("and", False, False, .5, False, [
("leaf", "prev_fluent", "AGENT_HAS_TRASH_off", False, False, False),
("leaf", "nonevent", "[REMOVE TRASH]_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .5, False, [
("leaf", "prev_fluent", "AGENT_HAS_TRASH_on", False, False, False),
("leaf", "event", "[USE TRASH CAN]_END", False, 1, False)
]
)
]
),
]
"""
### NOT INCLUDED ###
# DOOR OPEN
("root", "fluent", "DOOR_OPEN_on", False, False, [
# inertially ON
("and", False, False, .6, False, [
("leaf", "prev_fluent", "DOOR_OPEN_on", False, False, False),
("leaf", "nonevent", "@TODO@", False, 10, False), # TODO: non-action
]
),
# causally ON (open door inside) # TODO
]
),
# DOOR CLOSED (DOOR OPEN OFF) # TODO
# ELEVATOR DOOR OPEN # TODO
# ELEVATOR DOOR CLOSED # TODO
# PHONE RINGING #
# PHONE NOT RINGING (PHONE_RINGING_OFF)
# AGENT HAS PHONE/NOT
"""
import causal_grammar
causal_forest = causal_grammar.generate_causal_forest_from_abbreviated_forest(abbreviated_hallway_grammar)