-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.py
120 lines (114 loc) · 5.19 KB
/
demo.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
# dict keys are frame numbers
# frames are only reported when a fluent changes, and only for the fluent(s) that changed; fluents are considered to be on or off ("light" is treated as "light_on", and then "light_off" is calculated from that internally, for instance)
import causal_grammar
fluent_parses = {
1: { "light": .105, "fluent_3": .511, "fluent_4": .916, "fluent_5": 1.61, "fluent_6": .105 },
6: { "light": causal_grammar.kZeroProbabilityEnergy, "fluent_6": causal_grammar.kZeroProbabilityEnergy},
16: { "light": causal_grammar.kZeroProbabilityEnergy, "fluent_4": 1.20},
17: { "fluent_3": causal_grammar.kZeroProbabilityEnergy, "fluent_4": 2.30},
400: { "fluent_5": .223, "light": .105},
}
# dict keys are frame numbers
# frames are only reported when an event begins
# events have energy and agents
# it is assumed that the same event /can/ happen multiple times at the same time (multiple people talking on different cell phones, for example)
temporal_parses = {
5: { "E1_START": {"energy": .105, "agent": ("uuid4")} },
6: { "E1_END": {"energy": .105, "agent": ("uuid4")}, "E5_START": {"energy": 1.20, "agent": ("uuid2") } },
7: { "E2_START": {"energy": .511, "agent": ("uuid1") }, "E5_END": {"energy": 1.20, "agent": ("uuid2") } },
10: { "E3_START": {"energy": .916, "agent": ("uuid3") } },
15: { "E1_START": {"energy": .223, "agent": ("uuid9") } },
19: { "E1_END": {"energy": .223, "agent": ("uuid9") } },
45: { "E3_END": {"energy": .916, "agent": ("uuid3") } },
450: { "E1_START": {"energy": .916, "agent": ("uuid3") } },
455: { "E1_END": {"energy": .916, "agent": ("uuid3") } },
}
# our causal forest:
causal_forest = [
{
"node_type": "root",
"symbol_type": "fluent",
"symbol": "light_on",
"children": [
{ "node_type": "and", "probability": .3, "children": [
{ "node_type": "leaf", "symbol": "light_on", "symbol_type": "prev_fluent" },
{ "node_type": "leaf", "symbol": "E1_START", "symbol_type": "nonevent", "timeout": 10 },
]},
{ "node_type": "and", "probability": .7, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "light_off" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "E1_START", "timeout": 10 },
]
},
],
}, {
"node_type": "root",
"symbol_type": "fluent",
"symbol": "light_off",
"children": [
{ "node_type": "and", "probability": .3, "children": [
{ "node_type": "leaf", "symbol": "light_off", "symbol_type": "prev_fluent" },
{ "node_type": "leaf", "symbol": "E1_START", "symbol_type": "nonevent", "timeout": 10 },
]},
{ "node_type": "and", "probability": .7, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "light_on" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "E1_START", "timeout": 10 },
]
},
],
},
{
"node_type": "root",
"symbol_type": "fluent",
"symbol": "dooropen_on",
"children": [
{ "node_type": "leaf", "probability": .6, "symbol": "dooropen_on", "symbol_type": "prev_fluent" },
{ "node_type": "and", "probability": .2, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "dooropen_off" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "door_open_outside", "timeout": 20 },
]
},
{ "node_type": "and", "probability": .2, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "dooropen_off" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "door_open_inside", "timeout": 20 },
]
},
],
}, {
"node_type": "root",
"symbol_type": "fluent",
"symbol": "dooropen_off",
"children": [
{ "node_type": "leaf", "probability": .6, "symbol_type":"prev_fluent", "symbol": "dooropen_off" },
{ "node_type": "and", "probability": .2, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "dooropen_on" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "door_close_outside", "timeout": 20 },
]
},
{ "node_type": "and", "probability": .2, "children": [
{ "node_type": "leaf", "symbol_type": "prev_fluent", "symbol": "dooropen_on" },
{ "node_type": "leaf", "symbol_type": "event", "symbol": "door_close_inside", "timeout": 20 },
]
},
],
},
]
# TRUE NEXT LINE TO LOAD ORIGINAL MATLAB CSV FILE FOR OFFICE SCENE, JUST PULLING LIGHT SWITCH AND DOOR INFO, OVERRIDING TRIVIAL fluent_parses AND temporal_parses ABOVE
if False:
fluent_maps = {"Light_Status": "light", "Door_Status": "dooropen"}
event_maps = {"Touch_Switch":"E1", "Close_Door_Inside": "door_close_inside", "Close_Door_Outside": "door_close_outside", "Open_Door_Inside":"door_open_inside", "Open_Door_Outside":"door_open_outside"}
fluent_parses, temporal_parses = causal_grammar.import_csv("results/Exp2_output_data.txt",fluent_maps,event_maps)
print "--PREPPING DEMO--"
import pprint
pp = pprint.PrettyPrinter(indent=1)
print("causal_forest")
pp.pprint(causal_forest)
causal_grammar.hr()
print("fluent_parses")
pp.pprint(fluent_parses)
causal_grammar.hr()
print("temporal_parses")
pp.pprint(temporal_parses)
causal_grammar.hr()
print "--RUNNING DEMO--"
causal_grammar.process_events_and_fluents(causal_forest, fluent_parses, temporal_parses, causal_grammar.kFluentThresholdOnEnergy, causal_grammar.kFluentThresholdOffEnergy, causal_grammar.kReportingThresholdEnergy)
print "--DEMO COMPLETE--"