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 value estimation loss.
  
  Args:
    value_preds: Per-timestep estimated values.
    returns: Per-timestep returns for value function to predict.
    num_episodes: Number of episodes contained in the training data.
    weights: Optional scalar or element-wise (per-batch-entry) importance
      weights.  May include a mask for invalid timesteps.
  
  Returns:
    value_estimation_loss: A scalar value_estimation_loss loss.
docstr_tok: ["Computes","the","value","estimation","loss",".","Args",":","value_preds",":","Per-timestep","estimated","values",".","returns",":","Per-timestep","returns","for","value","function","to","predict",".","num_episodes",":","Number","of","episodes","contained","in","the","training","data",".","weights",":","Optional","scalar","or","element-wise","(","per-batch-entry",")","importance","weights",".","May","include","a","mask","for","invalid","timesteps",".","Returns",":","value_estimation_loss",":","A","scalar","value_estimation_loss","loss","."]
code: def value_estimation_loss(
      self,
      value_preds: types.Tensor,
      returns: types.Tensor,
      num_episodes: types.Int,
      weights: Optional[types.Tensor] = None,
  ) -> types.Tensor:
      """Computes the value estimation loss.
  
      Args:
        value_preds: Per-timestep estimated values.
        returns: Per-timestep returns for value function to predict.
        num_episodes: Number of episodes contained in the training data.
        weights: Optional scalar or element-wise (per-batch-entry) importance
          weights.  May include a mask for invalid timesteps.
  
      Returns:
        value_estimation_loss: A scalar value_estimation_loss loss.
      """
      value_estimation_error = tf.math.squared_difference(
          returns, value_preds
      )
      if weights is not None:
          value_estimation_error *= weights
  
      value_estimation_loss = (
          tf.reduce_sum(input_tensor=value_estimation_error)
          * self._value_estimation_loss_coef
      )
  
      # We take the mean over episodes by dividing by num_episodes.
      value_estimation_loss = value_estimation_loss / num_episodes
  
      return value_estimation_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 7 for calling the ReinforceAgent obj's underlying member method code with example usage: obj.value_estimation_loss(value_preds, returns, num_episodes, weights) and returns: value_estimation_loss