garage._functions

Functions exposed directly in the garage namespace.

make_optimizer(optimizer_type, module=None, **kwargs)

Create an optimizer for pyTorch & tensorflow algos.

Parameters:
  • optimizer_type (Union[type, tuple[type, dict]]) – Type of optimizer. This can be an optimizer type such as ‘torch.optim.Adam’ or a tuple of type and dictionary, where dictionary contains arguments to initialize the optimizer e.g. (torch.optim.Adam, {‘lr’ : 1e-3})
  • module (optional) – If the optimizer type is a torch.optimizer. The torch.nn.Module module whose parameters needs to be optimized must be specify.
  • kwargs (dict) – Other keyword arguments to initialize optimizer. This is not used when optimizer_type is tuple.
Returns:

Constructed optimizer.

Return type:

torch.optim.Optimizer

Raises:

ValueError – Raises value error when optimizer_type is tuple, and non-default argument is passed in kwargs.

log_multitask_performance(itr, batch, discount, name_map=None)

Log performance of episodes from multiple tasks.

Parameters:
  • itr (int) – Iteration number to be logged.
  • batch (EpisodeBatch) – Batch of episodes. The episodes should have either the “task_name” or “task_id” env_infos. If the “task_name” is not present, then name_map is required, and should map from task id’s to task names.
  • discount (float) – Discount used in computing returns.
  • name_map (dict[int, str] or None) – Mapping from task id’s to task names. Optional if the “task_name” environment info is present. Note that if provided, all tasks listed in this map will be logged, even if there are no episodes present for them.
Returns:

Undiscounted returns averaged across all tasks. Has

shape \((N \bullet [T])\).

Return type:

numpy.ndarray

log_performance(itr, batch, discount, prefix='Evaluation')

Evaluate the performance of an algorithm on a batch of episodes.

Parameters:
  • itr (int) – Iteration number.
  • batch (EpisodeBatch) – The episodes to evaluate with.
  • discount (float) – Discount value, from algorithm’s property.
  • prefix (str) – Prefix to add to all logged keys.
Returns:

Undiscounted returns.

Return type:

numpy.ndarray