(self, state, action, reward, next_state)
| 15 | |
| 16 | # update q function with sample <s, a, r, s'> |
| 17 | def learn(self, state, action, reward, next_state): |
| 18 | current_q = self.q_table[state][action] |
| 19 | # using Bellman Optimality Equation to update q function |
| 20 | new_q = reward + self.discount_factor * max(self.q_table[next_state]) |
| 21 | self.q_table[state][action] += self.learning_rate * (new_q - current_q) |
| 22 | |
| 23 | # get action for the state according to the q function table |
| 24 | # agent pick action of epsilon-greedy policy |