A greedy behavior policy. Only used when off-policy is true. 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 a
(self, s, a=None)
| 1117 | return self._num2action[a] |
| 1118 | |
| 1119 | def _greedy(self, s, a=None): |
| 1120 | """ |
| 1121 | A greedy behavior policy. Only used when off-policy is true. |
| 1122 | |
| 1123 | Parameters |
| 1124 | ---------- |
| 1125 | s : int, float, or tuple |
| 1126 | The state number for the current observation, as returned by |
| 1127 | ``self._obs2num[obs]`` |
| 1128 | a : int, float, or tuple |
| 1129 | The action number in the current state, as returned by |
| 1130 | ``self._action2num[obs]``. If None, sample an action from the |
| 1131 | action probabilities in state `s`, otherwise, return the |
| 1132 | probability of action `a` under the greedy policy. Default is None. |
| 1133 | |
| 1134 | Returns |
| 1135 | ------- |
| 1136 | If `a` is None: |
| 1137 | action : int, float, or :py:class:`ndarray <numpy.ndarray>` as returned by ``self._num2action`` |
| 1138 | If `a` is None, returns an action sampled from the distribution |
| 1139 | over actions defined by the greedy policy. |
| 1140 | |
| 1141 | If `a` is not None: |
| 1142 | action_prob : float in range [0, 1] |
| 1143 | If `a` is not None, returns the probability of `a` under the |
| 1144 | greedy policy. |
| 1145 | """ # noqa: E501 |
| 1146 | P, E = self.parameters, self.env_info |
| 1147 | n_actions = np.prod(E["n_actions_per_dim"]) |
| 1148 | a_star = np.argmax([P["Q"][(s, aa)] for aa in range(n_actions)]) |
| 1149 | if a is None: |
| 1150 | out = self._num2action[a_star] |
| 1151 | else: |
| 1152 | out = 1 if a == a_star else 0 |
| 1153 | return out |
| 1154 | |
| 1155 | def _on_policy_update(self, s, a, r, s_, a_): |
| 1156 | """ |