Commit f5ebf036 authored by Steven Cordwell's avatar Steven Cordwell
Browse files

PolicyIteration __init__ use assert statements

parent 852347f8
...@@ -518,18 +518,16 @@ class PolicyIteration(MDP): ...@@ -518,18 +518,16 @@ 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)
# Do some setup depending on the evaluation type # Do some setup depending on the evaluation type
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment