garage.torch.value_functions package

Value functions which use PyTorch.

class ValueFunction(env_spec, name)[source]

Bases: abc.ABC, sphinx.ext.autodoc.importer._MockObject

Base class for all baselines.

Parameters:
compute_loss(obs, returns)[source]

Compute mean value of loss.

Parameters:
  • obs (torch.Tensor) – Observation from the environment with shape \((N \dot [T], O*)\).
  • returns (torch.Tensor) – Acquired returns with shape \((N, )\).
Returns:

Calculated negative mean scalar value of

objective (float).

Return type:

torch.Tensor

class GaussianMLPValueFunction(env_spec, hidden_sizes=(32, 32), hidden_nonlinearity=<sphinx.ext.autodoc.importer._MockObject object>, hidden_w_init=<sphinx.ext.autodoc.importer._MockObject object>, hidden_b_init=<sphinx.ext.autodoc.importer._MockObject object>, output_nonlinearity=None, output_w_init=<sphinx.ext.autodoc.importer._MockObject object>, output_b_init=<sphinx.ext.autodoc.importer._MockObject object>, learn_std=True, init_std=1.0, layer_normalization=False, name='GaussianMLPValueFunction')[source]

Bases: garage.torch.value_functions.value_function.ValueFunction

Gaussian MLP Value Function with Model.

It fits the input data to a gaussian distribution estimated by a MLP.

Parameters:
  • env_spec (garage.envs.env_spec.EnvSpec) – Environment specification.
  • hidden_sizes (list[int]) – Output dimension of dense layer(s) for the MLP for mean. 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 torch.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 torch.Tensor.
  • hidden_b_init (callable) – Initializer function for the bias of intermediate dense layer(s). The function should return a torch.Tensor.
  • output_nonlinearity (callable) – Activation function for output dense layer. It should return a torch.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 torch.Tensor.
  • output_b_init (callable) – Initializer function for the bias of output dense layer(s). The function should return a torch.Tensor.
  • learn_std (bool) – Is std trainable.
  • init_std (float) – Initial value for std. (plain value - not log or exponentiated).
  • layer_normalization (bool) – Bool for using layer normalization or not.
  • name (str) – The name of the value function.
compute_loss(obs, returns)[source]

Compute mean value of loss.

Parameters:
  • obs (torch.Tensor) – Observation from the environment with shape \((N \dot [T], O*)\).
  • returns (torch.Tensor) – Acquired returns with shape \((N, )\).
Returns:

Calculated negative mean scalar value of

objective (float).

Return type:

torch.Tensor

forward(obs)[source]

Predict value based on paths.

Parameters:obs (torch.Tensor) – Observation from the environment with shape \((P, O*)\).
Returns:
Calculated baselines given observations with
shape \((P, O*)\).
Return type:torch.Tensor