class_docstr: Generates a tfp.distribution.Categorical by predicting logits.
docstr: Creates an instance of CategoricalProjectionNetwork.
  
  Args:
    sample_spec: A `tensor_spec.BoundedTensorSpec` detailing the shape and
      dtypes of samples pulled from the output distribution.
    logits_init_output_factor: Output factor for initializing kernel logits
      weights.
    name: A string representing name of the network.
docstr_tok: ["Creates","an","instance","of","CategoricalProjectionNetwork",".","Args",":","sample_spec",":","A","`","tensor_spec.BoundedTensorSpec","`","detailing","the","shape","and","dtypes","of","samples","pulled","from","the","output","distribution",".","logits_init_output_factor",":","Output","factor","for","initializing","kernel","logits","weights",".","name",":","A","string","representing","name","of","the","network","."]
code: def __init__(
      self,
      sample_spec,
      logits_init_output_factor=0.1,
      name="CategoricalProjectionNetwork",
  ):
      """Creates an instance of CategoricalProjectionNetwork.
  
      Args:
        sample_spec: A `tensor_spec.BoundedTensorSpec` detailing the shape and
          dtypes of samples pulled from the output distribution.
        logits_init_output_factor: Output factor for initializing kernel logits
          weights.
        name: A string representing name of the network.
      """
      unique_num_actions = np.unique(
          sample_spec.maximum - sample_spec.minimum + 1
      )
      if len(unique_num_actions) > 1 or np.any(unique_num_actions <= 0):
          raise ValueError(
              "Bounds on discrete actions must be the same for all "
              "dimensions and have at least 1 action. Projection "
              "Network requires num_actions to be equal across "
              "action dimensions. Implement a more general "
              "categorical projection if you need more flexibility."
          )
  
      output_shape = sample_spec.shape.concatenate(
          [int(unique_num_actions)]
      )
      output_spec = self._output_distribution_spec(
          output_shape, sample_spec, name
      )
  
      super(CategoricalProjectionNetwork, self).__init__(
          # We don't need these, but base class requires them.
          input_tensor_spec=None,
          state_spec=(),
          output_spec=output_spec,
          name=name,
      )
  
      if not tensor_spec.is_bounded(sample_spec):
          raise ValueError(
              "sample_spec must be bounded. Got: %s."
              % type(sample_spec)
          )
  
      if not tensor_spec.is_discrete(sample_spec):
          raise ValueError(
              "sample_spec must be discrete. Got: %s." % sample_spec
          )
  
      self._sample_spec = sample_spec
      self._output_shape = output_shape
  
      self._projection_layer = tf.keras.layers.Dense(
          self._output_shape.num_elements(),
          kernel_initializer=tf.compat.v1.keras.initializers.VarianceScaling(
              scale=logits_init_output_factor
          ),
          bias_initializer=tf.keras.initializers.Zeros(),
          name="logits",
      )
  
file_path: agents/tf_agents/networks/categorical_projection_network.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gin
  import numpy
  import tensorflow
  import tensorflow_probability
  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 CategoricalProjectionNetwork object from inherited base classes: network with example: obj = CategoricalProjectionNetwork(sample_spec, logits_init_output_factor, name)