garage.tf.regressors.categorical_mlp_regressor module

A regressor based on MLP with Normalized Inputs.

class CategoricalMLPRegressor(input_shape, output_dim, name='CategoricalMLPRegressor', 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=<function softmax_v2>, output_w_init=<tensorflow.python.ops.init_ops_v2.GlorotUniform object>, output_b_init=<tensorflow.python.ops.init_ops_v2.Zeros object>, optimizer=None, optimizer_args=None, tr_optimizer=None, tr_optimizer_args=None, use_trust_region=True, max_kl_step=0.01, normalize_inputs=True, layer_normalization=False)[source]

Bases: garage.tf.regressors.regressor.StochasticRegressor

Fits data to a Categorical with parameters are the output of an MLP.

A class for performing regression (or classification, really) by fitting a Categorical distribution to the outputs. Assumes that the output will always be a one hot vector

Parameters:
  • input_shape (tuple[int]) – Input shape of the training data. Since an MLP model is used, implementation assumes flattened inputs. The input shape of each data point should thus be of shape (x, ).
  • output_dim (int) – Output dimension of the model.
  • name (str) – Model name, also the variable scope.
  • hidden_sizes (list[int]) – Output dimension of dense layer(s) for the MLP for the network. For example, (32, 32) means the MLP 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 tanh activation.
  • hidden_w_init (Callable) – Initializer function for the weight of intermediate dense layer(s). The function should return a tf.Tensor. Default is Glorot uniform initializer.
  • hidden_b_init (Callable) – Initializer function for the bias of intermediate dense layer(s). The function should return a tf.Tensor. Default is zero initializer.
  • output_nonlinearity (Callable) – Activation function for output dense layer. It should return a tf.Tensor. Set it to None to maintain a softmax activation.
  • output_w_init (Callable) – Initializer function for the weight of output dense layer(s). The function should return a tf.Tensor. Default is Glorot uniform initializer.
  • output_b_init (Callable) – Initializer function for the bias of output dense layer(s). The function should return a tf.Tensor. Default is zero initializer.
  • optimizer (garage.tf.Optimizer) – Optimizer for minimizing the negative log-likelihood. Defaults to LbsgsOptimizer
  • optimizer_args (dict) – Arguments for the optimizer. Default is None, which means no arguments.
  • tr_optimizer (garage.tf.Optimizer) – Optimizer for trust region approximation. Defaults to ConjugateGradientOptimizer.
  • tr_optimizer_args (dict) – Arguments for the trust region optimizer. Default is None, which means no arguments.
  • use_trust_region (bool) – Whether to use trust region constraint.
  • max_kl_step (float) – KL divergence constraint for each iteration.
  • normalize_inputs (bool) – Bool for normalizing inputs or not.
  • layer_normalization (bool) – Bool for using layer normalization or not.
distribution

Distribution.

Type:garage.tf.distributions.DiagonalGaussian
fit(xs, ys)[source]

Fit with input data xs and label ys.

Parameters:
  • xs (numpy.ndarray) – Input data.
  • ys (numpy.ndarray) – Label of input data.
predict(xs)[source]

Predict ys based on input xs.

Parameters:xs (numpy.ndarray) – Input data.
Returns:The predicted ys (one hot vectors).
Return type:numpy.ndarray
recurrent

If this module has a hidden state.

Type:bool
vectorized

If this module supports vectorization input.

Type:bool