class_docstr: Policy that samples actions based on the FALCON algorithm.
class_docstr_tok: ["Policy","that","samples","actions","based","on","the","FALCON","algorithm","."]
docstr: Computes the gamma parameter(s) in the sampling probability.
  
  This helper method implements a simple heuristic for computing the
  the gamma parameter in Step 2 of Algorithm 1 in the paper
  https://arxiv.org/pdf/2003.12699.pdf. A higher gamma makes the action
  sampling distribution concentrate more on the greedy action.
  
  Args:
    mask: An optional mask represented by a tensor shaped as [batch_size,
      num_actions].
    dtype: Type of the returned value, expected to be a float type.
    batch_size: The batch size.
  
  Returns:
    The gamma parameter shaped as [batch_size, d], where d = 1 if
    self._max_exploration_probability_hint is unset, and d > 1 otherwise. In
    the latter case, the second dimension gives gamma parameters calculated on
    a 1-D grid of `exploitation_coefficient` in log2 scale between 0 and
    `_MAX_LOG2_EXPLOITATION_COEF` inclusively, and `d` corresponds to the grid
    size.
docstr_tok: ["Computes","the","gamma","parameter","(","s",")","in","the","sampling","probability",".","This","helper","method","implements","a","simple","heuristic","for","computing","the","the","gamma","parameter","in","Step","2","of","Algorithm","1","in","the","paper","https",":","\/\/arxiv.org\/pdf\/2003.12699.pdf",".","A","higher","gamma","makes","the","action","sampling","distribution","concentrate","more","on","the","greedy","action",".","Args",":","mask",":","An","optional","mask","represented","by","a","tensor","shaped","as","[","batch_size",",","num_actions","]",".","dtype",":","Type","of","the","returned","value",",","expected","to","be","a","float","type",".","batch_size",":","The","batch","size",".","Returns",":","The","gamma","parameter","shaped","as","[","batch_size",",","d","]",",","where","d","=","1","if","self._max_exploration_probability_hint","is","unset",",","and","d",">","1","otherwise",".","In","the","latter","case",",","the","second","dimension","gives","gamma","parameters","calculated","on","a","1-D","grid","of","`","exploitation_coefficient","`","in","log2","scale","between","0","and","`","_MAX_LOG2_EXPLOITATION_COEF","`","inclusively",",","and","`","d","`","corresponds","to","the","grid","size","."]
code: def _compute_gamma(
      self,
      mask: Optional[types.Tensor],
      dtype: tf.DType,
      batch_size: int,
  ) -> types.Float:
      """Computes the gamma parameter(s) in the sampling probability.
  
      This helper method implements a simple heuristic for computing the
      the gamma parameter in Step 2 of Algorithm 1 in the paper
      https://arxiv.org/pdf/2003.12699.pdf. A higher gamma makes the action
      sampling distribution concentrate more on the greedy action.
  
      Args:
        mask: An optional mask represented by a tensor shaped as [batch_size,
          num_actions].
        dtype: Type of the returned value, expected to be a float type.
        batch_size: The batch size.
  
      Returns:
        The gamma parameter shaped as [batch_size, d], where d = 1 if
        self._max_exploration_probability_hint is unset, and d > 1 otherwise. In
        the latter case, the second dimension gives gamma parameters calculated on
        a 1-D grid of `exploitation_coefficient` in log2 scale between 0 and
        `_MAX_LOG2_EXPLOITATION_COEF` inclusively, and `d` corresponds to the grid
        size.
      """
      num_samples_list_float = tf.maximum(
          [
              tf.cast(x.read_value(), tf.float32)
              for x in self.num_samples_list
          ],
          0.0,
      )
      num_trainable_elements_float = tf.cast(
          tf.math.maximum(self.num_trainable_elements, 1), tf.float32
      )
      num_allowed_actions = self._get_number_of_allowed_actions(mask)
      exploitation_coefficient = (
          self._get_exploitation_coefficient()
          if self._max_exploration_probability_hint is None
          else tf.pow(2.0, range(_MAX_LOG2_EXPLOITATION_COEF + 1))
      )
      gamma = tf.sqrt(
          num_allowed_actions
          * tf.reduce_sum(num_samples_list_float)
          / num_trainable_elements_float
      )
      return tf.minimum(
          _MAX_GAMMA,
          tf.reshape(gamma, [-1, 1])
          * tf.ones(shape=[batch_size, 1], dtype=dtype)
          * tf.reshape(exploitation_coefficient, [1, -1]),
      )
  
file_path: agents/tf_agents/bandits/policies/falcon_reward_prediction_policy.py
imports: from typing import Iterable, Optional, Sequence, Text, Tuple
  import tensorflow
  import tensorflow_probability
  from tf_agents.bandits.policies import constraints
  from tf_agents.bandits.policies import reward_prediction_base_policy
  from tf_agents.distributions import shifted_categorical
  from tf_agents.policies import utils
  from tf_agents.typing import types
label_desc: Use image node_id 6 for calling the FalconRewardPredictionPolicy obj's underlying member method code with example usage: obj._compute_gamma(mask, dtype, batch_size) and returns: tf