class_docstr: Unit tests for TabularQLearning.
class_docstr_tok: ["Unit","tests","for","TabularQLearning","."]
code: def test_update(self, mock_qlearn_parameters):
      self._setup_qlearn_parameters(mock_qlearn_parameters.return_value)
      action_space = spaces.Discrete(2)
      observation_space = spaces.Discrete(3)
      sut = FakeTabularQLearning("", observation_space, action_space)
  
      sut.start(0)
      self.assertEqual(sut.episode_count, 1)
      self.assertEqual(sut.step_count, 0)
      self.assertEqual(sut._epsilon, 0.1)
      # _eta has not been defined so far.
      self.assertEqual(sut._last_state, 0)
      self.assertEqual(sut._last_action, 0)
  
      sut.step(1, 1)
      self.assertEqual(sut.episode_count, 1)
      self.assertEqual(sut.step_count, 1)
      self.assertEqual(sut._epsilon, 0.09)
      self.assertEqual(sut._eta, 0.1)
      self.assertEqual(sut._last_state, 1)
      self.assertEqual(sut._last_action, 1)
      np.testing.assert_array_equal(sut._q, [[0.1, 0], [0, 0], [0, 0]])
  
      sut.step(1, 1)
      self.assertEqual(sut.episode_count, 1)
      self.assertEqual(sut.step_count, 2)
      self.assertEqual(sut._epsilon, 0.08)
      self.assertEqual(sut._eta, 0.09)
      self.assertEqual(sut._last_state, 1)
      self.assertEqual(sut._last_action, 1)
      np.testing.assert_array_equal(
          sut._q, [[0.1, 0], [0, 0.09], [0, 0]]
      )
  
      sut.step(1, 1)
      self.assertEqual(sut.episode_count, 1)
      self.assertEqual(sut.step_count, 3)
      self.assertEqual(sut._epsilon, 0.07)
      self.assertEqual(sut._eta, 0.08)
      self.assertEqual(sut._last_state, 1)
      self.assertEqual(sut._last_action, 1)
      # 0.16928 = 0.09 + (1(reward) + 0.9(gamma)*max([0, 0.09]) - 0.09) * 0.08(eta)
      np.testing.assert_almost_equal(
          sut._q, [[0.1, 0], [0, 0.16928], [0, 0]]
      )
  
      sut.end(1, 2)
      self.assertEqual(sut.episode_count, 1)
      self.assertEqual(sut.step_count, 4)
      # _epsilon remains the same as no action is chosen in end().
      self.assertEqual(sut._epsilon, 0.07)
      self.assertEqual(sut._eta, 0.07)
      # 0.2274304 = 0.16928 + (1(reward) - 0.16928) * 0.07(eta)
      np.testing.assert_almost_equal(
          sut._q, [[0.1, 0], [0, 0.2274304], [0, 0]]
      )
  
file_path: CNTK/bindings/python/cntk/contrib/deeprl/tests/tabular_qlearning_test.py
imports: import unittest
  import cntk.contrib.deeprl.tests.spaces
  import numpy
  from cntk.contrib.deeprl.agent.tabular_qlearning import TabularQLearning
label_desc: Use image node_id 3 for calling the TabularQLearningTest obj's underlying member method code with example usage: obj.test_update(mock_qlearn_parameters) without return types