class_docstr: A REINFORCE Agent.
  
  Implements:
  
  REINFORCE algorithm from
  
  "Simple statistical gradient-following algorithms for connectionist
  reinforcement learning"
  Williams, R.J., 1992.
  https://www-anw.cs.umass.edu/~barto/courses/cs687/williams92simple.pdf
  
  REINFORCE with state-value baseline, where state-values are estimated with
  function approximation, from
  
  "Reinforcement learning: An introduction" (Sec. 13.4)
  Sutton, R.S. and Barto, A.G., 2018.
  http://incompleteideas.net/book/the-book-2nd.html
  
  The REINFORCE agent can be optionally provided with:
  - value_network: A `tf_agents.network.Network` which parameterizes state-value
    estimation as a neural network. The network will be called with
    call(observation, step_type) and returns a floating point state-values
    tensor.
  - value_estimation_loss_coef: Weight on the value prediction loss.
  
  If value_network and value_estimation_loss_coef are provided, advantages are
  computed as
    `advantages = (discounted accumulated rewards) - (estimated state-values)`
  and the overall learning objective becomes:
    `(total loss) =
      (policy gradient loss) +
      value_estimation_loss_coef * (squared error of estimated state-values)`
class_docstr_tok: ["A","REINFORCE","Agent",".","Implements",":","REINFORCE","algorithm","from","''","Simple","statistical","gradient-following","algorithms","for","connectionist","reinforcement","learning","''","Williams",",","R.J.",",","1992.","https",":","\/\/www-anw.cs.umass.edu\/~barto\/courses\/cs687\/williams92simple.pdf","REINFORCE","with","state-value","baseline",",","where","state-values","are","estimated","with","function","approximation",",","from","''","Reinforcement","learning",":","An","introduction","''","(","Sec",".","13.4",")","Sutton",",","R.S",".","and","Barto",",","A.G.",",","2018.","http",":","\/\/incompleteideas.net\/book\/the-book-2nd.html","The","REINFORCE","agent","can","be","optionally","provided","with",":","-","value_network",":","A","`","tf_agents.network.Network","`","which","parameterizes","state-value","estimation","as","a","neural","network",".","The","network","will","be","called","with","call","(","observation",",","step_type",")","and","returns","a","floating","point","state-values","tensor",".","-","value_estimation_loss_coef",":","Weight","on","the","value","prediction","loss",".","If","value_network","and","value_estimation_loss_coef","are","provided",",","advantages","are","computed","as","`","advantages","=","(","discounted","accumulated","rewards",")","-","(","estimated","state-values",")","`","and","the","overall","learning","objective","becomes",":","`","(","total","loss",")","=","(","policy","gradient","loss",")","+","value_estimation_loss_coef","*","(","squared","error","of","estimated","state-values",")","`"]
docstr: Computes the optional entropy regularization loss.
  
  Extending REINFORCE by entropy regularization was originally proposed in
  "Function optimization using connectionist reinforcement learning
  algorithms." (Williams and Peng, 1991).
  
  Args:
    actions_distribution: A possibly batched tuple of action distributions.
    weights: Optional scalar or element-wise (per-batch-entry) importance
      weights.  May include a mask for invalid timesteps.
  
  Returns:
    entropy_regularization_loss: A tensor with the entropy regularization
    loss.
docstr_tok: ["Computes","the","optional","entropy","regularization","loss",".","Extending","REINFORCE","by","entropy","regularization","was","originally","proposed","in","''","Function","optimization","using","connectionist","reinforcement","learning","algorithms",".","''","(","Williams","and","Peng",",","1991",")",".","Args",":","actions_distribution",":","A","possibly","batched","tuple","of","action","distributions",".","weights",":","Optional","scalar","or","element-wise","(","per-batch-entry",")","importance","weights",".","May","include","a","mask","for","invalid","timesteps",".","Returns",":","entropy_regularization_loss",":","A","tensor","with","the","entropy","regularization","loss","."]
code: def entropy_regularization_loss(
      self,
      actions_distribution: types.NestedDistribution,
      weights: Optional[types.Tensor] = None,
  ) -> types.Tensor:
      """Computes the optional entropy regularization loss.
  
      Extending REINFORCE by entropy regularization was originally proposed in
      "Function optimization using connectionist reinforcement learning
      algorithms." (Williams and Peng, 1991).
  
      Args:
        actions_distribution: A possibly batched tuple of action distributions.
        weights: Optional scalar or element-wise (per-batch-entry) importance
          weights.  May include a mask for invalid timesteps.
  
      Returns:
        entropy_regularization_loss: A tensor with the entropy regularization
        loss.
      """
      if self._entropy_regularization:
          loss = _entropy_loss(
              actions_distribution, self.action_spec, weights
          )
          loss *= self._entropy_regularization
      else:
          loss = tf.constant(0.0, dtype=tf.float32)
  
      return loss
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Callable, Optional, Text
  import gin
  import numpy
  import tensorflow
  from tf_agents.agents import data_converter
  from tf_agents.agents import tf_agent
  from tf_agents.networks import network
  from tf_agents.policies import actor_policy
  from tf_agents.policies import greedy_policy
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import eager_utils
  from tf_agents.utils import nest_utils
  from tf_agents.utils import value_ops
label_desc: Use image node_id 6 for calling the ReinforceAgent obj's underlying member method code with example usage: obj.entropy_regularization_loss(actions_distribution, weights) and returns: loss