class_docstr: Behavioral Cloning.
  
  Based on Model-Free Imitation Learning with Policy Optimization:
      https://arxiv.org/abs/1605.08478
  
  Args:
      env_spec (EnvSpec): Specification of environment.
      learner (garage.torch.Policy): Policy to train.
      batch_size (int): Size of optimization batch.
      source (Policy or Generator[TimeStepBatch]): Expert to clone. If a
          policy is passed, will set `.policy` to source and use the trainer
          to sample from the policy.
      sampler (garage.sampler.Sampler): Sampler. If source is a policy, a
          sampler is required for sampling.
      policy_optimizer (torch.optim.Optimizer): Optimizer to be used to
          optimize the policy.
      policy_lr (float): Learning rate of the policy optimizer.
      loss (str): Which loss function to use. Must be either 'log_prob' or
          'mse'. If set to 'log_prob' (the default), `learner` must be a
          `garage.torch.StochasticPolicy`.
      minibatches_per_epoch (int): Number of minibatches per epoch.
      name (str): Name to use for logging.
  
  Raises:
      ValueError: If learner` is not a
          `garage.torch.StochasticPolicy` and loss is 'log_prob'.
class_docstr_tok: ["Behavioral","Cloning",".","Based","on","Model-Free","Imitation","Learning","with","Policy","Optimization",":","https",":","\/\/arxiv.org\/abs\/1605.08478","Args",":","env_spec","(","EnvSpec",")",":","Specification","of","environment",".","learner","(","garage.torch.Policy",")",":","Policy","to","train",".","batch_size","(","int",")",":","Size","of","optimization","batch",".","source","(","Policy","or","Generator","[","TimeStepBatch","]",")",":","Expert","to","clone",".","If","a","policy","is","passed",",","will","set","`",".policy","`","to","source","and","use","the","trainer","to","sample","from","the","policy",".","sampler","(","garage.sampler.Sampler",")",":","Sampler",".","If","source","is","a","policy",",","a","sampler","is","required","for","sampling",".","policy_optimizer","(","torch.optim.Optimizer",")",":","Optimizer","to","be","used","to","optimize","the","policy",".","policy_lr","(","float",")",":","Learning","rate","of","the","policy","optimizer",".","loss","(","str",")",":","Which","loss","function","to","use",".","Must","be","either","'log_prob","'","or","'mse","'",".","If","set","to","'log_prob","'","(","the","default",")",",","`","learner","`","must","be","a","`","garage.torch.StochasticPolicy","`",".","minibatches_per_epoch","(","int",")",":","Number","of","minibatches","per","epoch",".","name","(","str",")",":","Name","to","use","for","logging",".","Raises",":","ValueError",":","If","learner","`","is","not","a","`","garage.torch.StochasticPolicy","`","and","loss","is","'log_prob","'","."]
docstr: Compute loss of self._learner on the expert_actions.
  
  Args:
      observations (torch.Tensor): Observations used to select actions.
          Has shape :math:`(B, O^*)`, where :math:`B` is the batch
          dimension and :math:`O^*` are the observation dimensions.
      expert_actions (torch.Tensor): The actions of the expert.
          Has shape :math:`(B, A^*)`, where :math:`B` is the batch
          dimension and :math:`A^*` are the action dimensions.
  
  Returns:
      torch.Tensor: The loss through which gradient can be propagated
          back to the learner. Depends on self._loss.
docstr_tok: ["Compute","loss","of","self._learner","on","the","expert_actions",".","Args",":","observations","(","torch.Tensor",")",":","Observations","used","to","select","actions",".","Has","shape",":","math",":","`","(","B",",","O^","*",")","`",",","where",":","math",":","`","B","`","is","the","batch","dimension","and",":","math",":","`","O^","*","`","are","the","observation","dimensions",".","expert_actions","(","torch.Tensor",")",":","The","actions","of","the","expert",".","Has","shape",":","math",":","`","(","B",",","A^","*",")","`",",","where",":","math",":","`","B","`","is","the","batch","dimension","and",":","math",":","`","A^","*","`","are","the","action","dimensions",".","Returns",":","torch.Tensor",":","The","loss","through","which","gradient","can","be","propagated","back","to","the","learner",".","Depends","on","self._loss","."]
code: def _compute_loss(self, observations, expert_actions):
      """Compute loss of self._learner on the expert_actions.
  
      Args:
          observations (torch.Tensor): Observations used to select actions.
              Has shape :math:`(B, O^*)`, where :math:`B` is the batch
              dimension and :math:`O^*` are the observation dimensions.
          expert_actions (torch.Tensor): The actions of the expert.
              Has shape :math:`(B, A^*)`, where :math:`B` is the batch
              dimension and :math:`A^*` are the action dimensions.
  
      Returns:
          torch.Tensor: The loss through which gradient can be propagated
              back to the learner. Depends on self._loss.
  
      """
      learner_output = self.learner(observations)
      if self._loss == "mse":
          if isinstance(learner_output, torch.Tensor):
              # We must have a deterministic policy as the learner.
              learner_actions = learner_output
          else:
              # We must have a StochasticPolicy as the learner.
              action_dist, _ = learner_output
              learner_actions = action_dist.rsample()
          return torch.mean((expert_actions - learner_actions) ** 2)
      else:
          assert self._loss == "log_prob"
          # We already checked that we have a StochasticPolicy as the learner
          action_dist, _ = learner_output
          return -torch.mean(action_dist.log_prob(expert_actions))
  
file_path: garage/src/garage/torch/algos/bc.py
imports: import itertools
  from dowel import tabular
  import numpy
  import torch
  from garage import _Default, log_performance, make_optimizer, obtain_evaluation_episodes, TimeStepBatch
  from garage.np.algos.rl_algorithm import RLAlgorithm
  from garage.np.policies import Policy
  from garage.sampler import Sampler
  from garage.torch import np_to_torch
label_desc: Use image node_id 5 for calling the BC obj's underlying member method code with example usage: obj._compute_loss(observations, expert_actions) and returns: torch, unknown