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.GlorotUniform object>, hidden_b_init=<tensorflow.python.ops.init_ops.Zeros object>, output_nonlinearity=<function softmax>, output_w_init=<tensorflow.python.ops.init_ops.GlorotUniform object>, output_b_init=<tensorflow.python.ops.init_ops.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.base.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.
dist_info_sym(x_var, name=None)[source]

Build a symbolic graph of the distribution parameters.

Parameters:
  • x_var (tf.Tensor) – Input tf.Tensor for the input data.
  • name (str) – Name of the new graph.
Returns:

Output of the symbolic graph of the distribution

parameters.

Return type:

dict[tf.Tensor]

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.
get_params_internal(**args)[source]

Get the params, which are the trainable variables.

Parameters:args – Ignored by the function. Will be removed in future release.
Returns:A list of trainable variables in the current variable scope.
Return type:List[tf.Variable]
log_likelihood_sym(x_var, y_var, name=None)[source]

Build a symbolic graph of the log-likelihood.

Parameters:
  • x_var (tf.Tensor) – Input tf.Tensor for the input data.
  • y_var (tf.Tensor) – Input tf.Tensor for the one hot label of data.
  • name (str) – Name of the new graph.
Returns:

Output of the symbolic log-likelihood graph.

Return type:

tf.Tensor

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
predict_log_likelihood(xs, ys)[source]

Predict log-likelihood of output data conditioned on the input data.

Parameters:
  • xs (numpy.ndarray) – Input data.
  • ys (numpy.ndarray) – Output labels in one hot representation.
Returns:

The predicted log likelihoods.

Return type:

numpy.ndarray