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
f5ebf036
Commit
f5ebf036
authored
Mar 10, 2014
by
Steven Cordwell
Browse files
PolicyIteration __init__ use assert statements
parent
852347f8
Changes
1
Show whitespace changes
Inline
Side-by-side
src/mdptoolbox/mdp.py
View file @
f5ebf036
...
@@ -518,17 +518,15 @@ class PolicyIteration(MDP):
...
@@ -518,17 +518,15 @@ class PolicyIteration(MDP):
# Make sure it is a numpy array
# Make sure it is a numpy array
policy0
=
array
(
policy0
)
policy0
=
array
(
policy0
)
# Make sure the policy is the right size and shape
# Make sure the policy is the right size and shape
if
not
policy0
.
shape
in
((
self
.
S
,
),
(
self
.
S
,
1
),
(
1
,
self
.
S
)):
assert
policy0
.
shape
in
((
self
.
S
,
),
(
self
.
S
,
1
),
(
1
,
self
.
S
)),
\
raise
ValueError
(
"PyMDPtolbox: policy0 must a vector with "
"'policy0' must a vector with length S."
"length S."
)
# reshape the policy to be a vector
# reshape the policy to be a vector
policy0
=
policy0
.
reshape
(
self
.
S
)
policy0
=
policy0
.
reshape
(
self
.
S
)
# The policy can only contain integers between 1 and S
# The policy can only contain integers between 0 and S-1
if
(
mod
(
policy0
,
1
).
any
()
or
(
policy0
<
0
).
any
()
or
msg
=
"'policy0' must be a vector of integers between 0 and S-1."
(
policy0
>=
self
.
S
).
any
()):
assert
not
mod
(
policy0
,
1
).
any
(),
msg
raise
ValueError
(
"PyMDPtoolbox: policy0 must be a vector of "
assert
(
policy0
>=
0
).
all
(),
msg
"integers between 1 and S."
)
assert
(
policy0
<
self
.
S
).
all
(),
msg
else
:
self
.
policy
=
policy0
self
.
policy
=
policy0
# set the initial values to zero
# set the initial values to zero
self
.
V
=
zeros
(
self
.
S
)
self
.
V
=
zeros
(
self
.
S
)
...
...
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