garage.tf.policies.categorical_cnn_policy module¶
Categorical CNN Policy.
A policy represented by a Categorical distribution which is parameterized by a convolutional neural network (CNN) followed a multilayer perceptron (MLP).
-
class
CategoricalCNNPolicy
(env_spec, filters, strides, padding, name='CategoricalCNNPolicy', hidden_sizes=(32, 32), hidden_nonlinearity=<function relu>, 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
CategoricalCNNPolicy.
A policy that contains a CNN and a MLP to make prediction based on a categorical distribution.
It only works with akro.Discrete action space.
Parameters: - env_spec (garage.envs.env_spec.EnvSpec) – Environment specification.
- filters (Tuple[Tuple[int, Tuple[int, int]], ..]) – Number and dimension of filters. For example, ((3, (3, 5)), (32, (3, 3))) means there are two convolutional layers. The filter for the first layer have 3 channels and its shape is (3 x 5), while the filter for the second layer have 32 channels and its shape is (3 x 3).
- strides (tuple[int]) – The stride of the sliding window. For example, (1, 2) means there are two convolutional layers. The stride of the filter for first layer is 1 and that of the second layer is 2.
- padding (str) – The type of padding algorithm to use, either ‘SAME’ or ‘VALID’.
- name (str) – Policy name, also the variable scope of the policy.
- 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.CategoricalCNNPolicy
-
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