garage.torch.policies.stochastic_policy
¶
Base Stochastic Policy.
- class StochasticPolicy(env_spec, name)¶
Bases:
garage.torch.policies.policy.Policy
,abc.ABC
Abstract base class for torch stochastic policies.
- property env_spec¶
Policy environment specification.
- Returns
Environment specification.
- Return type
- property observation_space¶
Observation space.
- Returns
The observation space of the environment.
- Return type
akro.Space
- property action_space¶
Action space.
- Returns
The action space of the environment.
- Return type
akro.Space
- get_action(observation)¶
Get a single action given an observation.
- Parameters
observation (np.ndarray) – Observation from the environment. Shape is \(env_spec.observation_space\).
- Returns
- np.ndarray: Predicted action. Shape is
\(env_spec.action_space\).
- dict:
np.ndarray[float]: Mean of the distribution
- np.ndarray[float]: Standard deviation of logarithmic
values of the distribution.
- Return type
- get_actions(observations)¶
Get actions given observations.
- Parameters
observations (np.ndarray) – Observations from the environment. Shape is \(batch_dim \bullet env_spec.observation_space\).
- Returns
- np.ndarray: Predicted actions.
\(batch_dim \bullet env_spec.action_space\).
- dict:
np.ndarray[float]: Mean of the distribution.
- np.ndarray[float]: Standard deviation of logarithmic
values of the distribution.
- Return type
- abstract forward(observations)¶
Compute the action distributions from the observations.
- Parameters
observations (torch.Tensor) – Batch of observations on default torch device.
- Returns
Batch distribution of actions. dict[str, torch.Tensor]: Additional agent_info, as torch Tensors.
Do not need to be detached, and can be on any device.
- Return type
torch.distributions.Distribution
- get_param_values()¶
Get the parameters to the policy.
This method is included to ensure consistency with TF policies.
- Returns
The parameters (in the form of the state dictionary).
- Return type
- set_param_values(state_dict)¶
Set the parameters to the policy.
This method is included to ensure consistency with TF policies.
- Parameters
state_dict (dict) – State dictionary.
- reset(do_resets=None)¶
Reset the policy.
This is effective only to recurrent policies.
do_resets is an array of boolean indicating which internal states to be reset. The length of do_resets should be equal to the length of inputs, i.e. batch size.
- Parameters
do_resets (numpy.ndarray) – Bool array indicating which states to be reset.