class_docstr: Categorical distribution, for discrete integer actions (specification key: `categorical`).
  
  Args:
      temperature_mode ("predicted" | "global"): Whether to predict the temperature via a linear
          transformation of the state embedding, or to parametrize the temperature by a separate
          set of trainable weights
          (<span style="color:#00C000"><b>default</b></span>: default temperature of 1).
      skip_linear (bool): Whether to not add the implicit linear logits layer, requires suitable
          network output shape according to action space, not compatible with temperature_mode
          (<span style="color:#00C000"><b>default</b></span>: false).
      name (string): <span style="color:#0000C0"><b>internal use</b></span>.
      action_spec (specification): <span style="color:#0000C0"><b>internal use</b></span>.
      input_spec (specification): <span style="color:#0000C0"><b>internal use</b></span>.
class_docstr_tok: ["Categorical","distribution",",","for","discrete","integer","actions","(","specification","key",":","`","categorical","`",")",".","Args",":","temperature_mode","(","``","predicted","''","|","``","global","''",")",":","Whether","to","predict","the","temperature","via","a","linear","transformation","of","the","state","embedding",",","or","to","parametrize","the","temperature","by","a","separate","set","of","trainable","weights","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","default","temperature","of","1",")",".","skip_linear","(","bool",")",":","Whether","to","not","add","the","implicit","linear","logits","layer",",","requires","suitable","network","output","shape","according","to","action","space",",","not","compatible","with","temperature_mode","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","false",")",".","name","(","string",")",":","<","span","style=","''","color",":","#","0000C0","''",">","<","b",">","internal","use","<","\/b",">","<","\/span",">",".","action_spec","(","specification",")",":","<","span","style=","''","color",":","#","0000C0","''",">","<","b",">","internal","use","<","\/b",">","<","\/span",">",".","input_spec","(","specification",")",":","<","span","style=","''","color",":","#","0000C0","''",">","<","b",">","internal","use","<","\/b",">","<","\/span",">","."]
code: def __init__(
      self,
      *,
      temperature_mode=None,
      skip_linear=False,
      name=None,
      action_spec=None,
      input_spec=None,
  ):
      assert (
          action_spec.type == "int"
          and action_spec.num_values is not None
      )
      assert not skip_linear or temperature_mode is None
  
      if temperature_mode is None:
          parameters_spec = TensorsSpec(
              probabilities=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              logits=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              action_values=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              state_value=TensorSpec(
                  type="float", shape=action_spec.shape
              ),
          )
      else:
          parameters_spec = TensorsSpec(
              probabilities=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              temperature=TensorSpec(
                  type="float", shape=action_spec.shape
              ),
              logits=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              action_values=TensorSpec(
                  type="float",
                  shape=(action_spec.shape + (action_spec.num_values,)),
              ),
              state_value=TensorSpec(
                  type="float", shape=action_spec.shape
              ),
          )
      conditions_spec = TensorsSpec()
  
      super().__init__(
          name=name,
          action_spec=action_spec,
          input_spec=input_spec,
          parameters_spec=parameters_spec,
          conditions_spec=conditions_spec,
      )
  
      self.temperature_mode = temperature_mode
  
      if self.config.enable_int_action_masking:
          self.conditions_spec["mask"] = TensorSpec(
              type="bool",
              shape=(
                  self.action_spec.shape
                  + (self.action_spec.num_values,)
              ),
          )
  
      num_values = self.action_spec.num_values
      if skip_linear:
          self.action_values = None
          if (
              self.input_spec.shape[:-1] != self.action_spec.shape
              or self.input_spec.shape[-1]
              != self.action_spec.num_values
          ):
              raise TensorforceError.value(
                  name=name,
                  argument="input_spec.shape",
                  value=self.input_spec.shape,
                  hint="!= (*action_shape, num_values)",
              )
          elif (
              self.input_spec.shape[:-1] != self.action_spec.shape
              and self.input_spec.shape[:-1]
              != self.action_spec.shape[:-1]
          ):
              raise TensorforceError.value(
                  name=name,
                  argument="input_spec.shape",
                  value=self.input_spec.shape,
                  hint="not flattened and incompatible with action shape",
              )
  
      elif self.input_spec.rank == 1:
          # Single embedding
          self.action_values = self.submodule(
              name="action_values",
              module="linear",
              modules=layer_modules,
              size=(self.action_spec.size * num_values),
              initialization_scale=0.01,
              input_spec=input_spec,
          )
          if self.temperature_mode == "predicted":
              self.temperature = self.submodule(
                  name="temperature",
                  module="linear",
                  modules=layer_modules,
                  size=self.action_spec.size,
                  initialization_scale=0.01,
                  input_spec=self.input_spec,
              )
  
      else:
          # Embedding per action
          if self.input_spec.rank < 1 or self.input_spec.rank > 3:
              raise TensorforceError.value(
                  name=name,
                  argument="input_spec.shape",
                  value=self.input_spec.shape,
                  hint="invalid rank",
              )
          if self.input_spec.shape[:-1] == self.action_spec.shape[:-1]:
              size = self.action_spec.shape[-1]
          elif self.input_spec.shape[:-1] == self.action_spec.shape:
              size = 1
          else:
              raise TensorforceError.value(
                  name=name,
                  argument="input_spec.shape",
                  value=self.input_spec.shape,
                  hint="not flattened and incompatible with action shape",
              )
          self.action_values = self.submodule(
              name="action_values",
              module="linear",
              modules=layer_modules,
              size=(size * num_values),
              initialization_scale=0.01,
              input_spec=input_spec,
          )
          if self.temperature_mode == "predicted":
              self.temperature = self.submodule(
                  name="temperature",
                  module="linear",
                  modules=layer_modules,
                  size=size,
                  initialization_scale=0.01,
                  input_spec=self.input_spec,
              )
  
file_path: tensorforce/tensorforce/core/distributions/categorical.py
imports: import numpy
  import tensorflow
  from tensorforce import TensorforceError, util
  from tensorforce.core import layer_modules, TensorDict, TensorSpec, TensorsSpec, tf_function, tf_util
  from tensorforce.core.distributions import Distribution
label_desc: Use image node_id 1 to create a new Categorical object from inherited base classes: Distribution with example: obj = Categorical()