class_docstr: Generates a tfp.distribution.Normal by predicting a mean and std.
  
  Note: By default this network uses `tanh_squash_to_spec` to normalize its
  output. Due to the nature of the `tanh` function, values near the spec bounds
  cannot be returned.
  
  Note: The standard deviations are independent of the input.
class_docstr_tok: ["Generates","a","tfp.distribution.Normal","by","predicting","a","mean","and","std",".","Note",":","By","default","this","network","uses","`","tanh_squash_to_spec","`","to","normalize","its","output",".","Due","to","the","nature","of","the","`","tanh","`","function",",","values","near","the","spec","bounds","can","not","be","returned",".","Note",":","The","standard","deviations","are","independent","of","the","input","."]
docstr: Creates an instance of NormalProjectionNetwork.
  
  Args:
    sample_spec: A `tensor_spec.BoundedTensorSpec` detailing the shape and
      dtypes of samples pulled from the output distribution.
    activation_fn: Activation function to use in dense layer.
    init_means_output_factor: Output factor for initializing action means
      weights.
    std_bias_initializer_value: Initial value for the bias of the
      stddev_projection_layer or the direct bias_layer depending on the
      state_dependent_std flag.
    mean_transform: Transform to apply to the calculated means. Uses
      `tanh_squash_to_spec` by default.
    std_transform: Transform to apply to the stddevs.
    state_dependent_std: If true, stddevs will be produced by MLP from state.
      else, stddevs will be an independent variable.
    scale_distribution: Whether or not to use a bijector chain to scale
      distributions to match the sample spec. Note the TransformedDistribution
      does not support certain operations required by some agents or policies
      such as KL divergence calculations or Mode.
    seed: seed used for Keras kernal initializers.
    seed_stream_class: The seed stream class. This is almost always
      tfp.util.SeedStream, except for in unit testing, when one may want to
      seed all the layers deterministically.
    name: A string representing name of the network.
docstr_tok: ["Creates","an","instance","of","NormalProjectionNetwork",".","Args",":","sample_spec",":","A","`","tensor_spec.BoundedTensorSpec","`","detailing","the","shape","and","dtypes","of","samples","pulled","from","the","output","distribution",".","activation_fn",":","Activation","function","to","use","in","dense","layer",".","init_means_output_factor",":","Output","factor","for","initializing","action","means","weights",".","std_bias_initializer_value",":","Initial","value","for","the","bias","of","the","stddev_projection_layer","or","the","direct","bias_layer","depending","on","the","state_dependent_std","flag",".","mean_transform",":","Transform","to","apply","to","the","calculated","means",".","Uses","`","tanh_squash_to_spec","`","by","default",".","std_transform",":","Transform","to","apply","to","the","stddevs",".","state_dependent_std",":","If","true",",","stddevs","will","be","produced","by","MLP","from","state",".","else",",","stddevs","will","be","an","independent","variable",".","scale_distribution",":","Whether","or","not","to","use","a","bijector","chain","to","scale","distributions","to","match","the","sample","spec",".","Note","the","TransformedDistribution","does","not","support","certain","operations","required","by","some","agents","or","policies","such","as","KL","divergence","calculations","or","Mode",".","seed",":","seed","used","for","Keras","kernal","initializers",".","seed_stream_class",":","The","seed","stream","class",".","This","is","almost","always","tfp.util.SeedStream",",","except","for","in","unit","testing",",","when","one","may","want","to","seed","all","the","layers","deterministically",".","name",":","A","string","representing","name","of","the","network","."]
code: def __init__(
      self,
      sample_spec,
      activation_fn=None,
      init_means_output_factor=0.1,
      std_bias_initializer_value=0.0,
      mean_transform=tanh_squash_to_spec,
      std_transform=tf.nn.softplus,
      state_dependent_std=False,
      scale_distribution=False,
      seed=None,
      seed_stream_class=tfp.util.SeedStream,
      name="NormalProjectionNetwork",
  ):
      """Creates an instance of NormalProjectionNetwork.
  
      Args:
        sample_spec: A `tensor_spec.BoundedTensorSpec` detailing the shape and
          dtypes of samples pulled from the output distribution.
        activation_fn: Activation function to use in dense layer.
        init_means_output_factor: Output factor for initializing action means
          weights.
        std_bias_initializer_value: Initial value for the bias of the
          stddev_projection_layer or the direct bias_layer depending on the
          state_dependent_std flag.
        mean_transform: Transform to apply to the calculated means. Uses
          `tanh_squash_to_spec` by default.
        std_transform: Transform to apply to the stddevs.
        state_dependent_std: If true, stddevs will be produced by MLP from state.
          else, stddevs will be an independent variable.
        scale_distribution: Whether or not to use a bijector chain to scale
          distributions to match the sample spec. Note the TransformedDistribution
          does not support certain operations required by some agents or policies
          such as KL divergence calculations or Mode.
        seed: seed used for Keras kernal initializers.
        seed_stream_class: The seed stream class. This is almost always
          tfp.util.SeedStream, except for in unit testing, when one may want to
          seed all the layers deterministically.
        name: A string representing name of the network.
      """
      if len(tf.nest.flatten(sample_spec)) != 1:
          raise ValueError(
              "Normal Projection network only supports single spec samples."
          )
      self._scale_distribution = scale_distribution
      output_spec = self._output_distribution_spec(sample_spec, name)
      super(NormalProjectionNetwork, self).__init__(
          # We don't need these, but base class requires them.
          input_tensor_spec=None,
          state_spec=(),
          output_spec=output_spec,
          name=name,
      )
  
      self._sample_spec = sample_spec
      self._is_multivariate = sample_spec.shape.ndims > 0
      self._mean_transform = mean_transform
      self._std_transform = std_transform
      self._state_dependent_std = state_dependent_std
      seed_stream = seed_stream_class(
          seed=seed, salt="tf_agents_normal_projection_network"
      )
      mean_seed = seed_stream()
      if mean_seed is not None:
          mean_seed = mean_seed % sys.maxsize
      self._means_projection_layer = tf.keras.layers.Dense(
          sample_spec.shape.num_elements(),
          activation=activation_fn,
          kernel_initializer=tf.keras.initializers.VarianceScaling(
              scale=init_means_output_factor, seed=mean_seed
          ),
          bias_initializer=tf.keras.initializers.Zeros(),
          name="means_projection_layer",
      )
  
      self._stddev_projection_layer = None
      if self._state_dependent_std:
          std_seed = seed_stream()
          if std_seed is not None:
              std_seed = std_seed % sys.maxsize
          self._stddev_projection_layer = tf.keras.layers.Dense(
              sample_spec.shape.num_elements(),
              activation=activation_fn,
              kernel_initializer=tf.compat.v1.keras.initializers.VarianceScaling(
                  scale=init_means_output_factor, seed=std_seed
              ),
              bias_initializer=tf.constant_initializer(
                  value=std_bias_initializer_value
              ),
              name="stddev_projection_layer",
          )
      else:
          self._bias = bias_layer.BiasLayer(
              bias_initializer=tf.constant_initializer(
                  value=std_bias_initializer_value
              )
          )
  
file_path: agents/tf_agents/networks/normal_projection_network.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import sys
  import gin
  import tensorflow
  import tensorflow_probability
  from tf_agents.distributions import utils
  from tf_agents.keras_layers import bias_layer
  from tf_agents.networks import network
  from tf_agents.networks import utils
  from tf_agents.specs import distribution_spec
  from tf_agents.specs import tensor_spec
label_desc: Use image node_id 1 to create a new NormalProjectionNetwork object from inherited base classes: network with example: obj = NormalProjectionNetwork(sample_spec, activation_fn, init_means_output_factor, std_bias_initializer_value, mean_transform, std_transform, state_dependent_std, scale_distribution, seed, seed_stream_class, name)