docstr: Test that the previous label is set correctly for a simple case.
docstr_tok: ["Test","that","the","previous","label","is","set","correctly","for","a","simple","case","."]
code: def testPreviousLabelIsSetCorrectly(self):
      """Test that the previous label is set correctly for a simple case."""
      # Reward of 1 is given if action == (context % 3)
      context = tf.reshape(tf.range(128), shape=[128, 1])
      labels = tf.math.mod(context, 3)
      batch_size = 4
      dataset = (
          tf.data.Dataset.from_tensor_slices((context, labels))
          .repeat()
          .shuffle(4 * batch_size)
      )
      reward_distribution = deterministic_reward_distribution(tf.eye(3))
      env = ce.ClassificationBanditEnvironment(
          dataset, reward_distribution, batch_size
      )
      self.evaluate(tf.compat.v1.global_variables_initializer())
  
      time_step = env.reset()
      time_step_label = tf.squeeze(
          tf.math.mod(time_step.observation, 3)
      )
      action = tf.math.mod(time_step.observation, 3)
      next_time_step = env.step(action)
      next_time_step_label = tf.squeeze(
          tf.math.mod(next_time_step.observation, 3)
      )
  
      if tf.executing_eagerly():
          np.testing.assert_almost_equal(
              self.evaluate(time_step_label),
              self.evaluate(env._previous_label),
          )
          np.testing.assert_almost_equal(
              self.evaluate(next_time_step_label),
              self.evaluate(env._current_label),
          )
      else:
          with self.cached_session() as sess:
              (
                  time_step_label_value,
                  next_time_step_label_value,
              ) = sess.run([time_step_label, next_time_step_label])
  
              previous_label_value = self.evaluate(env._previous_label)
              np.testing.assert_almost_equal(
                  time_step_label_value, previous_label_value
              )
              current_label_value = self.evaluate(env._current_label)
              np.testing.assert_almost_equal(
                  next_time_step_label_value, current_label_value
              )
  
file_path: agents/tf_agents/bandits/environments/classification_environment_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  from absl.testing.absltest import mock
  import numpy
  import tensorflow
  import tensorflow_probability
  from tf_agents.bandits.environments import classification_environment
label_desc: Use image node_id 4 for calling the ClassificationEnvironmentTest obj's underlying member method code with example usage: obj.testPreviousLabelIsSetCorrectly() without return types