-
Notifications
You must be signed in to change notification settings - Fork 0
/
stages.py
154 lines (125 loc) · 4.95 KB
/
stages.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
import numpy as np
from activities import *
class Stage():
def __init__(self, name, activity_setting):
"""
Args:
name (string): name of the stage
activity_setting (list): contains the set of activities with proabability of occurence and max_num of occurence (optional)
"""
self.name = name
self.activity_list = []
self.activity_names = []
self.activity_probs = []
self._init_activity(activity_setting)
assert self._check_probs()
self.n_activity = len(self.activity_list)
self.action_sequence = []
self.time_window_elapsed = 0
def _get_name_list(self):
return [activity.name for activity in self.activity_list]
def _check_probs(self):
return sum(self.activity_probs) == 1
# def renormalize(self):
# prob_sum = 0
# prob_sum += sum([tuple[1] for tuple in self.normal_activities])
# prob_sum += sum([tuple[1] for tuple in self.limited_activities])
# for tuple in self.normal_activities:
# tuple[1] /= prob_sum
# for tuple in self.limited_activities:
# tuple[1] /= prob_sum
def _init_activity(self, activity_setting):
"""
Generate a list of Activity object accordingly
"""
for act in activity_setting:
name, prob, n_max = act
if name == 'restroom':
self.activity_list.append(RestroomActivity())
elif name == 'walk_only':
self.activity_list.append(WalkingActivity())
elif name == 'sit_only':
self.activity_list.append(SittingActivity())
elif name == 'work':
self.activity_list.append(WorkingActivity())
elif name == 'drink_only':
self.activity_list.append(DrinkingActivity())
elif name == 'oral_clean':
self.activity_list.append(OralCleaningActivity())
else:
raise Exception("No matching activity class.")
self.activity_probs.append(prob)
self.activity_names.append(name)
def _add_activity(self, activity_name):
idx = self.activity_names.index(activity_name)
activity = self.activity_list[idx]
actions, time_window = activity.generate_activity()
self.action_sequence.extend(actions)
self.time_window_elapsed += time_window
class DaytimeStage(Stage):
"""
Daytime stage ontains drinking, sitting, walking, working and using restroom activities.
"""
def __init__(self, activity_setting=[('drink_only', 0.04, None), ('sit_only', 0.27, None), ('walk_only', 0.27, None), ('work', 0.4, None), ('restroom', 0.02, None)]):
super().__init__(name='daytime', activity_setting=activity_setting)
def generate_actions(self):
"""
Randomly select activities based on probabilities
"""
prob_threshold = 0
p = np.random.rand()
for i in range(self.n_activity):
prob_threshold += self.activity_probs[i]
act = self.activity_list[i]
if p < prob_threshold:
self._add_activity(act.name)
break
class EveningStage(Stage):
"""
Evening stage ontains drinking, sitting, walking and using restroom activities.
"""
def __init__(self, activity_setting=[('drink_only', 0.04, None), ('sit_only', 0.57, None), ('walk_only', 0.37, None), ('restroom', 0.02, None)]):
super().__init__(name='evening', activity_setting=activity_setting)
def generate_actions(self):
"""
Randomly select activities based on probabilities
"""
prob_threshold = 0
p = np.random.rand()
for i in range(self.n_activity):
prob_threshold += self.activity_probs[i]
act = self.activity_list[i]
if p < prob_threshold:
self._add_activity(act.name)
break
class DailyCareStage(Stage):
"""
Daily care stage contains the oral cleanining activity.
"""
def __init__(self, activity_setting=[('oral_clean', 1, None)]):
super().__init__(name='dailycare', activity_setting=activity_setting)
def generate_actions(self):
"""
Performing oral cleaning activity
"""
act = self.activity_list[0]
self._add_activity(act.name)
class MealStage(Stage):
"""
Meal stage contains having meal activity.
"""
def __init__(self, activity_setting=[('have_meal', 1, None)]):
super().__init__(name='meal', activity_setting=activity_setting)
def generate_actions(self):
"""
Having meals
"""
act = self.activity_list[0]
self._add_activity(act.name)
#TODO: print a log for all the hyperparamter
"""
complex event:
brushing teeth before 10 pm, brushing twice a day and each time longer than 2 min
wash hands before having meals
"""
# stage refers to