MCPcopy Create free account
hub / github.com/rlcode/reinforcement-learning / PolicyEnv

Class PolicyEnv

1-grid-world/env.py:242–265  ·  view source on GitHub ↗

Pure-data MDP for policy/value iteration. state = [row, col].

Source from the content-addressed store, hash-verified

240
241# ---------------------------------------------------------------------------
242class PolicyEnv:
243 """Pure-data MDP for policy/value iteration. state = [row, col]."""
244 transition_probability = 1
245 possible_actions = [0, 1, 2, 3]
246
247 def __init__(self):
248 self.width, self.height = WIDTH, HEIGHT
249 self.reward = [[0.0] * WIDTH for _ in range(HEIGHT)]
250 self.reward[2][2], self.reward[1][2], self.reward[2][1] = 1.0, -1.0, -1.0
251 self.all_state = [[x, y] for x in range(WIDTH) for y in range(HEIGHT)]
252
253 def get_all_states(self):
254 return self.all_state
255
256 def state_after_action(self, state, action):
257 dx, dy = DP_ACTIONS[action]
258 return [max(0, min(WIDTH - 1, state[0] + dx)), max(0, min(HEIGHT - 1, state[1] + dy))]
259
260 def get_reward(self, state, action):
261 ns = self.state_after_action(state, action)
262 return self.reward[ns[0]][ns[1]]
263
264 def get_transition_prob(self, state, action):
265 return self.transition_probability
266
267
268# ---------------------------------------------------------------------------

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected