Fix division by zero in ValueIteration._boundIter
#32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mdp.ValueIteration
usesValueIteration._boundIter
to setself.max_iter
for discounted MDPs. This is based on the span: the difference between the minimum and maximum values after one step of the Bellman operator.The problem is for some MDPs the value can be identical for all states after a single application of the Bellman operator. This happens when$R(s,a)$ is equal to $Q(s,a)$ -- not common, but it does happen (e.g. any MDP with an all-zero reward is a degenerate example). In this case,
span
is0
andmax_iter
becomes negative infinity.If my understanding of the bound is correct, in this case we actually don't need to perform any iterations of value iteration -- the all-zero initialisation is OK. So I've added an explicit check that sets
max_iter = 0
in this case avoiding the division by zero. I've also added a regression test for the all-zero MDP.Some doctests are failing but they were failing before. All other tests are passing on my machine.