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

simulate_mdp doesn't like it if you start in a terminal state #2

Closed
fancyfredbot opened this issue May 6, 2024 · 1 comment
Closed

Comments

@fancyfredbot
Copy link

fancyfredbot commented May 6, 2024

If you aren't careful you leave the starting point at 0,0 when you move to cliff world, and then simulate_mdp blows up because you immediately terminate and there are no available actions.

@@ -193,7 +193,7 @@ def simulate_mdp(mdp, policy, max_iterations=20) -> list[Step]:
     steps = []
     state = mdp.start
     current_iteration = 0
-    while True:
+    while current_iteration != max_iterations and not mdp.is_terminal(state) and mdp.is_reachable(state):
         current_iteration += 1
         action = policy(state)
         state_probs = [(s, p) for s, p in mdp.transition(state, action).items()]
@@ -203,9 +203,7 @@ def simulate_mdp(mdp, policy, max_iterations=20) -> list[Step]:
         reward = mdp.reward(state, action, next_state)
         steps.append(Step(state, action, reward))
         state = next_state
-        if current_iteration == max_iterations or mdp.is_terminal(state):
-            steps.append(Step(next_state, None, 0.0))
-            break
+    steps.append(Step(state, None, 0.0))
     return steps
alessiodm pushed a commit that referenced this issue May 7, 2024
simulate_mdp doesn't like it if you start in a terminal state

From #2

```
If you aren't careful you leave the starting point at 0,0 when you move
to cliff world, and then simulate_mdp blows up because you immediately
terminate and there are no available actions.
```
@alessiodm
Copy link
Owner

alessiodm commented May 7, 2024

Thank you very much, great catch. I applied the fix.

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

No branches or pull requests

2 participants