MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / greedy_policy

Method greedy_policy

numpy_ml/rl_models/agents.py:360–388  ·  view source on GitHub ↗

Execute a greedy policy using the current agent parameters. Parameters ---------- max_steps : int The maximum number of steps to run the episode. render : bool Whether to render the episode during execution. Returns -

(self, max_steps, render=True)

Source from the content-addressed store, hash-verified

358 self.derived_variables["theta_samples"] = samples
359
360 def greedy_policy(self, max_steps, render=True):
361 """
362 Execute a greedy policy using the current agent parameters.
363
364 Parameters
365 ----------
366 max_steps : int
367 The maximum number of steps to run the episode.
368 render : bool
369 Whether to render the episode during execution.
370
371 Returns
372 -------
373 total_reward : float
374 The total reward on the episode.
375 n_steps : float
376 The total number of steps taken on the episode.
377 """
378 E, D, P = self.env_info, self.derived_variables, self.parameters
379 Mu, Sigma = P["theta_mean"], np.diag(P["theta_var"])
380 sample = np.random.multivariate_normal(Mu, Sigma, 1)
381
382 W_len, obs_dim = D["W_len"], E["obs_dim"]
383 n_actions = np.prod(E["n_actions_per_dim"])
384
385 W = sample[0, :W_len].reshape(obs_dim, n_actions)
386 b = sample[0, W_len:]
387 total_reward, n_steps = self._episode(W, b, max_steps, render)
388 return total_reward, n_steps
389
390
391class MonteCarloAgent(AgentBase):

Callers

nothing calls this directly

Calls 1

_episodeMethod · 0.95

Tested by

no test coverage detected