class_docstr: Bandit environment that returns random observations and rewards.
class_docstr_tok: ["Bandit","environment","that","returns","random","observations","and","rewards","."]
docstr: Initializes an environment that returns random observations and rewards.
  
  Note that `observation_distribution` and `reward_distribution` are expected
  to have batch rank 1. That is, `observation_distribution.batch_shape` should
  have length exactly 1. `tensorflow_probability.distributions.Independent` is
  useful for manipulating batch and event shapes. For example,
  
  ```python
  observation_distribution = tfd.Independent(tfd.Normal(tf.zeros([12, 3, 4]),
                                                        tf.ones([12, 3, 4])))
  env = RandomBanditEnvironment(observation_distribution, ...)
  env.observation_spec  # tensor_spec.TensorSpec(shape=[3, 4], ...)
  env.batch_size  # 12
  ```
  
  Args:
    observation_distribution: a `tensorflow_probability.Distribution`. Batches
      of observations will be drawn from this distribution. The `batch_shape`
      of this distribution must have length 1 and be the same as the
      `batch_shape` of `reward_distribution`.
    reward_distribution: a `tensorflow_probability.Distribution`. Batches of
      rewards will be drawn from this distribution. The `batch_shape` of this
      distribution must have length 1 and be the same as the `batch_shape` of
      `observation_distribution`.
    action_spec: a `TensorSpec` describing the expected action. Note that
      actions are ignored and do not affect rewards.
docstr_tok: ["Initializes","an","environment","that","returns","random","observations","and","rewards",".","Note","that","`","observation_distribution","`","and","`","reward_distribution","`","are","expected","to","have","batch","rank","1",".","That","is",",","`","observation_distribution.batch_shape","`","should","have","length","exactly","1",".","`","tensorflow_probability.distributions.Independent","`","is","useful","for","manipulating","batch","and","event","shapes",".","For","example",",","``","`","python","observation_distribution","=","tfd.Independent","(","tfd.Normal","(","tf.zeros","(","[","12",",","3",",","4","]",")",",","tf.ones","(","[","12",",","3",",","4","]",")",")",")","env","=","RandomBanditEnvironment","(","observation_distribution",",","...",")","env.observation_spec","#","tensor_spec.TensorSpec","(","shape=","[","3",",","4","]",",","...",")","env.batch_size","#","12","``","`","Args",":","observation_distribution",":","a","`","tensorflow_probability.Distribution","`",".","Batches","of","observations","will","be","drawn","from","this","distribution",".","The","`","batch_shape","`","of","this","distribution","must","have","length","1","and","be","the","same","as","the","`","batch_shape","`","of","`","reward_distribution","`",".","reward_distribution",":","a","`","tensorflow_probability.Distribution","`",".","Batches","of","rewards","will","be","drawn","from","this","distribution",".","The","`","batch_shape","`","of","this","distribution","must","have","length","1","and","be","the","same","as","the","`","batch_shape","`","of","`","observation_distribution","`",".","action_spec",":","a","`","TensorSpec","`","describing","the","expected","action",".","Note","that","actions","are","ignored","and","do","not","affect","rewards","."]
code: def __init__(
      self,
      observation_distribution: types.Distribution,
      reward_distribution: types.Distribution,
      action_spec: Optional[types.TensorSpec] = None,
  ):
      """Initializes an environment that returns random observations and rewards.
  
      Note that `observation_distribution` and `reward_distribution` are expected
      to have batch rank 1. That is, `observation_distribution.batch_shape` should
      have length exactly 1. `tensorflow_probability.distributions.Independent` is
      useful for manipulating batch and event shapes. For example,
  
      ```python
      observation_distribution = tfd.Independent(tfd.Normal(tf.zeros([12, 3, 4]),
                                                            tf.ones([12, 3, 4])))
      env = RandomBanditEnvironment(observation_distribution, ...)
      env.observation_spec  # tensor_spec.TensorSpec(shape=[3, 4], ...)
      env.batch_size  # 12
      ```
  
      Args:
        observation_distribution: a `tensorflow_probability.Distribution`. Batches
          of observations will be drawn from this distribution. The `batch_shape`
          of this distribution must have length 1 and be the same as the
          `batch_shape` of `reward_distribution`.
        reward_distribution: a `tensorflow_probability.Distribution`. Batches of
          rewards will be drawn from this distribution. The `batch_shape` of this
          distribution must have length 1 and be the same as the `batch_shape` of
          `observation_distribution`.
        action_spec: a `TensorSpec` describing the expected action. Note that
          actions are ignored and do not affect rewards.
      """
      observation_batch_shape = observation_distribution.batch_shape
      reward_batch_shape = reward_distribution.batch_shape
      reward_event_shape = reward_distribution.event_shape
  
      if observation_batch_shape.rank != 1:
          _raise_batch_shape_error(
              "observation_distribution", observation_batch_shape
          )
  
      if reward_batch_shape.rank != 1:
          _raise_batch_shape_error(
              "reward_distribution", observation_batch_shape
          )
  
      if reward_event_shape.rank != 0:
          raise ValueError(
              "`reward_distribution` must have event_shape (); got {}".format(
                  reward_event_shape
              )
          )
  
      if reward_distribution.dtype != tf.float32:
          raise ValueError(
              "`reward_distribution` must have dtype float32; got {}".format(
                  reward_distribution.float32
              )
          )
  
      if observation_batch_shape[0] != reward_batch_shape[0]:
          raise ValueError(
              "`reward_distribution` and `observation_distribution` must have the "
              "same batch shape; got {} and {}".format(
                  reward_batch_shape, observation_batch_shape
              )
          )
      batch_size = tf.compat.dimension_value(observation_batch_shape[0])
      self._observation_distribution = observation_distribution
      self._reward_distribution = reward_distribution
      observation_spec = tensor_spec.TensorSpec(
          shape=self._observation_distribution.event_shape,
          dtype=self._observation_distribution.dtype,
          name="observation_spec",
      )
      time_step_spec = time_step.time_step_spec(observation_spec)
      super(RandomBanditEnvironment, self).__init__(
          time_step_spec=time_step_spec,
          action_spec=action_spec,
          batch_size=batch_size,
      )
  
file_path: agents/tf_agents/bandits/environments/random_bandit_environment.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Optional
  import tensorflow
  from tf_agents.bandits.environments import bandit_tf_environment
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
label_desc: Use image node_id 1 to create a new RandomBanditEnvironment object from inherited base classes: bte with example: obj = RandomBanditEnvironment(observation_distribution, reward_distribution, action_spec)