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

Fixes problems in mdp.py #918

Merged
merged 2 commits into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion mdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def check_consistency(self):
assert abs(s - 1) < 0.001


class MDP2(MDP):

"""Inherits from MDP. Handles terminal states, and transitions to and from terminal states better."""
def __init__(self, init, actlist, terminals, transitions, reward=None, gamma=0.9):
MDP.__init__(self, init, actlist, terminals, transitions, reward, gamma=gamma)

def T(self, state, action):
if action is None:
return [(0.0, state)]
else:
return self.transitions[state][action]


class GridMDP(MDP):

"""A two-dimensional grid MDP, as in [Figure 17.1]. All you have to do is
Expand Down Expand Up @@ -186,7 +199,7 @@ def value_iteration(mdp, epsilon=0.001):
U1[s] = R(s) + gamma * max(sum(p*U[s1] for (p, s1) in T(s, a))
for a in mdp.actions(s))
delta = max(delta, abs(U1[s] - U[s]))
if delta < epsilon*(1 - gamma)/gamma:
if delta <= epsilon*(1 - gamma)/gamma:
return U


Expand Down