garage.tf.policies.categorical_mlp_policy module¶
Categorical MLP Policy.
A policy represented by a Categorical distribution which is parameterized by a multilayer perceptron (MLP).
-
class
CategoricalMLPPolicy
(env_spec, name='CategoricalMLPPolicy', hidden_sizes=(32, 32), hidden_nonlinearity=<function tanh>, hidden_w_init=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, hidden_b_init=<tensorflow.python.ops.init_ops_v2.Zeros object>, output_nonlinearity=None, output_w_init=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, output_b_init=<tensorflow.python.ops.init_ops_v2.Zeros object>, layer_normalization=False)[source]¶ Bases:
garage.tf.policies.policy.StochasticPolicy
Categorical MLP Policy.
A policy represented by a Categorical distribution which is parameterized by a multilayer perceptron (MLP).
It only works with akro.Discrete action space.
Parameters: - env_spec (garage.envs.env_spec.EnvSpec) – Environment specification.
- name (str) – Policy name, also the variable scope.
- hidden_sizes (list[int]) – Output dimension of dense layer(s). For example, (32, 32) means the MLP of this policy consists of two hidden layers, each with 32 hidden units.
- hidden_nonlinearity (callable) – Activation function for intermediate dense layer(s). It should return a tf.Tensor. Set it to None to maintain a linear activation.
- hidden_w_init (callable) – Initializer function for the weight of intermediate dense layer(s). The function should return a tf.Tensor.
- hidden_b_init (callable) – Initializer function for the bias of intermediate dense layer(s). The function should return a tf.Tensor.
- output_nonlinearity (callable) – Activation function for output dense layer. It should return a tf.Tensor. Set it to None to maintain a linear activation.
- output_w_init (callable) – Initializer function for the weight of output dense layer(s). The function should return a tf.Tensor.
- output_b_init (callable) – Initializer function for the bias of output dense layer(s). The function should return a tf.Tensor.
- layer_normalization (bool) – Bool for using layer normalization or not.
-
build
(state_input, name=None)[source]¶ Build policy.
Parameters: - state_input (tf.Tensor) – State input.
- name (str) – Name of the policy, which is also the name scope.
Returns: Policy distribution.
Return type: tfp.distributions.OneHotCategorical
-
clone
(name)[source]¶ Return a clone of the policy.
It only copies the configuration of the primitive, not the parameters.
Parameters: name (str) – Name of the newly created policy. It has to be different from source policy if cloned under the same computational graph. Returns: Newly cloned policy. Return type: garage.tf.policies.Policy
-
distribution
¶ Policy distribution.
Returns: Policy distribution. Return type: tfp.Distribution.OneHotCategorical
-
get_action
(observation)[source]¶ Return a single action.
Parameters: observation (numpy.ndarray) – Observations. Returns: Action given input observation. dict(numpy.ndarray): Distribution parameters. Return type: int
-
get_actions
(observations)[source]¶ Return multiple actions.
Parameters: observations (numpy.ndarray) – Observations. Returns: Actions given input observations. dict(numpy.ndarray): Distribution parameters. Return type: list[int]
-
get_regularizable_vars
()[source]¶ Get regularizable weight variables under the Policy scope.
Returns: Trainable variables. Return type: list[tf.Tensor]
-
vectorized
¶ Vectorized or not.
Returns: True if primitive supports vectorized operations. Return type: Bool