class_docstr: Policy gradient agent for episodic setting. This agent here supports
  **un-batched** training, i.e., each time generates one action, takes one
  observation, and updates the policy.
  
  The policy must take in an observation of shape `[1] + observation_shape`,
  where the first dimension 1 stands for batch dimension, and output a `dict`
  containing:
  
  - Key **"action"** whose value is a Tensor of shape     `[1] + action_shape` containing a single action.
  - One of keys "log_prob" or "dist":
  
      - **"log_prob"**: A Tensor of shape `[1]`, the log probability of the         "action".
      - **"dist"**: A         tf_main:`tf.distributions.Distribution <distributions/Distribution>`        with the `log_prob` interface and         `log_prob = dist.log_prob(outputs["action"])`.
  
  .. role:: python(code)
     :language: python
  
  Args:
      env_config: An instance of :class:`~texar.tf.agents.EnvConfig`
          specifying action space, observation space, and reward range, etc.
          Use :func:`~texar.tf.agents.get_gym_env_config` to create an
          EnvConfig from a gym environment.
      sess (optional): A tf session.
          Can be `None` here and set later with `agent.sess = session`.
      policy (optional): A policy net that takes in observation and outputs
          actions and probabilities.
          If not given, a policy network is created based on :attr:`hparams`.
      policy_kwargs (dict, optional): Keyword arguments for policy
          constructor. Note that the `hparams` argument for network
          constructor is specified in the "policy_hparams" field of
          :attr:`hparams` and should not be included in `policy_kwargs`.
          Ignored if :attr:`policy` is given.
      policy_caller_kwargs (dict, optional): Keyword arguments for
          calling the policy to get actions. The policy is called with
          :python:`outputs=policy(inputs=observation, **policy_caller_kwargs)`
      learning_rate (optional): Learning rate for policy optimization. If
          not given, determine the learning rate from :attr:`hparams`.
          See :func:`~texar.tf.core.get_train_op` for more details.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
class_docstr_tok: ["Policy","gradient","agent","for","episodic","setting",".","This","agent","here","supports","*","*","un-batched","*","*","training",",","i.e.",",","each","time","generates","one","action",",","takes","one","observation",",","and","updates","the","policy",".","The","policy","must","take","in","an","observation","of","shape","`","[","1","]","+","observation_shape","`",",","where","the","first","dimension","1","stands","for","batch","dimension",",","and","output","a","`","dict","`","containing",":","-","Key","*","*","''","action","''","*","*","whose","value","is","a","Tensor","of","shape","`","[","1","]","+","action_shape","`","containing","a","single","action",".","-","One","of","keys","``","log_prob","''","or","``","dist","''",":","-","*","*","''","log_prob","''","*","*",":","A","Tensor","of","shape","`","[","1","]","`",",","the","log","probability","of","the","``","action","''",".","-","*","*","''","dist","''","*","*",":","A","tf_main",":","`","tf.distributions.Distribution","<","distributions\/Distribution",">","`","with","the","`","log_prob","`","interface","and","`","log_prob","=","dist.log_prob","(","outputs","[","``","action","''","]",")","`",".","..","role",":",":","python","(","code",")",":","language",":","python","Args",":","env_config",":","An","instance","of",":","class",":","`","~texar.tf.agents.EnvConfig","`","specifying","action","space",",","observation","space",",","and","reward","range",",","etc",".","Use",":","func",":","`","~texar.tf.agents.get_gym_env_config","`","to","create","an","EnvConfig","from","a","gym","environment",".","sess","(","optional",")",":","A","tf","session",".","Can","be","`","None","`","here","and","set","later","with","`","agent.sess","=","session","`",".","policy","(","optional",")",":","A","policy","net","that","takes","in","observation","and","outputs","actions","and","probabilities",".","If","not","given",",","a","policy","network","is","created","based","on",":","attr",":","`","hparams","`",".","policy_kwargs","(","dict",",","optional",")",":","Keyword","arguments","for","policy","constructor",".","Note","that","the","`","hparams","`","argument","for","network","constructor","is","specified","in","the","``","policy_hparams","''","field","of",":","attr",":","`","hparams","`","and","should","not","be","included","in","`","policy_kwargs","`",".","Ignored","if",":","attr",":","`","policy","`","is","given",".","policy_caller_kwargs","(","dict",",","optional",")",":","Keyword","arguments","for","calling","the","policy","to","get","actions",".","The","policy","is","called","with",":","python",":","`","outputs=policy","(","inputs=observation",",","*","*","policy_caller_kwargs",")","`","learning_rate","(","optional",")",":","Learning","rate","for","policy","optimization",".","If","not","given",",","determine","the","learning","rate","from",":","attr",":","`","hparams","`",".","See",":","func",":","`","~texar.tf.core.get_train_op","`","for","more","details",".","hparams","(","dict","or","HParams",",","optional",")",":","Hyperparameters",".","Missing","hyperparamerter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","sturcture","and","default","values","."]
code: def _get_pg_loss(self):
      if "log_prob" in self._outputs:
          log_probs = self._outputs["log_prob"]
      elif "dist" in self._outputs:
          log_probs = self._outputs["dist"].log_prob(
              self._action_inputs
          )
      else:
          raise ValueError(
              "Outputs of the policy must have one of "
              '"log_prob" or "dist".'
          )
      pg_loss = losses.pg_loss_with_log_probs(
          log_probs=log_probs,
          advantages=self._advantage_inputs,
          average_across_timesteps=True,
          sum_over_timesteps=False,
      )
      return pg_loss
  
imports: import tensorflow
  from texar.tf.agents.episodic_agent_base import EpisodicAgentBase
  from texar.tf.utils import utils
  from texar.tf.core import optimization
  from texar.tf.losses import pg_losses
  from texar.tf.losses.rewards import discount_reward
label_desc: Use image node_id 4 for calling the PGAgent obj's underlying member method code with example usage: obj._get_pg_loss() and returns: pg_loss