Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BN_GenerativeModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Andriella
BN_GenerativeModel
Commits
06002892
Commit
06002892
authored
4 years ago
by
Antonio Andriella
Browse files
Options
Downloads
Patches
Plain Diff
integrate the new logic (user_action and react_time) in the simulation
parent
4e05c7c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+60
-14
60 additions, 14 deletions
main.py
with
60 additions
and
14 deletions
main.py
+
60
−
14
View file @
06002892
...
@@ -48,6 +48,40 @@ def compute_next_state(user_action, task_evolution, attempt_counter, correct_mov
...
@@ -48,6 +48,40 @@ def compute_next_state(user_action, task_evolution, attempt_counter, correct_mov
return
task_evolution
,
attempt_counter
,
correct_move_counter
,
wrong_move_counter
,
timeout_counter
,
max_attept_counter
return
task_evolution
,
attempt_counter
,
correct_move_counter
,
wrong_move_counter
,
timeout_counter
,
max_attept_counter
def
interpret_user_output
(
action_id
):
user_action
=
0
user_react_time
=
0
if
action_id
==
0
:
user_action
=
0
;
user_react_time
=
0
elif
action_id
==
1
:
user_action
=
1
;
user_react_time
=
0
elif
action_id
==
2
:
user_action
=
2
;
user_react_time
=
0
elif
action_id
==
3
:
user_action
=
0
;
user_react_time
=
1
elif
action_id
==
4
:
user_action
=
1
;
user_react_time
=
1
elif
action_id
==
5
:
user_action
=
2
;
user_react_time
=
1
elif
action_id
==
6
:
user_action
=
0
;
user_react_time
=
2
elif
action_id
==
7
:
user_action
=
1
;
user_react_time
=
2
elif
action_id
==
8
:
user_action
=
2
;
user_react_time
=
2
return
user_action
,
user_react_time
def
simulation
(
user_bn_model
,
user_var_target
,
user_memory_name
,
user_memory_value
,
user_attention_name
,
user_attention_value
,
def
simulation
(
user_bn_model
,
user_var_target
,
user_memory_name
,
user_memory_value
,
user_attention_name
,
user_attention_value
,
user_reactivity_name
,
user_reactivity_value
,
user_reactivity_name
,
user_reactivity_value
,
task_progress_name
,
game_attempt_name
,
robot_assistance_name
,
robot_feedback_name
,
task_progress_name
,
game_attempt_name
,
robot_assistance_name
,
robot_feedback_name
,
...
@@ -83,7 +117,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -83,7 +117,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
'''
'''
CPD 6: for each robot assistance store the number of pos and neg feedback
CPD 6: for each robot assistance store the number of pos and neg feedback
'''
'''
robot_assistance_per_
feedback
=
[[
0
for
i
in
range
(
Robot_Assistance
.
counter
.
value
)]
for
j
in
range
(
Robot_Feedback
.
counter
.
value
)]
robot_assistance_per_
action
=
[[
0
for
i
in
range
(
Robot_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
#these are the variables of the persona bn that are dynamic and will be affected from the game evolution
#these are the variables of the persona bn that are dynamic and will be affected from the game evolution
...
@@ -122,7 +156,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -122,7 +156,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_action
,
dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_action
,
'
game_state
'
:
game_state_counter_per_action
,
'
game_state
'
:
game_state_counter_per_action
,
'
robot_assistance
'
:
robot_assistance_per_
feedback
,
'
robot_assistance
'
:
robot_assistance_per_
action
,
'
robot_feedback
'
:
robot_feedback_per_action
}
'
robot_feedback
'
:
robot_feedback_per_action
}
while
(
task_evolution
<
task_complexity
):
while
(
task_evolution
<
task_complexity
):
...
@@ -142,6 +176,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -142,6 +176,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
robot_actions_prob
=
bn_functions
.
infer_prob_from_state
(
robot_bn_model
,
robot_actions_prob
=
bn_functions
.
infer_prob_from_state
(
robot_bn_model
,
infer_variable
=
robot_var_target
,
infer_variable
=
robot_var_target
,
evidence_variables
=
robot_vars_evidence
)
evidence_variables
=
robot_vars_evidence
)
robot_action
=
bn_functions
.
get_stochastic_action
(
robot_actions_prob
.
values
)
robot_action
=
bn_functions
.
get_stochastic_action
(
robot_actions_prob
.
values
)
n_robot_assistance_feedback
=
Robot_Assistance_Feedback
.
counter
.
value
n_robot_assistance_feedback
=
Robot_Assistance_Feedback
.
counter
.
value
if
robot_action
>=
n_robot_assistance_feedback
/
2
:
if
robot_action
>=
n_robot_assistance_feedback
/
2
:
...
@@ -188,6 +223,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -188,6 +223,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
user_actions_prob
=
bn_functions
.
infer_prob_from_state
(
other_user_bn_model
,
user_actions_prob
=
bn_functions
.
infer_prob_from_state
(
other_user_bn_model
,
infer_variable
=
other_user_var_target
,
infer_variable
=
other_user_var_target
,
evidence_variables
=
other_user_vars_evidence
)
evidence_variables
=
other_user_vars_evidence
)
else
:
else
:
#return the user action in this state based on the Persona profile
#return the user action in this state based on the Persona profile
...
@@ -199,13 +235,16 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -199,13 +235,16 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
robot_assistance_name
:
robot_assistance_action
,
robot_assistance_name
:
robot_assistance_action
,
robot_feedback_name
:
robot_feedback_action
robot_feedback_name
:
robot_feedback_action
}
}
user_action
s_prob
=
bn_functions
.
infer_prob_from_state
(
user_bn_model
,
query_re
s_prob
=
bn_functions
.
infer_prob_from_state
(
user_bn_model
,
infer_variable
=
user_var_target
,
infer_variable
=
user_var_target
,
evidence_variables
=
user_vars_evidence
)
evidence_variables
=
user_vars_evidence
)
user_action
=
bn_functions
.
get_stochastic_action
(
user_actions_prob
.
values
)
#this is needed because we are querying the system with user_react_time and user_action output is 3x3
query_res_prob_to_list
=
[
query_res_prob
.
values
[
i
][
j
]
for
i
in
range
(
query_res_prob
.
values
.
shape
[
0
])
for
j
in
range
(
query_res_prob
.
values
.
shape
[
1
])]
query_action
=
bn_functions
.
get_stochastic_action
(
query_res_prob_to_list
)
user_action
,
user_react_time
=
bn_functions
.
interpret_user_output
(
query_action
)
#updates counters for plots
#updates counters for plots
robot_assistance_per_
feedback
[
robot_feedback
_action
][
robot_assistance_action
]
+=
1
robot_assistance_per_
action
[
user
_action
][
robot_assistance_action
]
+=
1
attempt_counter_per_action
[
user_action
][
attempt_counter
]
+=
1
attempt_counter_per_action
[
user_action
][
attempt_counter
]
+=
1
game_state_counter_per_action
[
user_action
][
game_state_counter
]
+=
1
game_state_counter_per_action
[
user_action
][
game_state_counter
]
+=
1
robot_feedback_per_action
[
user_action
][
robot_feedback_action
]
+=
1
robot_feedback_per_action
[
user_action
][
robot_feedback_action
]
+=
1
...
@@ -219,7 +258,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
...
@@ -219,7 +258,7 @@ def simulation(user_bn_model, user_var_target, user_memory_name, user_memory_val
timeout_counter
,
max_attempt_counter
)
timeout_counter
,
max_attempt_counter
)
print
(
"
task_evolution {}, attempt_counter {}, timeout_counter {}
"
.
format
(
task_evolution
,
iter_counter
,
timeout_counter
))
print
(
"
task_evolution {}, attempt_counter {}, timeout_counter {}
"
.
format
(
task_evolution
,
iter_counter
,
timeout_counter
))
print
(
"
robot_assistance_per_
feedback
{}
"
.
format
(
robot_assistance_per_
feedback
))
print
(
"
robot_assistance_per_
action
{}
"
.
format
(
robot_assistance_per_
action
))
print
(
"
attempt_counter_per_action {}
"
.
format
(
attempt_counter_per_action
))
print
(
"
attempt_counter_per_action {}
"
.
format
(
attempt_counter_per_action
))
print
(
"
game_state_counter_per_action {}
"
.
format
(
game_state_counter_per_action
))
print
(
"
game_state_counter_per_action {}
"
.
format
(
game_state_counter_per_action
))
print
(
"
robot_feedback_per_action {}
"
.
format
(
robot_feedback_per_action
))
print
(
"
robot_feedback_per_action {}
"
.
format
(
robot_feedback_per_action
))
...
@@ -276,12 +315,12 @@ epochs = 40
...
@@ -276,12 +315,12 @@ epochs = 40
robot_cpds
=
bnlearn
.
import_DAG
(
'
bn_robot_model/robot_model.bif
'
)
robot_cpds
=
bnlearn
.
import_DAG
(
'
bn_robot_model/robot_model.bif
'
)
#initialise memory, attention and reactivity varibles
#initialise memory, attention and reactivity varibles
persona_memory
=
0
;
persona_attention
=
0
;
persona_reactivity
=
1
;
persona_memory
=
0
;
persona_attention
=
0
;
persona_reactivity
=
1
;
persona_cpds
=
bnlearn
.
import_DAG
(
'
bn_persona_model/persona_model.bif
'
)
persona_cpds
=
bnlearn
.
import_DAG
(
'
bn_persona_model/
new_
persona_model.bif
'
)
#initialise memory, attention and reactivity varibles
#initialise memory, attention and reactivity varibles
real_user_memory
=
2
;
real_user_attention
=
2
;
real_user_reactivity
=
2
;
real_user_memory
=
2
;
real_user_attention
=
2
;
real_user_reactivity
=
2
;
real_user_cpds
=
None
#bnlearn.import_DAG('bn_other_user_model/user_model.bif')
real_user_cpds
=
None
#bnlearn.import_DAG('bn_other_user_model/user_model.bif')
game_performance_per_episode
,
robot_assistance_per_episode
=
simulation
(
user_bn_model
=
persona_cpds
,
user_var_target
=
[
'
user_action
'
],
user_memory_name
=
"
memory
"
,
user_memory_value
=
persona_memory
,
game_performance_per_episode
,
robot_assistance_per_episode
=
simulation
(
user_bn_model
=
persona_cpds
,
user_var_target
=
[
'
user_action
'
,
'
user_react_time
'
],
user_memory_name
=
"
memory
"
,
user_memory_value
=
persona_memory
,
user_attention_name
=
"
attention
"
,
user_attention_value
=
persona_attention
,
user_attention_name
=
"
attention
"
,
user_attention_value
=
persona_attention
,
user_reactivity_name
=
"
reactivity
"
,
user_reactivity_value
=
persona_reactivity
,
user_reactivity_name
=
"
reactivity
"
,
user_reactivity_value
=
persona_reactivity
,
task_progress_name
=
"
game_state
"
,
game_attempt_name
=
"
attempt
"
,
task_progress_name
=
"
game_state
"
,
game_attempt_name
=
"
attempt
"
,
...
@@ -318,10 +357,17 @@ else:
...
@@ -318,10 +357,17 @@ else:
utils
.
plot2D_game_performance
(
full_path
+
plot_game_performance_path
,
epochs
,
game_performance_per_episode
)
utils
.
plot2D_game_performance
(
full_path
+
plot_game_performance_path
,
epochs
,
game_performance_per_episode
)
utils
.
plot2D_assistance
(
full_path
+
plot_robot_assistance_path
,
epochs
,
robot_assistance_per_episode
)
utils
.
plot2D_assistance
(
full_path
+
plot_robot_assistance_path
,
epochs
,
robot_assistance_per_episode
)
#TODO
'''
'''
- define a function that takes the state as input and return the user action and its reaction time
With the current simulator we can generate a list of episodes
- plot robot
'
s levels of assistance during the session
the episodes will be used to generate the trans probabilities and as input to the IRL algo
- evalute if the persona is wrong how long does it take for the simulator to detect that
'''
- check percentages
#TODO
'''
# - include reaction time as output
\ No newline at end of file
# - average mistakes, average timeout, average assistance, average_react_time
# - include real time episodes into the simulation:
# - counters for robot_assistance, robot_feedback, attempt, game_state, attention and reactivity
# - using the function update probability to generate the new user model and use it as input to the simulator
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment