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","'","."]
code: def __init__(
      self,
      env_spec,
      learner,
      *,
      batch_size,
      source=None,
      sampler=None,
      policy_optimizer=torch.optim.Adam,
      policy_lr=_Default(1e-3),
      loss="log_prob",
      minibatches_per_epoch=16,
      name="BC",
  ):
      self._source = source
      self.learner = learner
      self._optimizer = make_optimizer(
          policy_optimizer, module=self.learner, lr=policy_lr
      )
      if loss not in ("log_prob", "mse"):
          raise ValueError('Loss should be either "log_prob" or "mse".')
      self._loss = loss
      self._minibatches_per_epoch = minibatches_per_epoch
      self._eval_env = None
      self._batch_size = batch_size
      self._name = name
  
      # For plotting
      self.policy = self.learner
  
      # Public fields for sampling.
      self._env_spec = env_spec
      self.exploration_policy = None
      self.policy = None
      self.max_episode_length = env_spec.max_episode_length
      self._sampler = sampler
      if isinstance(self._source, Policy):
          self.exploration_policy = self._source
          self._source = source
          if not isinstance(self._sampler, Sampler):
              raise TypeError("Source is a policy. Missing a sampler.")
      else:
          self._source = itertools.cycle(iter(source))
  
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 1 to create a new BC object from inherited base classes: RLAlgorithm with example: obj = BC(env_spec, learner)