Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division by zero in ValueIteration._boundIter #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AdamGleave
Copy link

@AdamGleave AdamGleave commented Jan 26, 2020

mdp.ValueIteration uses ValueIteration._boundIter to set self.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 is 0 and max_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant