-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcausal_grammar_summerdata.py
396 lines (391 loc) · 13.4 KB
/
causal_grammar_summerdata.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# This Python file uses the following encoding: utf-8
### SUMMERDATA GRAMMAR ###
#("node_type", "symbol_type", "symbol", probability, timeout, [children])
"""
abbreviated_xxx_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)
]
)
]
),
]
"""
# {door, light, screen} are only detectable fluents. So if it's not door, light, screen, it should be "random" for origdata. which means (tested) ~ we're setting to "random": trash {same, less, more}; phone {off_active, active_off, off, active}; cup {same, less, more}; thirst {not, thirsty, thirsty_not, not_thirsty}; waterstream {water_on, water_off};
detectable_fluents = ("door","light","screen",)
# NOTE: unsure of what to put in for probabilities -- using mostly False for now
### GRAMMAR FOR SUMMER DATA -- CVPR 2012 ###
from math import exp, pow
def weibull(t1, t2, lam, k):
return 1 - exp(pow(t1 / lam,k) - pow(t2 / lam, k))
abbreviated_summerdata_grammar = [
# AGENT THIRSTY
("root", "fluent", "thirst_on", .4, False, [ # TODO (amy): adjust probabilities to get good results
# ON INERTIALLY -- stay thirsty and don't complete drinking
("and", False, False, .5, False, [
("leaf", "prev_fluent", "thirst_on", False, False, False),
("leaf", "nonevent", "drink_END", False, 1, False),
]
),
# STAY ON SIGNALED - drinking signals that the person was thristy
("and", False, False, .1, False, [
("leaf", "prev_fluent", "thirst_on", False, False, False),
("leaf", "event", "drink_START", False, 1, False),
]
),
# ON SPONTANEOUSLY - fluent staying off timed out
("and", False, False, .4, False, [
("leaf", "prev_fluent", "thirst_off", False, False, False),
# node_type, symbol_type, symbol, probability, timeout, children
#("leaf", "jump", "become_thirsty", lambda t1, t2: weibull(t1,t2,600,1.5), False, False, "thirst_off"), # TODO: add "jump" for node type -- must be paired with "timer" node on other side
]
),
],
),
# AGENT SATIATED (AGENT_THIRSTY_OFF)
("root", "fluent", "thirst_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "thirst_off", False, False, False),
#("leaf", "timer", "become_thirsty", lambda t1, t2: weibull(t1,t2,600,1.5), False, False, "thirst_on"), # TODO: does this need a new node symbol?
# TODO: add "timer" for node type. where do i put the probability on the duration? put it in hte probability slot? also: how to handle unknown time when the scene starts this way?
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "thirst_on", False, False, False),
("leaf", "event", "drink_END", False, 1, False)
]
)
]
),
# cup MORE # TODO on updating db -- merge cup_MORE with cup_LESS for answering queries
("root", "fluent", "cup_MORE_on", .4, False, [
# ON CAUSALLY (NEVER ON INERTIALLY)
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_MORE_on", False, False, False),
("leaf", "event", "benddown_END", False, 1, False), # TODO (amy): maybe ONGOING?
]
),
# ON CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_MORE_off", False, False, False),
("leaf", "event", "benddown_END", False, 1, False) # TODO (amy): maybe ONGOING?
]
)
]
),
# cup MORE OFF (STAYS)
("root", "fluent", "cup_MORE_off", .6, False, [
# OFF INERTIALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_MORE_off", False, False, False),
("leaf", "nonevent", "benddown_END", False, 1, False), # TODO (amy): maybe ONGOING?
]
),
# OFF CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_MORE_on", False, False, False),
("leaf", "nonevent", "benddown_END", False, 1, False), # TODO (amy): maybe ONGOING?
]
)
]
),
# cup LESS
("root", "fluent", "cup_LESS_on", .4, False, [
# ON CAUSALLY (NEVER ON INERTIALLY)
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_LESS_on", False, False, False),
("leaf", "event", "drink_END", False, 1, False), # TODO (amy): maybe ONGOING?
]
),
# ON CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_LESS_off", False, False, False),
("leaf", "event", "drink_END", False, 1, False) # TODO (amy): maybe ONGOING?
]
)
]
),
# cup LESS OFF (STAYS)
("root", "fluent", "cup_LESS_off", .6, False, [
# OFF INERTIALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_LESS_off", False, False, False),
("leaf", "nonevent", "drink_END", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, False, False, [
("leaf", "prev_fluent", "cup_LESS_on", False, False, False),
("leaf", "nonevent", "drink_END", False, 1, False),
]
)
]
),
# WATER STREAM ON
("root", "fluent", "waterstream_on", .4, False, [
# ON INERTIALLY
("and", False, False, .01, False, [
("leaf", "prev_fluent", "waterstream_on", False, False, False),
("leaf", "nonevent", "benddown_END", False, 1, False), # or ONGOING? TODO -- or is this how we signal "ongoing"?
]
),
# ON CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "waterstream_off", False, False, False),
("leaf", "event", "benddown_START", False, 1, False),
]
)
]
),
# WATER STREAM OFF (waterstream_on_OFF)
("root", "fluent", "waterstream_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .01, False, [
("leaf", "prev_fluent", "waterstream_off", False, False, False),
("leaf", "nonevent", "benddown_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "waterstream_on", False, False, False),
("leaf", "event", "benddown_END", False, 1, False)
]
)
]
),
# DOOR OPEN
("root", "fluent", "door_on", .4, False, [
# inertially ON
("and", False, False, .01, False, [
("leaf", "prev_fluent", "door_on", False, False, False),
("leaf", "nonevent", "standing_END", False, 1, False),
]
),
# causally ON -- open from this side
("and", False, False, .99, False, [
("leaf", "prev_fluent", "door_off", False, False, False),
("leaf", "event", "standing_START", False, 10, False), # TODO: make ONGOING option
]
),
]
),
# DOOR CLOSED (DOOR OPEN OFF)
("root", "fluent", "door_off", .6, False, [
# inertially OFF
("and", False, False, .01, False, [
("leaf", "prev_fluent", "door_off", False, False, False),
("leaf", "nonevent", "standing_START", False, 1, False), # TODO: make ONGOING nonaction
]
),
# causally OFF -- close and go through
("and", False, False, .99, False, [
("leaf", "prev_fluent", "door_on", False, False, False),
("leaf", "event", "standing_END", False, 25, False),
]
),
]
),
# PHONE ACTIVE
("root", "fluent", "PHONE_ACTIVE_on", .3, False, [
# ON INERTIALLY
("and", False, False, .01, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_on", False, False, False),
("leaf", "nonevent", "makecall_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_off", False, False, False),
("leaf", "event", "makecall_START", False, 1, False),
]
)
]
),
# PHONE STANDBY (PHONE_ACTIVE_OFF)
("root", "fluent", "PHONE_ACTIVE_off", .7, False, [
# OFF INERTIALLY
("and", False, False, .01, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_off", False, False, False),
("leaf", "nonevent", "makecall_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "PHONE_ACTIVE_on", False, False, False),
("leaf", "event", "makecall_END", False, 1, False)
]
)
]
),
# LIGHT ON
("root", "fluent", "light_on", .5, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "light_on", False, False, False),
("leaf", "nonevent", "pressbutton_START", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "light_off", False, False, False),
("leaf", "event", "pressbutton_START", False, 10, False),
]
)
]
),
# LIGHT OFF (LIGHT_ON_OFF)
("root", "fluent", "light_off", .5, False, [
# ON INERTIALLY
("and", False, False, .6, False, [
("leaf", "prev_fluent", "light_off", False, False, False),
("leaf", "nonevent", "pressbutton_START", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .4, False, [
("leaf", "prev_fluent", "light_on", False, False, False),
("leaf", "event", "pressbutton_START", False, 10, False),
]
)
]
),
# TRASH MORE
("root", "fluent", "trash_MORE_on", .4, False, [
# ON CAUSALLY (NEVER ON INERTIALLY)
("and", False, False, .01, False, [
("leaf", "prev_fluent", "trash_MORE_on", False, False, False),
("leaf", "event", "throwtrash_END", False, 1, False),
]
),
# ON CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "trash_MORE_off", False, False, False),
("leaf", "event", "throwtrash_END", False, 1, False)
]
)
]
),
# TRASH MORE OFF (STAYS)
("root", "fluent", "trash_MORE_off", .6, False, [
# OFF INERTIALLY
("and", False, False, .01, False, [
("leaf", "prev_fluent", "trash_MORE_off", False, False, False),
("leaf", "nonevent", "throwtrash_END", False, 1, False),
]
),
# OFF CAUSALLY
("and", False, False, .99, False, [
("leaf", "prev_fluent", "trash_MORE_on", False, False, False),
("leaf", "nonevent", "throwtrash_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),
]
)
]
),
# SCREEN ON
("root", "fluent", "screen_on", .5, False, [
# ON INERTIALLY -- stay screen
("and", False, False, .35, False, [
("leaf", "prev_fluent", "screen_on", False, False, False),
("leaf", "nonevent", "usecomputer_END", False, 1, False),
]
),
# ON INERTIALLY -- on timer -- STAY ON SIGNALED
#("and", False, False, .6, False, [
# ("leaf", "prev_fluent", "screen_on", False, False, False),
# ("leaf", "timer", "become_screensaver", lambda t1, t2: weibull(t1,t2,600,1.5), False, False, "screen_off"), # TODO: put in different probability
# ]
#),
# ON CAUSALLY
("and", False, False, .3, False, [
("leaf", "prev_fluent", "screen_off", False, False, False),
("leaf", "event", "usecomputer_START", False, 100, False),
]
),
# ON CONTINUED USE - TODO
("and", False, False, .35, False, [
("leaf", "prev_fluent", "screen_on", False, False, False),
("leaf", "event", "usecomputer_START", False, 100, False),
]
),
]
),
# SCREEN OFF
("root", "fluent", "screen_off", .5, False, [
# OFF CAUSALLY
("and", False, False, .3, False, [
("leaf", "prev_fluent", "screen_on", False, False, False),
("leaf", "event", "usecomputer_END", False, 20, False)
]
),
# OFF SPONTANEOUSLY - fluent staying on timed out (SCREENSAVER ACTIVATED)
#("and", False, False, .4, False, [
# ("leaf", "prev_fluent", "screen_on", False, False, False),
# #("leaf", "jump", "become_screensaver", lambda t1, t2: weibull(t1,t2,600,1.5), False, False, "screen_on"), # TODO: put in different probability
# ]
#),
# OFF INERTIALLY - due to the screensaver kicking on (so causally changed because of non-action)
("and", False, False, .4, False, [
("leaf", "prev_fluent", "screen_on", False, False, False),
("leaf", "nonevent", "usecomputer_START", False, 100, False),
("leaf", "nonevent", "usecomputer_END", False, 1000, False)
]
),
# OFF INERTIALLY - no change because didn't start using the computer
("and", False, False, .3, False, [
("leaf", "prev_fluent", "screen_off", False, False, False),
("leaf", "nonevent", "usecomputer_START", False, 200, False)
]
)
]
),
# TODO: DOORLOCK -- might be possible if standing is good enough
]
"""
### NOT INCLUDED ###
# SKIPPED: ELEVATOR (because this set didn't have elevators)
# ELEVATOR DOOR OPEN
# ELEVATOR DOOR CLOSED
# SKIPPED: add "ringing"... don't have enough action information for this
# 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_summerdata_grammar)