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: Given observations and context, get actions and probs from policy.
  
  Args:
      obs (torch.Tensor): Observation values, with shape
          :math:`(X, N, O)`. X is the number of tasks. N is batch size. O
           is the size of the flattened observation space.
      context (torch.Tensor): Context values, with shape
          :math:`(X, N, C)`. X is the number of tasks. N is batch size. C
          is the combined size of observation, action, reward, and next
          observation if next observation is used in context. Otherwise,
          C is the combined size of observation, action, and reward.
  
  Returns:
      tuple:
          * torch.Tensor: Predicted action values.
          * np.ndarray: Mean of distribution.
          * np.ndarray: Log std of distribution.
          * torch.Tensor: Log likelihood of distribution.
          * torch.Tensor: Sampled values from distribution before
              applying tanh transformation.
      torch.Tensor: z values, with shape :math:`(N, L)`. N is batch size.
          L is the latent dimension.
docstr_tok: ["Given","observations","and","context",",","get","actions","and","probs","from","policy",".","Args",":","obs","(","torch.Tensor",")",":","Observation","values",",","with","shape",":","math",":","`","(","X",",","N",",","O",")","`",".","X","is","the","number","of","tasks",".","N","is","batch","size",".","O","is","the","size","of","the","flattened","observation","space",".","context","(","torch.Tensor",")",":","Context","values",",","with","shape",":","math",":","`","(","X",",","N",",","C",")","`",".","X","is","the","number","of","tasks",".","N","is","batch","size",".","C","is","the","combined","size","of","observation",",","action",",","reward",",","and","next","observation","if","next","observation","is","used","in","context",".","Otherwise",",","C","is","the","combined","size","of","observation",",","action",",","and","reward",".","Returns",":","tuple",":","*","torch.Tensor",":","Predicted","action","values",".","*","np.ndarray",":","Mean","of","distribution",".","*","np.ndarray",":","Log","std","of","distribution",".","*","torch.Tensor",":","Log","likelihood","of","distribution",".","*","torch.Tensor",":","Sampled","values","from","distribution","before","applying","tanh","transformation",".","torch.Tensor",":","z","values",",","with","shape",":","math",":","`","(","N",",","L",")","`",".","N","is","batch","size",".","L","is","the","latent","dimension","."]
code: def forward(self, obs, context):
      """Given observations and context, get actions and probs from policy.
  
      Args:
          obs (torch.Tensor): Observation values, with shape
              :math:`(X, N, O)`. X is the number of tasks. N is batch size. O
               is the size of the flattened observation space.
          context (torch.Tensor): Context values, with shape
              :math:`(X, N, C)`. X is the number of tasks. N is batch size. C
              is the combined size of observation, action, reward, and next
              observation if next observation is used in context. Otherwise,
              C is the combined size of observation, action, and reward.
  
      Returns:
          tuple:
              * torch.Tensor: Predicted action values.
              * np.ndarray: Mean of distribution.
              * np.ndarray: Log std of distribution.
              * torch.Tensor: Log likelihood of distribution.
              * torch.Tensor: Sampled values from distribution before
                  applying tanh transformation.
          torch.Tensor: z values, with shape :math:`(N, L)`. N is batch size.
              L is the latent dimension.
  
      """
      self.infer_posterior(context)
      self.sample_from_belief()
      task_z = self.z
  
      # task, batch
      t, b, _ = obs.size()
      obs = obs.view(t * b, -1)
      task_z = [z.repeat(b, 1) for z in task_z]
      task_z = torch.cat(task_z, dim=0)
  
      # run policy, get log probs and new actions
      obs_z = torch.cat([obs, task_z.detach()], dim=1)
      dist = self._policy(obs_z)[0]
      pre_tanh, actions = dist.rsample_with_pre_tanh_value()
      log_pi = dist.log_prob(value=actions, pre_tanh_value=pre_tanh)
      log_pi = log_pi.unsqueeze(1)
      mean = dist.mean.to("cpu").detach().numpy()
      log_std = (dist.variance**0.5).log().to("cpu").detach().numpy()
  
      return (actions, mean, log_std, log_pi, pre_tanh), task_z
  
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 6 for calling the ContextConditionedPolicy obj's underlying member method code with example usage: obj.forward(obs, context) and returns: actions,  mean,  log_std,  log_pi,  pre_tanh,  task_z