class_docstr: A policy that outputs actions based on observation and latent context.
  
  In PEARL, policies are conditioned on current state and a latent context
  (adaptation data) variable Z. This inference network estimates the
  posterior probability of z given past transitions. It uses context
  information stored in the encoder to infer the probabilistic value of z and
  samples from a policy conditioned on z.
  
  Args:
      latent_dim (int): Latent context variable dimension.
      context_encoder (garage.torch.embeddings.ContextEncoder): Recurrent or
          permutation-invariant context encoder.
      policy (garage.torch.policies.Policy): Policy used to train the
          network.
      use_information_bottleneck (bool): True if latent context is not
          deterministic; false otherwise.
      use_next_obs (bool): True if next observation is used in context
          for distinguishing tasks; false otherwise.
class_docstr_tok: ["A","policy","that","outputs","actions","based","on","observation","and","latent","context",".","In","PEARL",",","policies","are","conditioned","on","current","state","and","a","latent","context","(","adaptation","data",")","variable","Z",".","This","inference","network","estimates","the","posterior","probability","of","z","given","past","transitions",".","It","uses","context","information","stored","in","the","encoder","to","infer","the","probabilistic","value","of","z","and","samples","from","a","policy","conditioned","on","z.","Args",":","latent_dim","(","int",")",":","Latent","context","variable","dimension",".","context_encoder","(","garage.torch.embeddings.ContextEncoder",")",":","Recurrent","or","permutation-invariant","context","encoder",".","policy","(","garage.torch.policies.Policy",")",":","Policy","used","to","train","the","network",".","use_information_bottleneck","(","bool",")",":","True","if","latent","context","is","not","deterministic",";","false","otherwise",".","use_next_obs","(","bool",")",":","True","if","next","observation","is","used","in","context","for","distinguishing","tasks",";","false","otherwise","."]
docstr: Append single transition to the current context.
  
  Args:
      timestep (garage._dtypes.TimeStep): Timestep containing transition
          information to be added to context.
docstr_tok: ["Append","single","transition","to","the","current","context",".","Args",":","timestep","(","garage._dtypes.TimeStep",")",":","Timestep","containing","transition","information","to","be","added","to","context","."]
code: def update_context(self, timestep):
      """Append single transition to the current context.
  
      Args:
          timestep (garage._dtypes.TimeStep): Timestep containing transition
              information to be added to context.
  
      """
      o = torch.as_tensor(
          timestep.observation[None, None, ...], device=global_device()
      ).float()
      a = torch.as_tensor(
          timestep.action[None, None, ...], device=global_device()
      ).float()
      r = torch.as_tensor(
          np.array([timestep.reward])[None, None, ...],
          device=global_device(),
      ).float()
      no = torch.as_tensor(
          timestep.next_observation[None, None, ...],
          device=global_device(),
      ).float()
  
      if self._use_next_obs:
          data = torch.cat([o, a, r, no], dim=2)
      else:
          data = torch.cat([o, a, r], dim=2)
  
      if self._context is None:
          self._context = data
      else:
          self._context = torch.cat([self._context, data], dim=1)
  
file_path: garage/src/garage/torch/policies/context_conditioned_policy.py
imports: import numpy
  import torch
  from torch import nn
  import torch.nn.functional
  from garage.torch import global_device, product_of_gaussians
label_desc: Use image node_id 4 for calling the ContextConditionedPolicy obj's underlying member method code with example usage: obj.update_context(timestep) without return types