def __init__(self): shape1, shape2, shape3 = sg.sample_shape(3) objs1 = tg.Select(shape=shape1, when='now') objs2 = tg.Select(shape=shape2, when='now') objs3 = tg.Select(shape=shape3, when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def __init__(self): color1, color2, color3 = sg.sample_color(3) objs1 = tg.Select(color=color1, when='now') objs2 = tg.Select(color=color2, when='now') objs3 = tg.Select(color=color3, when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def __init__(self): attr1, attr2, attr3 = sg.sample_colorshape(3) objs1 = tg.Select(color=attr1[0], shape=attr1[1], when='now') objs2 = tg.Select(color=attr2[0], shape=attr2[1], when='now') objs3 = tg.Select(color=attr3[0], shape=attr3[1], when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def __init__(self): shape1, shape2 = sg.sample_shape(2) objs1 = tg.Select(shape=shape1, when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, shape=shape2, when='now', space_type=sg.random_space()) self._operator = tg.Exist(objs2)
def __init__(self): color1, color2 = sg.sample_color(2) objs1 = tg.Select(color=color1, when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=color2, when='now', space_type=sg.random_space()) self._operator = tg.Exist(objs2)
def testGetShapeOf(self): objs1 = tg.Select(color=sg.Color('blue'), when='last1') shape = tg.GetShape(objs1) objs2 = tg.Select(shape=shape, color=sg.Color('red'), when='now') task = tg.Task(tg.Exist(objs2)) n_epoch = 5 objset = sg.ObjectSet(n_epoch=n_epoch) for i_epoch in range(n_epoch): objset = task.guess_objset(objset, i_epoch)
def __init__(self): attr1, attr2 = sg.sample_colorshape(2) when2 = sg.random_when() objs1 = tg.Select(color=attr1[0], shape=attr1[1], when='now') objs2 = tg.Select(color=attr2[0], shape=attr2[1], when=when2) self._operator = tg.Switch(tg.Exist(objs1), tg.Go(objs1), tg.Go(objs2), both_options_avail=False)
def testExistColorOfGuessObjsetManyEpochs(self): objs1 = tg.Select(shape=sg.Shape('circle'), when='last1') color = tg.GetColor(objs1) objs2 = tg.Select(color=color, shape=sg.Shape('square'), when='now') task = tg.Task(tg.Exist(objs2)) n_epoch = 100 objset = sg.ObjectSet(n_epoch=n_epoch) for i in range(1, n_epoch)[::-1]: should_be = random.random() > 0.5 objset = task.guess_objset(objset, i, should_be=should_be) self.assertEqual(task(objset, i), should_be)
def __init__(self): attr1, attr2 = sg.sample_colorshape(2) objs1 = tg.Select(color=attr1[0], shape=attr1[1], when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=attr2[0], shape=attr2[1], when='now', space_type=sg.random_space()) self._operator = tg.Exist(objs2)
def testExistColorOfGuessObjset(self): objs1 = tg.Select(shape=sg.Shape('circle'), when='last1') color = tg.GetColor(objs1) objs2 = tg.Select(color=color, shape=sg.Shape('square'), when='now') task = tg.Task(tg.Exist(objs2)) n_epoch = 10 objset = sg.ObjectSet(n_epoch=n_epoch) objset = task.guess_objset(objset, 1, should_be=True) objset = task.guess_objset(objset, 3, should_be=False) self.assertTrue(task(objset, 1)) self.assertFalse(task(objset, 3))
def testGetSpaceCall(self): objs0 = tg.Select(color=sg.Color('red'), when='last1') objs1 = tg.Select(loc=tg.GetLoc(objs0), when='now', space_type='left') task1 = tg.Task(tg.Exist(objs1)) objs2 = tg.Select(loc=tg.GetLoc(objs0), when='now', space_type='right') task2 = tg.Task(tg.Exist(objs2)) objs3 = tg.Select(loc=tg.GetLoc(objs0), when='now', space_type='top') task3 = tg.Task(tg.Exist(objs3)) objs4 = tg.Select(loc=tg.GetLoc(objs0), when='now', space_type='bottom') task4 = tg.Task(tg.Exist(objs4)) objset = sg.ObjectSet(n_epoch=2) obj1 = sg.Object([sg.Loc([0.5, 0.5]), sg.Color('red')], when='now') objset.add(obj1, epoch_now=0) obj1 = sg.Object([sg.Loc([0.2, 0.3])], when='now') objset.add(obj1, epoch_now=1) self.assertTrue(task1(objset, epoch_now=1)) self.assertFalse(task2(objset, epoch_now=1)) self.assertTrue(task3(objset, epoch_now=1)) self.assertFalse(task4(objset, epoch_now=1))
def __init__(self): shape1, shape2, shape3, shape4 = sg.sample_shape(4) objs1 = tg.Select(shape=shape1, when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, shape=shape2, when='now', space_type=sg.random_space()) bool1 = tg.Exist(objs2) objs3 = tg.Select(shape=shape3) objs4 = tg.Select(shape=shape4) go1 = tg.Go(objs3) go2 = tg.Go(objs4) self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
def __init__(self): color1, color2, color3, color4 = sg.sample_color(4) objs1 = tg.Select(color=color1, when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=color2, when='now', space_type=sg.random_space()) bool1 = tg.Exist(objs2) objs3 = tg.Select(color=color3) objs4 = tg.Select(color=color4) go1 = tg.Go(objs3) go2 = tg.Go(objs4) self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
def testExistSpaceGuessObjset(self): # When should_be is False, there is a objset = sg.ObjectSet(n_epoch=10) objs1 = tg.Select(color=sg.Color('red'), when='now') loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=sg.Color('blue'), when='now', space_type='left') task = tg.Task(tg.Exist(objs2)) for epoch_now in range(1, 10)[::-1]: should_be = random.random() > 0.5 objset = task.guess_objset(objset, epoch_now, should_be=should_be) self.assertEqual(task(objset, epoch_now), should_be)
def testExistColorSpaceGuessObjsetManyEpochs(self): objs1 = tg.Select(color=sg.Color('red'), when='last1') loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=sg.Color('blue'), when='now', space_type='left') task = tg.Task(tg.Exist(objs2)) n_epoch = 10 objset = sg.ObjectSet(n_epoch=n_epoch) objset = task.guess_objset(objset, 2, should_be=False) objset = task.guess_objset(objset, 1, should_be=True) self.assertFalse(task(objset, 2)) self.assertTrue(task(objset, 1))
def testIsFinal(self): objs1 = tg.Select(color=sg.Color('red'), shape=sg.Shape('square'), when='now') objs2 = tg.Select(color=sg.Color('blue'), shape=sg.Shape('square'), when='now') objs3 = tg.Select(shape=sg.Shape('circle'), when='last1') bool1 = tg.Exist(objs1) go1 = tg.Go(objs2) go2 = tg.Go(objs3) op = tg.Switch(bool1, go1, go2, both_options_avail=False) self.assertFalse(op.parent) self.assertTrue(bool1.parent) self.assertTrue(go1.parent)
def testExistColorSpaceGuessObjset(self): for space_type in ['left', 'right', 'top', 'bottom']: objs1 = tg.Select(color=sg.Color('red'), when='now') loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=sg.Color('blue'), when='now', space_type=space_type) task = tg.Task(tg.Exist(objs2)) n_epoch = 100 objset = sg.ObjectSet(n_epoch=n_epoch) for i in range(0, n_epoch)[::-1]: should_be = random.random() > 0.5 objset = task.guess_objset(objset, i, should_be=should_be) self.assertEqual(task(objset, i), should_be)
def testOperatorSize(self): objs1 = tg.Select(shape=sg.Shape('circle'), when='now') color1 = tg.GetColor(objs1) objs2 = tg.Select(color=color1, shape=sg.Shape('square'), when='now') exist = tg.Exist(objs2) task = tg.Task(exist) self.assertEqual(task.operator_size, 4) objs1 = tg.Select(when='last1') objs2 = tg.Select(when='now') s1 = tg.GetShape(objs1) s2 = tg.GetShape(objs2) c1 = tg.GetColor(objs1) c2 = tg.GetColor(objs2) bool1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2)) task = tg.Task(bool1) self.assertEqual(task.operator_size, 9)
def testExistGuessObjset(self): objset = sg.ObjectSet(n_epoch=10) objs1 = tg.Select(color=sg.Color('red'), when='now') task = tg.Task(tg.Exist(objs1)) epoch_now = 1 objset = task.guess_objset(objset, epoch_now, should_be=True) l1 = len(objset.select(epoch_now, color=sg.Color('red'), when='now')) l2 = len(objset.select(epoch_now, color=sg.Color('blue'), when='now')) self.assertEqual(1, l1) self.assertEqual(0, l2) self.assertTrue(task(objset, epoch_now)) epoch_now = 2 objset = task.guess_objset(objset, epoch_now, should_be=False) l1 = len(objset.select(epoch_now, color=sg.Color('red'), when='now')) self.assertEqual(0, l1) self.assertFalse(task(objset, epoch_now))
def __init__(self): attr1, attr2, attr3, attr4 = sg.sample_colorshape(4) objs1 = tg.Select(color=attr1[0], shape=attr1[1], when=sg.random_when()) loc = tg.GetLoc(objs1) objs2 = tg.Select(loc=loc, color=attr2[0], shape=attr2[1], when='now', space_type=sg.random_space()) bool1 = tg.Exist(objs2) objs3 = tg.Select(color=attr3[0], shape=attr3[1]) objs4 = tg.Select(color=attr4[0], shape=attr4[1]) go1 = tg.Go(objs3) go2 = tg.Go(objs4) self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
def __init__(self): shape1, shape2 = sg.sample_shape(2) objs1 = tg.Select(shape=shape1, when=sg.random_when()) color1 = tg.GetColor(objs1) objs2 = tg.Select(color=color1, shape=shape2, when='now') self._operator = tg.Exist(objs2)
def __init__(self): attr1 = sg.random_colorshape() objs1 = tg.Select(color=attr1[0], shape=attr1[1], when='now') task = tg.Exist(objs1) self._operator = task
def __init__(self): objs1 = tg.Select(shape=sg.random_shape(), when='now') self._operator = tg.Exist(objs1)
def testCompareChild(self): objs1 = tg.Select(color=sg.Color('red'), when='now') bool1 = tg.Exist(objs1) go1 = tg.Go(objs1) self.assertEqual(bool1.child[0], go1.child[0])
def __init__(self): self._color1 = sg.random_color() objs1 = tg.Select(color=self._color1, when='now') shape1 = tg.GetShape(objs1) objs2 = tg.Select(color=self._color1, shape=shape1, when='last1') self._operator = tg.Exist(objs2)
def __init__(self): objs1 = tg.Select(when='now') color1 = tg.GetColor(objs1) shape1 = tg.GetShape(objs1) objs2 = tg.Select(color=color1, shape=shape1, when='last1') self._operator = tg.Exist(objs2)
def __init__(self): color1, color2 = sg.sample_color(2) objs1 = tg.Select(color=color1, when=sg.random_when()) shape1 = tg.GetShape(objs1) objs2 = tg.Select(color=color2, shape=shape1, when='now') self._operator = tg.Exist(objs2)
def __init__(self): objs1 = tg.Select(color=sg.random_color(), when='now') self._operator = tg.Exist(objs1)