r""" Update :math:`\mu` and :math:`\Sigma` according to the rewards accrued on the current episode. Returns ------- avg_reward : float The average reward earned by the best `retain_prcnt` theta samples on the current episode.
(self)
| 326 | return total_reward, n_steps |
| 327 | |
| 328 | def update(self): |
| 329 | r""" |
| 330 | Update :math:`\mu` and :math:`\Sigma` according to the rewards accrued on |
| 331 | the current episode. |
| 332 | |
| 333 | Returns |
| 334 | ------- |
| 335 | avg_reward : float |
| 336 | The average reward earned by the best `retain_prcnt` theta samples |
| 337 | on the current episode. |
| 338 | """ |
| 339 | D, P = self.derived_variables, self.parameters |
| 340 | n_retain = int(self.retain_prcnt * self.n_samples_per_episode) |
| 341 | |
| 342 | # sort the cumulative rewards for each theta sample from greatest to least |
| 343 | sorted_y_val_idxs = np.argsort(D["cumulative_rewards"])[::-1] |
| 344 | top_idxs = sorted_y_val_idxs[:n_retain] |
| 345 | |
| 346 | # update theta_mean and theta_var with the best theta value |
| 347 | P["theta_mean"] = np.mean(D["theta_samples"][top_idxs], axis=0) |
| 348 | P["theta_var"] = np.var(D["theta_samples"][top_idxs], axis=0) |
| 349 | |
| 350 | def _sample_thetas(self): |
| 351 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected