Skip to content
Snippets Groups Projects
Commit 2a4988be authored by Antonio Andriella's avatar Antonio Andriella
Browse files

add functions to manage more than 1 query variables

parent de757a6a
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,7 @@ def average_prob(ref_cpds_table, current_cpds_table): ...@@ -60,7 +60,7 @@ def average_prob(ref_cpds_table, current_cpds_table):
res_cpds_table[elem1][elem2] = (ref_cpds_table[elem1][elem2]+current_cpds_table[elem1][elem2])/2 res_cpds_table[elem1][elem2] = (ref_cpds_table[elem1][elem2]+current_cpds_table[elem1][elem2])/2
return res_cpds_table return res_cpds_table
def update_cpds_tables(bn_model,variables_tables): def update_cpds_tables(bn_model, variables_tables):
''' '''
This function updates the bn model with the variables_tables provided in input This function updates the bn model with the variables_tables provided in input
Args: Args:
...@@ -144,6 +144,7 @@ def get_stochastic_action(actions_distr_prob): ...@@ -144,6 +144,7 @@ def get_stochastic_action(actions_distr_prob):
index = i index = i
return index return index
actions_distr_prob_scaled = [0]*len(actions_distr_prob) actions_distr_prob_scaled = [0]*len(actions_distr_prob)
accum = 0 accum = 0
for i in range(len(actions_distr_prob)): for i in range(len(actions_distr_prob)):
...@@ -155,27 +156,60 @@ def get_stochastic_action(actions_distr_prob): ...@@ -155,27 +156,60 @@ def get_stochastic_action(actions_distr_prob):
return action_id return action_id
def interpret_user_output(action_id): def flat_action_probs(action_probs):
flat_array_user_action_prob = None
column = 0
if len(action_probs.values.shape)==2:
flat_array_user_action_prob = [action_probs.values[j][i] for j in range(action_probs.values.shape[0]) for i in range(action_probs.values.shape[1])]
column = action_probs.values.shape[0]
row = action_probs.values.shape[1]
else:
assert "Did you forget to add the additional target, only one has been detected"
flat_array_user_action_prob = action_probs.values
column = 1
row = 0
return flat_array_user_action_prob, column, row
def interpret_action_output(action_id, col, row, targets):
'''
Given the id of the action selected from the probabilistic inference model and the target variables
return the action (user act + react time) or (robot ass and robot feedback)
Args
action_id 1d array of probs
col: #col of array action id
row: #row of array action id
targets the targets we aim to evaluate
Return:
user_action
user_react_time
'''
#N.B it assumes that the query is performed passing as first argument robot_assistance
# and as a second robot_feedback
robot_assistance = 0
robot_feedback = 0
user_action = 0 user_action = 0
user_react_time = 0 user_react_time = 0
if action_id == 0: if targets[0] == 'user_action':
user_action = 0; user_react_time = 0 user_action = int(action_id / row)
elif action_id == 1: user_react_time = int(action_id % row)
user_action = 1; user_react_time = 0 print("user_action ", user_action, ' user_react ', user_react_time)
elif action_id == 2: return user_action, user_react_time
user_action = 2; user_react_time = 0 elif targets[1] == 'user_action':
elif action_id == 3: user_action = int(action_id % row)
user_action = 0; user_react_time = 1 user_react_time = int(action_id / row)
elif action_id == 4: print("user_action ", user_action, ' user_react ', user_react_time)
user_action = 1; user_react_time = 1 return user_action, user_react_time
elif action_id == 5: elif targets[0] == "robot_assistance":
user_action = 2; user_react_time = 1 robot_assistance = int(action_id / row)
elif action_id == 6: robot_feedback = int(action_id % row)
user_action = 0; user_react_time = 2 print("robot_ass ", robot_assistance, 'robot_feed ', robot_feedback)
elif action_id == 7: return robot_assistance, robot_feedback
user_action = 1; user_react_time = 2 elif targets[1] == "robot_assistance":
elif action_id == 8: robot_assistance = int(action_id % row)
user_action = 2; user_react_time = 2 robot_feedback = int(action_id / row)
print("robot_feed ", robot_assistance, 'robot_ass ', robot_feedback)
return user_action, user_react_time return robot_assistance, robot_feedback
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment