Ejemplo n.º 1
0
  def test_back_propagation_max(self):
    # First back propapate the reward on grandchild1.
    tree.back_propagation(self.grandchild1, 1., update_method='max')
    # Only nodes on lineage:
    # grandchild1 -- child1 -- root will be updated.
    self.assertEqual(self.grandchild1.visits, 1)
    self.assertAlmostEqual(self.grandchild1.quality, 1.)
    self.assertEqual(self.child1.visits, 1)
    self.assertAlmostEqual(self.child1.quality, 1.)
    self.assertEqual(self.root.visits, 1)
    self.assertAlmostEqual(self.root.quality, 1.)
    # Other nodes will not be affected.
    self.assertEqual(self.grandchild2.visits, 0)
    self.assertAlmostEqual(self.grandchild2.quality, 0.)
    self.assertEqual(self.child2.visits, 0)
    self.assertAlmostEqual(self.child2.quality, 0.)

    # Then back propapate the reward on child2.
    tree.back_propagation(self.child2, 9., update_method='max')
    # Only nodes on lineage:
    # child2 -- root will be updated.
    self.assertEqual(self.child2.visits, 1)
    self.assertAlmostEqual(self.child2.quality, 9.)
    self.assertEqual(self.root.visits, 2)
    self.assertAlmostEqual(self.root.quality, 9.)
    # Other nodes will not be affected.
    self.assertEqual(self.grandchild1.visits, 1)
    self.assertAlmostEqual(self.grandchild1.quality, 1.)
    self.assertEqual(self.grandchild2.visits, 0)
    self.assertAlmostEqual(self.grandchild2.quality, 0.)
    self.assertEqual(self.child1.visits, 1)
    self.assertAlmostEqual(self.child1.quality, 1.)
Ejemplo n.º 2
0
 def test_back_propagation_reward_value_not_finite(
     self, reward_value, update_method):
   # Back propapate the reward on grandchild1.
   tree.back_propagation(
       self.grandchild1, reward_value, update_method=update_method)
   # Nodes on lineage
   # grandchild1 -- child1 -- root
   # will not be affected since the back propagation step is skipped:
   self.assertEqual(self.grandchild1.visits, 0)
   self.assertAlmostEqual(self.grandchild1.quality, 0.)
   self.assertEqual(self.child1.visits, 0)
   self.assertAlmostEqual(self.child1.quality, 0.)
   self.assertEqual(self.root.visits, 0)
   self.assertAlmostEqual(self.root.quality, 0.)
   # Other nodes will not be affected.
   self.assertEqual(self.grandchild2.visits, 0)
   self.assertAlmostEqual(self.grandchild2.quality, 0.)
   self.assertEqual(self.child2.visits, 0)
   self.assertAlmostEqual(self.child2.quality, 0.)