A greedy behavior policy. Parameters ---------- s : int, float, or tuple The state number for the current observation, as returned by self._obs2num[obs] a : int, float, or tuple The action number in the current state, as r
(self, s, a=None)
| 1562 | return self._num2action[a] |
| 1563 | |
| 1564 | def _greedy(self, s, a=None): |
| 1565 | """ |
| 1566 | A greedy behavior policy. |
| 1567 | |
| 1568 | Parameters |
| 1569 | ---------- |
| 1570 | s : int, float, or tuple |
| 1571 | The state number for the current observation, as returned by |
| 1572 | self._obs2num[obs] |
| 1573 | a : int, float, or tuple |
| 1574 | The action number in the current state, as returned by |
| 1575 | self._action2num[obs]. If None, sample an action from the action |
| 1576 | probabilities in state s, otherwise, return the probability of |
| 1577 | action `a` under the greedy policy. Default is None. |
| 1578 | |
| 1579 | Returns |
| 1580 | ------- |
| 1581 | If `a` is None: |
| 1582 | action : int, float, or :py:class:`ndarray <numpy.ndarray>` as returned by :meth:`_num2action` |
| 1583 | If `a` is None, returns an action sampled from the distribution |
| 1584 | over actions defined by the greedy policy. |
| 1585 | |
| 1586 | If `a` is not None: |
| 1587 | action_prob : float in range [0, 1] |
| 1588 | If `a` is not None, returns the probability of `a` under the |
| 1589 | greedy policy. |
| 1590 | """ # noqa: E501 |
| 1591 | E, Q = self.env_info, self.parameters["Q"] |
| 1592 | n_actions = np.prod(E["n_actions_per_dim"]) |
| 1593 | a_star = np.argmax([Q[(s, aa)] for aa in range(n_actions)]) |
| 1594 | if a is None: |
| 1595 | out = self._num2action[a_star] |
| 1596 | else: |
| 1597 | out = 1 if a == a_star else 0 |
| 1598 | return out |
| 1599 | |
| 1600 | def update(self): |
| 1601 | """ |