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
2a4988be
Commit
2a4988be
authored
4 years ago
by
Antonio Andriella
Browse files
Options
Downloads
Patches
Plain Diff
add functions to manage more than 1 query variables
parent
de757a6a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bn_functions.py
+56
-22
56 additions, 22 deletions
bn_functions.py
with
56 additions
and
22 deletions
bn_functions.py
+
56
−
22
View file @
2a4988be
...
@@ -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
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