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
1eee9533
Commit
1eee9533
authored
4 years ago
by
Antonio Andriella
Browse files
Options
Downloads
Patches
Plain Diff
working version including new function to read real_time variables and update them into the model
parent
fb0a85fa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+126
-102
126 additions, 102 deletions
main.py
with
126 additions
and
102 deletions
main.py
+
126
−
102
View file @
1eee9533
...
@@ -3,7 +3,7 @@ import os
...
@@ -3,7 +3,7 @@ import os
import
bnlearn
import
bnlearn
import
numpy
as
np
import
numpy
as
np
#import classes and modules
#import classes and modules
from
bn_variables
import
Robo
t_Assistance
,
Robo
t_Feedback
,
User_Action
,
User_React_time
,
Game_State
,
Attempt
from
bn_variables
import
Agen
t_Assistance
,
Agen
t_Feedback
,
User_Action
,
User_React_time
,
Game_State
,
Attempt
import
bn_functions
import
bn_functions
import
utils
import
utils
import
episode
as
ep
import
episode
as
ep
...
@@ -47,7 +47,7 @@ def compute_next_state(user_action, task_progress_counter, attempt_counter, corr
...
@@ -47,7 +47,7 @@ def compute_next_state(user_action, task_progress_counter, attempt_counter, corr
elif
user_action
==
0
and
attempt_counter
<
max_attempt_per_object
:
elif
user_action
==
0
and
attempt_counter
<
max_attempt_per_object
:
attempt_counter
+=
1
attempt_counter
+=
1
timeout_counter
+=
1
timeout_counter
+=
1
# the
robo
t or therapist makes the correct move on the patient's behalf
# the
agen
t or therapist makes the correct move on the patient's behalf
else
:
else
:
attempt_counter
=
1
attempt_counter
=
1
max_attempt_counter
+=
1
max_attempt_counter
+=
1
...
@@ -75,9 +75,9 @@ def compute_next_state(user_action, task_progress_counter, attempt_counter, corr
...
@@ -75,9 +75,9 @@ def compute_next_state(user_action, task_progress_counter, attempt_counter, corr
def
simulation
(
bn_model_user_action
,
var_user_action_target_action
,
bn_model_user_react_time
,
var_user_react_time_target_action
,
def
simulation
(
bn_model_user_action
,
var_user_action_target_action
,
bn_model_user_react_time
,
var_user_react_time_target_action
,
user_memory_name
,
user_memory_value
,
user_attention_name
,
user_attention_value
,
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
,
robo
t_assistance_name
,
robo
t_feedback_name
,
task_progress_name
,
game_attempt_name
,
agen
t_assistance_name
,
agen
t_feedback_name
,
bn_model_
robo
t_assistance
,
var_
robo
t_assistance_target_action
,
bn_model_
robo
t_feedback
,
bn_model_
agen
t_assistance
,
var_
agen
t_assistance_target_action
,
bn_model_
agen
t_feedback
,
var_
robo
t_feedback_target_action
,
var_
agen
t_feedback_target_action
,
bn_model_other_user_action
,
var_other_user_action_target_action
,
bn_model_other_user_action
,
var_other_user_action_target_action
,
bn_model_other_user_react_time
,
var_other_user_target_react_time_action
,
bn_model_other_user_react_time
,
var_other_user_target_react_time_action
,
other_user_memory_name
,
other_user_memory_value
,
other_user_memory_name
,
other_user_memory_value
,
...
@@ -94,25 +94,25 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -94,25 +94,25 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
n_timeout_per_episode:
n_timeout_per_episode:
'''
'''
#TODO: remove
robo
t_assistance_vect and
robo
t_feedback_vect
#TODO: remove
agen
t_assistance_vect and
agen
t_feedback_vect
#metrics we need, in order to compute afterwords the belief
#metrics we need, in order to compute afterwords the belief
attempt_counter_per_action
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
attempt_counter_per_action
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
game_state_counter_per_action
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
game_state_counter_per_action
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
robo
t_feedback_per_action
=
[[
0
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
agen
t_feedback_per_action
=
[[
0
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
robo
t_assistance_per_action
=
[[
0
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
agen
t_assistance_per_action
=
[[
0
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
attempt_counter_per_react_time
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
attempt_counter_per_react_time
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
game_state_counter_per_react_time
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
game_state_counter_per_react_time
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
robo
t_feedback_per_react_time
=
[[
0
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
agen
t_feedback_per_react_time
=
[[
0
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
robo
t_assistance_per_react_time
=
[[
0
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
agen
t_assistance_per_react_time
=
[[
0
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
game_state_counter_per_
robo
t_assistance
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
game_state_counter_per_
agen
t_assistance
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
attempt_counter_per_
robo
t_assistance
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
attempt_counter_per_
agen
t_assistance
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
game_state_counter_per_
robo
t_feedback
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
game_state_counter_per_
agen
t_feedback
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
attempt_counter_per_
robo
t_feedback
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
attempt_counter_per_
agen
t_feedback
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
#output variables:
#output variables:
...
@@ -121,8 +121,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -121,8 +121,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
n_timeout_per_episode
=
[
0
]
*
epochs
n_timeout_per_episode
=
[
0
]
*
epochs
n_max_attempt_per_episode
=
[
0
]
*
epochs
n_max_attempt_per_episode
=
[
0
]
*
epochs
game_performance_episode
=
[
0
]
*
epochs
game_performance_episode
=
[
0
]
*
epochs
n_assistance_lev_per_episode
=
[[
0
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
n_assistance_lev_per_episode
=
[[
0
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
n_feedback_per_episode
=
[[
0
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
n_feedback_per_episode
=
[[
0
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
n_react_time_per_episode
=
[[
0
for
i
in
range
(
User_React_time
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
n_react_time_per_episode
=
[[
0
for
i
in
range
(
User_React_time
.
counter
.
value
)]
for
j
in
range
(
epochs
)]
...
@@ -144,19 +144,19 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -144,19 +144,19 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
#The following variables are used to update the BN at the end of the episode
#The following variables are used to update the BN at the end of the episode
user_action_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_action
,
user_action_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_action
,
'
game_state
'
:
game_state_counter_per_action
,
'
game_state
'
:
game_state_counter_per_action
,
'
robo
t_assistance
'
:
robo
t_assistance_per_action
,
'
agen
t_assistance
'
:
agen
t_assistance_per_action
,
'
robo
t_feedback
'
:
robo
t_feedback_per_action
}
'
agen
t_feedback
'
:
agen
t_feedback_per_action
}
user_react_time_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_react_time
,
user_react_time_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_react_time
,
'
game_state
'
:
game_state_counter_per_react_time
,
'
game_state
'
:
game_state_counter_per_react_time
,
'
robo
t_assistance
'
:
robo
t_assistance_per_react_time
,
'
agen
t_assistance
'
:
agen
t_assistance_per_react_time
,
'
robo
t_feedback
'
:
robo
t_feedback_per_react_time
}
'
agen
t_feedback
'
:
agen
t_feedback_per_react_time
}
robo
t_assistance_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_
robo
t_assistance
,
agen
t_assistance_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_
agen
t_assistance
,
'
game_state
'
:
game_state_counter_per_
robo
t_assistance
}
'
game_state
'
:
game_state_counter_per_
agen
t_assistance
}
robo
t_feedback_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_
robo
t_feedback
,
agen
t_feedback_dynamic_variables
=
{
'
attempt
'
:
attempt_counter_per_
agen
t_feedback
,
'
game_state
'
:
game_state_counter_per_
robo
t_feedback
}
'
game_state
'
:
game_state_counter_per_
agen
t_feedback
}
#data structure to memorise the sequence of states (state, action, next_state)
#data structure to memorise the sequence of states (state, action, next_state)
episode
=
[]
episode
=
[]
...
@@ -168,30 +168,30 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -168,30 +168,30 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
current_state
=
(
game_state_counter
,
attempt_counter
,
selected_user_action
)
current_state
=
(
game_state_counter
,
attempt_counter
,
selected_user_action
)
##################QUERY FOR THE ROBOT ASSISTANCE AND FEEDBACK##################
##################QUERY FOR THE ROBOT ASSISTANCE AND FEEDBACK##################
vars_
robo
t_evidence
=
{
vars_
agen
t_evidence
=
{
user_reactivity_name
:
user_reactivity_value
,
user_reactivity_name
:
user_reactivity_value
,
user_memory_name
:
user_memory_value
,
user_memory_name
:
user_memory_value
,
task_progress_name
:
game_state_counter
,
task_progress_name
:
game_state_counter
,
game_attempt_name
:
attempt_counter
-
1
,
game_attempt_name
:
attempt_counter
-
1
,
}
}
query_
robo
t_assistance_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_
robo
t_assistance
,
query_
agen
t_assistance_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_
agen
t_assistance
,
infer_variable
=
var_
robo
t_assistance_target_action
,
infer_variable
=
var_
agen
t_assistance_target_action
,
evidence_variables
=
vars_
robo
t_evidence
)
evidence_variables
=
vars_
agen
t_evidence
)
query_
robo
t_feedback_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_
robo
t_feedback
,
query_
agen
t_feedback_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_
agen
t_feedback
,
infer_variable
=
var_
robo
t_feedback_target_action
,
infer_variable
=
var_
agen
t_feedback_target_action
,
evidence_variables
=
vars_
robo
t_evidence
)
evidence_variables
=
vars_
agen
t_evidence
)
selected_
robo
t_assistance_action
=
bn_functions
.
get_stochastic_action
(
query_
robo
t_assistance_prob
.
values
)
selected_
agen
t_assistance_action
=
bn_functions
.
get_stochastic_action
(
query_
agen
t_assistance_prob
.
values
)
selected_
robo
t_feedback_action
=
bn_functions
.
get_stochastic_action
(
query_
robo
t_feedback_prob
.
values
)
selected_
agen
t_feedback_action
=
bn_functions
.
get_stochastic_action
(
query_
agen
t_feedback_prob
.
values
)
#counters for plots
#counters for plots
n_assistance_lev_per_episode
[
e
][
selected_
robo
t_assistance_action
]
+=
1
n_assistance_lev_per_episode
[
e
][
selected_
agen
t_assistance_action
]
+=
1
n_feedback_per_episode
[
e
][
selected_
robo
t_feedback_action
]
+=
1
n_feedback_per_episode
[
e
][
selected_
agen
t_feedback_action
]
+=
1
current_
robo
t_action
=
(
selected_
robo
t_assistance_action
,
selected_
robo
t_feedback_action
)
current_
agen
t_action
=
(
selected_
agen
t_assistance_action
,
selected_
agen
t_feedback_action
)
print
(
"
robo
t_assistance {}, attempt {}, game {},
robo
t_feedback {}
"
.
format
(
selected_
robo
t_assistance_action
,
attempt_counter
,
game_state_counter
,
selected_
robo
t_feedback_action
))
print
(
"
agen
t_assistance {}, attempt {}, game {},
agen
t_feedback {}
"
.
format
(
selected_
agen
t_assistance_action
,
attempt_counter
,
game_state_counter
,
selected_
agen
t_feedback_action
))
##########################QUERY FOR THE USER ACTION AND REACT TIME#####################################
##########################QUERY FOR THE USER ACTION AND REACT TIME#####################################
...
@@ -203,8 +203,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -203,8 +203,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
other_user_memory_name
:
other_user_memory_value
,
other_user_memory_name
:
other_user_memory_value
,
task_progress_name
:
game_state_counter
,
task_progress_name
:
game_state_counter
,
game_attempt_name
:
attempt_counter
-
1
,
game_attempt_name
:
attempt_counter
-
1
,
robo
t_assistance_name
:
selected_
robo
t_assistance_action
,
agen
t_assistance_name
:
selected_
agen
t_assistance_action
,
robo
t_feedback_name
:
selected_
robo
t_feedback_action
agen
t_feedback_name
:
selected_
agen
t_feedback_action
}
}
query_user_action_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_other_user_action
,
query_user_action_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_other_user_action
,
infer_variable
=
var_other_user_action_target_action
,
infer_variable
=
var_other_user_action_target_action
,
...
@@ -221,8 +221,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -221,8 +221,8 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
user_memory_name
:
user_memory_value
,
user_memory_name
:
user_memory_value
,
task_progress_name
:
game_state_counter
,
task_progress_name
:
game_state_counter
,
game_attempt_name
:
attempt_counter
-
1
,
game_attempt_name
:
attempt_counter
-
1
,
robo
t_assistance_name
:
selected_
robo
t_assistance_action
,
agen
t_assistance_name
:
selected_
agen
t_assistance_action
,
robo
t_feedback_name
:
selected_
robo
t_feedback_action
agen
t_feedback_name
:
selected_
agen
t_feedback_action
}
}
query_user_action_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_user_action
,
query_user_action_prob
=
bn_functions
.
infer_prob_from_state
(
bn_model_user_action
,
infer_variable
=
var_user_action_target_action
,
infer_variable
=
var_user_action_target_action
,
...
@@ -239,21 +239,21 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -239,21 +239,21 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
n_react_time_per_episode
[
e
][
selected_user_react_time
]
+=
1
n_react_time_per_episode
[
e
][
selected_user_react_time
]
+=
1
#updates counters for user action
#updates counters for user action
robo
t_assistance_per_action
[
selected_user_action
][
selected_
robo
t_assistance_action
]
+=
1
agen
t_assistance_per_action
[
selected_user_action
][
selected_
agen
t_assistance_action
]
+=
1
attempt_counter_per_action
[
selected_user_action
][
attempt_counter
-
1
]
+=
1
attempt_counter_per_action
[
selected_user_action
][
attempt_counter
-
1
]
+=
1
game_state_counter_per_action
[
selected_user_action
][
game_state_counter
]
+=
1
game_state_counter_per_action
[
selected_user_action
][
game_state_counter
]
+=
1
robo
t_feedback_per_action
[
selected_user_action
][
selected_
robo
t_feedback_action
]
+=
1
agen
t_feedback_per_action
[
selected_user_action
][
selected_
agen
t_feedback_action
]
+=
1
#update counter for user react time
#update counter for user react time
robo
t_assistance_per_react_time
[
selected_user_react_time
][
selected_
robo
t_assistance_action
]
+=
1
agen
t_assistance_per_react_time
[
selected_user_react_time
][
selected_
agen
t_assistance_action
]
+=
1
attempt_counter_per_react_time
[
selected_user_react_time
][
attempt_counter
-
1
]
+=
1
attempt_counter_per_react_time
[
selected_user_react_time
][
attempt_counter
-
1
]
+=
1
game_state_counter_per_react_time
[
selected_user_react_time
][
game_state_counter
]
+=
1
game_state_counter_per_react_time
[
selected_user_react_time
][
game_state_counter
]
+=
1
robo
t_feedback_per_react_time
[
selected_user_react_time
][
selected_
robo
t_feedback_action
]
+=
1
agen
t_feedback_per_react_time
[
selected_user_react_time
][
selected_
agen
t_feedback_action
]
+=
1
#update counter for
robo
t feedback
#update counter for
agen
t feedback
game_state_counter_per_
robo
t_feedback
[
selected_
robo
t_feedback_action
][
game_state_counter
]
+=
1
game_state_counter_per_
agen
t_feedback
[
selected_
agen
t_feedback_action
][
game_state_counter
]
+=
1
attempt_counter_per_
robo
t_feedback
[
selected_
robo
t_feedback_action
][
attempt_counter
-
1
]
+=
1
attempt_counter_per_
agen
t_feedback
[
selected_
agen
t_feedback_action
][
attempt_counter
-
1
]
+=
1
#update counter for
robo
t assistance
#update counter for
agen
t assistance
game_state_counter_per_
robo
t_assistance
[
selected_
robo
t_assistance_action
][
game_state_counter
]
+=
1
game_state_counter_per_
agen
t_assistance
[
selected_
agen
t_assistance_action
][
game_state_counter
]
+=
1
attempt_counter_per_
robo
t_assistance
[
selected_
robo
t_assistance_action
][
attempt_counter
-
1
]
+=
1
attempt_counter_per_
agen
t_assistance
[
selected_
agen
t_assistance_action
][
attempt_counter
-
1
]
+=
1
# updates counters for simulation
# updates counters for simulation
# remap user_action index
# remap user_action index
...
@@ -276,7 +276,7 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -276,7 +276,7 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
# store the (state, action, next_state)
# store the (state, action, next_state)
episode
.
append
((
ep
.
point_to_index
(
current_state
,
state_space
),
episode
.
append
((
ep
.
point_to_index
(
current_state
,
state_space
),
ep
.
point_to_index
(
current_
robo
t_action
,
action_space
),
ep
.
point_to_index
(
current_
agen
t_action
,
action_space
),
ep
.
point_to_index
(
next_state
,
state_space
)))
ep
.
point_to_index
(
next_state
,
state_space
)))
print
(
"
current_state
"
,
current_state
,
"
next_state
"
,
next_state
)
print
(
"
current_state
"
,
current_state
,
"
next_state
"
,
next_state
)
...
@@ -284,10 +284,10 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -284,10 +284,10 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
print
(
"
game_state_counter {}, iter_counter {}, correct_counter {}, wrong_counter {},
"
print
(
"
game_state_counter {}, iter_counter {}, correct_counter {}, wrong_counter {},
"
"
timeout_counter {}, max_attempt {}
"
.
format
(
game_state_counter
,
iter_counter
,
correct_move_counter
,
"
timeout_counter {}, max_attempt {}
"
.
format
(
game_state_counter
,
iter_counter
,
correct_move_counter
,
wrong_move_counter
,
timeout_counter
,
max_attempt_counter
))
wrong_move_counter
,
timeout_counter
,
max_attempt_counter
))
# print("
robo
t_assistance_per_action {}".format(
robo
t_assistance_per_action))
# print("
agen
t_assistance_per_action {}".format(
agen
t_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("
robo
t_feedback_per_action {}".format(
robo
t_feedback_per_action))
# print("
agen
t_feedback_per_action {}".format(
agen
t_feedback_per_action))
# print("iter {}, correct {}, wrong {}, timeout {}".format(iter_counter, correct_move_counter, wrong_move_counter, timeout_counter))
# print("iter {}, correct {}, wrong {}, timeout {}".format(iter_counter, correct_move_counter, wrong_move_counter, timeout_counter))
#save episode
#save episode
...
@@ -296,14 +296,14 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -296,14 +296,14 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
#update user models
#update user models
bn_model_user_action
=
bn_functions
.
update_cpds_tables
(
bn_model_user_action
,
user_action_dynamic_variables
)
bn_model_user_action
=
bn_functions
.
update_cpds_tables
(
bn_model_user_action
,
user_action_dynamic_variables
)
bn_model_user_react_time
=
bn_functions
.
update_cpds_tables
(
bn_model_user_react_time
,
user_react_time_dynamic_variables
)
bn_model_user_react_time
=
bn_functions
.
update_cpds_tables
(
bn_model_user_react_time
,
user_react_time_dynamic_variables
)
#update
robo
t models
#update
agen
t models
bn_model_
robo
t_assistance
=
bn_functions
.
update_cpds_tables
(
bn_model_
robo
t_assistance
,
robo
t_assistance_dynamic_variables
)
bn_model_
agen
t_assistance
=
bn_functions
.
update_cpds_tables
(
bn_model_
agen
t_assistance
,
agen
t_assistance_dynamic_variables
)
bn_model_
robo
t_feedback
=
bn_functions
.
update_cpds_tables
(
bn_model_
robo
t_feedback
,
robo
t_feedback_dynamic_variables
)
bn_model_
agen
t_feedback
=
bn_functions
.
update_cpds_tables
(
bn_model_
agen
t_feedback
,
agen
t_feedback_dynamic_variables
)
#reset counter
#reset counter
robo
t_assistance_per_action
=
[[
0
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
for
j
in
agen
t_assistance_per_action
=
[[
0
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
range
(
User_Action
.
counter
.
value
)]
robo
t_feedback_per_action
=
[[
0
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
for
j
in
agen
t_feedback_per_action
=
[[
0
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
range
(
User_Action
.
counter
.
value
)]
game_state_counter_per_action
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
game_state_counter_per_action
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_Action
.
counter
.
value
)]
range
(
User_Action
.
counter
.
value
)]
...
@@ -314,20 +314,20 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -314,20 +314,20 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
range
(
User_React_time
.
counter
.
value
)]
range
(
User_React_time
.
counter
.
value
)]
game_state_counter_per_react_time
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
game_state_counter_per_react_time
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
range
(
User_React_time
.
counter
.
value
)]
robo
t_feedback_per_react_time
=
[[
0
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
for
j
in
agen
t_feedback_per_react_time
=
[[
0
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
range
(
User_React_time
.
counter
.
value
)]
robo
t_assistance_per_react_time
=
[[
0
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
for
j
in
agen
t_assistance_per_react_time
=
[[
0
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
for
j
in
range
(
User_React_time
.
counter
.
value
)]
range
(
User_React_time
.
counter
.
value
)]
game_state_counter_per_
robo
t_assistance
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
game_state_counter_per_
agen
t_assistance
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
range
(
Agen
t_Assistance
.
counter
.
value
)]
attempt_counter_per_
robo
t_assistance
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
attempt_counter_per_
agen
t_assistance
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
range
(
Agen
t_Assistance
.
counter
.
value
)]
game_state_counter_per_
robo
t_feedback
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
game_state_counter_per_
agen
t_feedback
=
[[
0
for
i
in
range
(
Game_State
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
range
(
Agen
t_Feedback
.
counter
.
value
)]
attempt_counter_per_
robo
t_feedback
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
attempt_counter_per_
agen
t_feedback
=
[[
0
for
i
in
range
(
Attempt
.
counter
.
value
)]
for
j
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
range
(
Agen
t_Feedback
.
counter
.
value
)]
#for plots
#for plots
n_correct_per_episode
[
e
]
=
correct_move_counter
n_correct_per_episode
[
e
]
=
correct_move_counter
...
@@ -351,12 +351,11 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
...
@@ -351,12 +351,11 @@ def simulation(bn_model_user_action, var_user_action_target_action, bn_model_use
#############################################################################
#############################################################################
#SIMULATION PARAMS
#SIMULATION PARAMS
epochs
=
10
epochs
=
10
#initialise the
robo
t
#initialise the
agen
t
bn_model_
robot
_assistance
=
bnlearn
.
import_DAG
(
'
bn_
robo
t_model/
robo
t_assistive_model.bif
'
)
bn_model_
caregiver
_assistance
=
bnlearn
.
import_DAG
(
'
bn_
agen
t_model/
agen
t_assistive_model.bif
'
)
bn_model_
robot
_feedback
=
bnlearn
.
import_DAG
(
'
bn_
robo
t_model/
robo
t_feedback_model.bif
'
)
bn_model_
caregiver
_feedback
=
bnlearn
.
import_DAG
(
'
bn_
agen
t_model/
agen
t_feedback_model.bif
'
)
bn_model_user_action
=
bnlearn
.
import_DAG
(
'
bn_persona_model/user_action_model.bif
'
)
bn_model_user_action
=
bnlearn
.
import_DAG
(
'
bn_persona_model/user_action_model.bif
'
)
bn_model_user_react_time
=
bnlearn
.
import_DAG
(
'
bn_persona_model/user_react_time_model.bif
'
)
bn_model_user_react_time
=
bnlearn
.
import_DAG
(
'
bn_persona_model/user_react_time_model.bif
'
)
bn_model_other_user_action
=
None
#bnlearn.import_DAG('bn_persona_model/other_user_action_model.bif')
bn_model_other_user_action
=
None
#bnlearn.import_DAG('bn_persona_model/other_user_action_model.bif')
...
@@ -374,43 +373,68 @@ game_state = [i for i in range(0, Game_State.counter.value+1)]
...
@@ -374,43 +373,68 @@ game_state = [i for i in range(0, Game_State.counter.value+1)]
user_action
=
[
i
for
i
in
range
(
-
1
,
User_Action
.
counter
.
value
-
1
)]
user_action
=
[
i
for
i
in
range
(
-
1
,
User_Action
.
counter
.
value
-
1
)]
state_space
=
(
game_state
,
attempt
,
user_action
)
state_space
=
(
game_state
,
attempt
,
user_action
)
states_space_list
=
list
(
itertools
.
product
(
*
state_space
))
states_space_list
=
list
(
itertools
.
product
(
*
state_space
))
robo
t_assistance_action
=
[
i
for
i
in
range
(
Robo
t_Assistance
.
counter
.
value
)]
agen
t_assistance_action
=
[
i
for
i
in
range
(
Agen
t_Assistance
.
counter
.
value
)]
robo
t_feedback_action
=
[
i
for
i
in
range
(
Robo
t_Feedback
.
counter
.
value
)]
agen
t_feedback_action
=
[
i
for
i
in
range
(
Agen
t_Feedback
.
counter
.
value
)]
action_space
=
(
robo
t_assistance_action
,
robo
t_feedback_action
)
action_space
=
(
agen
t_assistance_action
,
agen
t_feedback_action
)
action_space_list
=
list
(
itertools
.
product
(
*
action_space
))
action_space_list
=
list
(
itertools
.
product
(
*
action_space
))
game_performance_per_episode
,
react_time_per_episode
,
robot_assistance_per_episode
,
robot_feedback_per_episode
,
generated_episodes
=
\
##############BEFORE RUNNING THE SIMULATION UPDATE THE BELIEF IF YOU HAVE DATA####################
simulation
(
bn_model_user_action
=
bn_model_user_action
,
var_user_action_target_action
=
[
'
user_action
'
],
bn_belief_user_action_file
=
"
/home/pal/carf_ws/src/carf/caregiver_in_the_loop/log/0/bn_belief_user_action.pkl
"
bn_model_user_react_time
=
bn_model_user_react_time
,
var_user_react_time_target_action
=
[
'
user_react_time
'
],
bn_belief_user_react_time_file
=
"
/home/pal/carf_ws/src/carf/caregiver_in_the_loop/log/0/bn_belief_user_react_time.pkl
"
user_memory_name
=
"
memory
"
,
user_memory_value
=
persona_memory
,
bn_belief_caregiver_assistance_file
=
"
/home/pal/carf_ws/src/carf/caregiver_in_the_loop/log/0/bn_belief_caregiver_assistive_action.pkl
"
user_attention_name
=
"
attention
"
,
user_attention_value
=
persona_attention
,
bn_belief_caregiver_feedback_file
=
"
/home/pal/carf_ws/src/carf/caregiver_in_the_loop/log/0/bn_belief_caregiver_feedback_action.pkl
"
user_reactivity_name
=
"
reactivity
"
,
user_reactivity_value
=
persona_reactivity
,
if
bn_belief_user_action_file
!=
None
and
bn_belief_user_react_time_file
!=
None
and
\
task_progress_name
=
"
game_state
"
,
game_attempt_name
=
"
attempt
"
,
bn_belief_caregiver_assistance_file
!=
None
and
bn_belief_caregiver_feedback_file
!=
None
:
robot_assistance_name
=
"
robot_assistance
"
,
robot_feedback_name
=
"
robot_feedback
"
,
bn_belief_user_action
=
utils
.
read_user_statistics_from_pickle
(
bn_belief_user_action_file
)
bn_model_robot_assistance
=
bn_model_robot_assistance
,
var_robot_assistance_target_action
=
[
"
robot_assistance
"
],
bn_belief_user_react_time
=
utils
.
read_user_statistics_from_pickle
(
bn_belief_user_react_time_file
)
bn_model_robot_feedback
=
bn_model_robot_feedback
,
var_robot_feedback_target_action
=
[
"
robot_feedback
"
],
bn_belief_caregiver_assistance
=
utils
.
read_user_statistics_from_pickle
(
bn_belief_caregiver_assistance_file
)
bn_model_other_user_action
=
bn_model_other_user_action
,
var_other_user_action_target_action
=
[
'
user_action
'
],
bn_belief_caregiver_feedback
=
utils
.
read_user_statistics_from_pickle
(
bn_belief_caregiver_feedback_file
)
bn_model_other_user_react_time
=
bn_model_other_user_react_time
,
bn_model_user_action
=
bn_functions
.
update_cpds_tables
(
bn_model
=
bn_model_user_action
,
variables_tables
=
bn_belief_user_action
)
var_other_user_target_react_time_action
=
[
"
user_react_time
"
],
other_user_memory_name
=
"
memory
"
,
bn_model_user_react_time
=
bn_functions
.
update_cpds_tables
(
bn_model
=
bn_model_user_react_time
,
variables_tables
=
bn_belief_user_react_time
)
other_user_memory_value
=
other_user_memory
,
other_user_attention_name
=
"
attention
"
,
bn_model_caregiver_assistance
=
bn_functions
.
update_cpds_tables
(
bn_model
=
bn_model_caregiver_assistance
,
variables_tables
=
bn_belief_caregiver_assistance
)
other_user_attention_value
=
other_user_attention
,
other_user_reactivity_name
=
"
reactivity
"
,
bn_model_caregiver_feedback
=
bn_functions
.
update_cpds_tables
(
bn_model
=
bn_model_caregiver_feedback
,
variables_tables
=
bn_belief_caregiver_feedback
)
other_user_reactivity_value
=
other_user_reactivity
,
state_space
=
states_space_list
,
action_space
=
action_space_list
,
game_performance_per_episode
,
react_time_per_episode
,
agent_assistance_per_episode
,
agent_feedback_per_episode
,
generated_episodes
=
\
epochs
=
epochs
,
task_complexity
=
5
,
max_attempt_per_object
=
4
)
simulation
(
bn_model_user_action
=
bn_model_user_action
,
var_user_action_target_action
=
[
'
user_action
'
],
bn_model_user_react_time
=
bn_model_user_react_time
,
var_user_react_time_target_action
=
[
'
user_react_time
'
],
user_memory_name
=
"
memory
"
,
user_memory_value
=
persona_memory
,
user_attention_name
=
"
attention
"
,
user_attention_value
=
persona_attention
,
user_reactivity_name
=
"
reactivity
"
,
user_reactivity_value
=
persona_reactivity
,
task_progress_name
=
"
game_state
"
,
game_attempt_name
=
"
attempt
"
,
agent_assistance_name
=
"
agent_assistance
"
,
agent_feedback_name
=
"
agent_feedback
"
,
bn_model_agent_assistance
=
bn_model_caregiver_assistance
,
var_agent_assistance_target_action
=
[
"
agent_assistance
"
],
bn_model_agent_feedback
=
bn_model_caregiver_feedback
,
var_agent_feedback_target_action
=
[
"
agent_feedback
"
],
bn_model_other_user_action
=
bn_model_other_user_action
,
var_other_user_action_target_action
=
[
'
user_action
'
],
bn_model_other_user_react_time
=
bn_model_other_user_react_time
,
var_other_user_target_react_time_action
=
[
"
user_react_time
"
],
other_user_memory_name
=
"
memory
"
,
other_user_memory_value
=
other_user_memory
,
other_user_attention_name
=
"
attention
"
,
other_user_attention_value
=
other_user_attention
,
other_user_reactivity_name
=
"
reactivity
"
,
other_user_reactivity_value
=
other_user_reactivity
,
state_space
=
states_space_list
,
action_space
=
action_space_list
,
epochs
=
epochs
,
task_complexity
=
5
,
max_attempt_per_object
=
4
)
else
:
assert
(
"
You
'
re not using the user information
"
)
question
=
raw_input
(
"
Are you sure you don
'
t want to load user
'
s belief information?
"
)
plot_game_performance_path
=
""
plot_game_performance_path
=
""
plot_
robo
t_assistance_path
=
""
plot_
agen
t_assistance_path
=
""
episodes_path
=
"
episodes.npy
"
episodes_path
=
"
episodes.npy
"
if
bn_model_other_user_action
!=
None
:
if
bn_model_other_user_action
!=
None
:
plot_game_performance_path
=
"
game_performance_
"
+
"
_epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
plot_game_performance_path
=
"
game_performance_
"
+
"
_epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
plot_
robo
t_assistance_path
=
"
robo
t_assistance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
plot_
agen
t_assistance_path
=
"
agen
t_assistance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
plot_
robo
t_feedback_path
=
"
robo
t_feedback_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
plot_
agen
t_feedback_path
=
"
agen
t_feedback_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_real_user_memory_
"
+
str
(
real_user_memory
)
+
"
_real_user_attention_
"
+
str
(
real_user_attention
)
+
"
_real_user_reactivity_
"
+
str
(
real_user_reactivity
)
+
"
.jpg
"
else
:
else
:
plot_game_performance_path
=
"
game_performance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
plot_game_performance_path
=
"
game_performance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
plot_
robo
t_assistance_path
=
"
robo
t_assistance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
plot_
agen
t_assistance_path
=
"
agen
t_assistance_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
plot_
robo
t_feedback_path
=
"
robo
t_feedback_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
plot_
agen
t_feedback_path
=
"
agen
t_feedback_
"
+
"
epoch_
"
+
str
(
epochs
)
+
"
_persona_memory_
"
+
str
(
persona_memory
)
+
"
_persona_attention_
"
+
str
(
persona_attention
)
+
"
_persona_reactivity_
"
+
str
(
persona_reactivity
)
+
"
.jpg
"
dir_name
=
input
(
"
Please insert the name of the directory:
"
)
dir_name
=
input
(
"
Please insert the name of the directory:
"
)
full_path
=
os
.
getcwd
()
+
"
/results/
"
+
dir_name
+
"
/
"
full_path
=
os
.
getcwd
()
+
"
/results/
"
+
dir_name
+
"
/
"
...
@@ -430,8 +454,8 @@ with open(full_path+episodes_path, "ab") as f:
...
@@ -430,8 +454,8 @@ with open(full_path+episodes_path, "ab") as f:
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_
robo
t_assistance_path
,
epochs
,
robo
t_assistance_per_episode
)
utils
.
plot2D_assistance
(
full_path
+
plot_
agen
t_assistance_path
,
epochs
,
agen
t_assistance_per_episode
)
utils
.
plot2D_feedback
(
full_path
+
plot_
robo
t_feedback_path
,
epochs
,
robo
t_feedback_per_episode
)
utils
.
plot2D_feedback
(
full_path
+
plot_
agen
t_feedback_path
,
epochs
,
agen
t_feedback_per_episode
)
...
@@ -443,7 +467,7 @@ the episodes will be used to generate the trans probabilities and as input to th
...
@@ -443,7 +467,7 @@ the episodes will be used to generate the trans probabilities and as input to th
# - include reaction time as output
# - include reaction time as output
# - average mistakes, average timeout, average assistance, average_react_time
# - average mistakes, average timeout, average assistance, average_react_time
# - include real time episodes into the simulation:
# - include real time episodes into the simulation:
# - counters for
robo
t_assistance,
robo
t_feedback, attempt, game_state, attention and reactivity
# - counters for
agen
t_assistance,
agen
t_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
# - 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