Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
pymdptoolbox
Commits
ff3cabc0
Commit
ff3cabc0
authored
Jan 24, 2013
by
Steven Cordwell
Browse files
change behaivour of MDP.bellmanOperator
parent
3c514a0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
mdp.py
View file @
ff3cabc0
...
...
@@ -477,10 +477,10 @@ class MDP(object):
# Which way is better? if choose the first way, then the classes that
# call this function must be changed
# 1. Return, (policy, value)
#
return (Q.argmax(axis=1), Q.max(axis=1))
return
(
Q
.
argmax
(
axis
=
1
),
Q
.
max
(
axis
=
1
))
# 2. update self.policy and self.value directly
self
.
value
=
Q
.
max
(
axis
=
1
)
self
.
policy
=
Q
.
argmax
(
axis
=
1
)
#
self.value = Q.max(axis=1)
#
self.policy = Q.argmax(axis=1)
def
computePpolicyPRpolicy
(
self
):
"""Computes the transition matrix and the reward matrix for a policy
...
...
@@ -915,18 +915,17 @@ class PolicyIteration(MDP):
elif
self
.
eval_type
==
"iterative"
:
self
.
evalPolicyIterative
()
policy_prev
=
self
.
policy
# This should update the classes policy attribute but leave the
# value alone
self
.
bellmanOperator
()
policy_next
,
null
=
self
.
bellmanOperator
()
del
null
n_different
=
(
self
.
policy
!=
policy
_prev
).
sum
()
n_different
=
(
policy
_next
!=
self
.
policy
).
sum
()
if
self
.
verbose
:
print
(
' %s %s'
)
%
(
self
.
iter
,
n_different
)
if
(
self
.
policy
==
policy
_prev
).
all
()
or
(
self
.
iter
==
self
.
max_iter
):
if
(
policy
_next
==
self
.
policy
).
all
()
or
(
self
.
iter
==
self
.
max_iter
):
done
=
True
self
.
time
=
time
()
-
self
.
time
...
...
@@ -1451,8 +1450,8 @@ class ValueIteration(MDP):
Vprev
=
self
.
value
# Bellman Operator:
updates "self.value" and "self.policy"
self
.
bellmanOperator
()
# Bellman Operator:
compute policy and value functions
self
.
policy
,
self
.
value
=
self
.
bellmanOperator
()
# The values, based on Q. For the function "max()": the option
# "axis" means the axis along which to operate. In this case it
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment