| 85 | self.models[a].partial_fit(X, [G]) |
| 86 | |
| 87 | def sample_action(self, s, eps): |
| 88 | # eps = 0 |
| 89 | # Technically, we don't need to do epsilon-greedy |
| 90 | # because SGDRegressor predicts 0 for all states |
| 91 | # until they are updated. This works as the |
| 92 | # "Optimistic Initial Values" method, since all |
| 93 | # the rewards for Mountain Car are -1. |
| 94 | if np.random.random() < eps: |
| 95 | return self.env.action_space.sample() |
| 96 | else: |
| 97 | return np.argmax(self.predict(s)) |
| 98 | |
| 99 | |
| 100 | # returns a list of states_and_rewards, and the total reward |