Execute a deterministic greedy policy using the current agent parameters. Parameters ---------- max_steps : int The maximum number of steps to run the episode. render : bool Whether to render the episode during execution.
(self, max_steps, render=True)
| 1252 | return self.behavior_policy(s) |
| 1253 | |
| 1254 | def greedy_policy(self, max_steps, render=True): |
| 1255 | """ |
| 1256 | Execute a deterministic greedy policy using the current agent |
| 1257 | parameters. |
| 1258 | |
| 1259 | Parameters |
| 1260 | ---------- |
| 1261 | max_steps : int |
| 1262 | The maximum number of steps to run the episode. |
| 1263 | render : bool |
| 1264 | Whether to render the episode during execution. |
| 1265 | |
| 1266 | Returns |
| 1267 | ------- |
| 1268 | total_reward : float |
| 1269 | The total reward on the episode. |
| 1270 | n_steps : float |
| 1271 | The total number of steps taken on the episode. |
| 1272 | """ |
| 1273 | self.flush_history() |
| 1274 | |
| 1275 | H = self.episode_history |
| 1276 | obs = self.env.reset() |
| 1277 | |
| 1278 | total_reward, n_steps = 0.0, 0 |
| 1279 | for i in range(max_steps): |
| 1280 | if render: |
| 1281 | self.env.render() |
| 1282 | |
| 1283 | s = self._obs2num[obs] |
| 1284 | action = self._greedy(s) |
| 1285 | a = self._action2num[action] |
| 1286 | |
| 1287 | # store (state, action) tuple |
| 1288 | H["state_actions"].append((s, a)) |
| 1289 | |
| 1290 | # take action |
| 1291 | obs, reward, done, info = self.env.step(action) |
| 1292 | n_steps += 1 |
| 1293 | |
| 1294 | # record rewards |
| 1295 | H["rewards"].append(reward) |
| 1296 | total_reward += reward |
| 1297 | |
| 1298 | if done: |
| 1299 | break |
| 1300 | |
| 1301 | return total_reward, n_steps |
| 1302 | |
| 1303 | |
| 1304 | class DynaAgent(AgentBase): |
nothing calls this directly
no test coverage detected