Exemple #1
0
 def __init__(self):
     color1, color2 = sg.sample_color(2)
     objs1 = tg.Select(color=color1, when=sg.random_when())
     objs2 = tg.Select(color=color2, when=sg.random_when())
     a1 = tg.GetShape(objs1)
     a2 = tg.GetShape(objs2)
     self._operator = tg.IsSame(a1, a2)
Exemple #2
0
 def __init__(self):
     color1, color2, color3 = sg.sample_color(3)
     objs1 = tg.Select(color=color1, when='latest')
     shape1 = tg.GetShape(objs1)
     objs2 = tg.Select(color=color2, shape=shape1, when='now')
     self._operator = tg.Go(objs2)
     self._color1, self._color2, self._color3 = color1, color2, color3
Exemple #3
0
 def __init__(self):
     shape1, shape2 = sg.sample_shape(2)
     objs1 = tg.Select(shape=shape1, when=sg.random_when())
     objs2 = tg.Select(shape=shape2, when=sg.random_when())
     a1 = tg.GetColor(objs1)
     a2 = tg.GetColor(objs2)
     self._operator = tg.IsSame(a1, a2)
Exemple #4
0
 def __init__(self):
     shape1, shape2 = sg.sample_shape(2)
     objs1 = tg.Select(shape=shape1, when='now')
     objs2 = tg.Select(shape=shape2, when=sg.random_when())
     self._operator = tg.Switch(tg.Exist(objs1),
                                tg.Go(objs1),
                                tg.Go(objs2),
                                both_options_avail=False)
Exemple #5
0
 def __init__(self):
     color1, color2 = sg.sample_color(2)
     objs1 = tg.Select(color=color1, when='now')
     objs2 = tg.Select(color=color2, when=sg.random_when())
     self._operator = tg.Switch(tg.Exist(objs1),
                                tg.Go(objs1),
                                tg.Go(objs2),
                                both_options_avail=False)
Exemple #6
0
    def testGenerateObjset(self):
        objs1 = tg.Select(shape=sg.Shape('square'), when='last1')
        objs2 = tg.Select(shape=sg.Shape('circle'), when='last1')
        attr1 = tg.GetColor(objs1)
        attr2 = tg.GetColor(objs2)
        task = tg.Task(tg.IsSame(attr1, attr2))

        task.generate_objset(n_epoch=20, n_distractor=3, average_memory_span=3)
Exemple #7
0
    def __init__(self):
        shape1, shape2, shape3 = sg.sample_shape(3)
        objs1 = tg.Select(shape=shape1, when='latest')
        color1 = tg.GetColor(objs1)
        objs2 = tg.Select(color=color1, shape=shape2, when='now')
        self._operator = tg.Go(objs2)

        self._shape1, self._shape2, self._shape3 = shape1, shape2, shape3
Exemple #8
0
 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)
Exemple #9
0
 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)
Exemple #10
0
    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)
Exemple #11
0
    def testSetChild(self):
        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)
        and1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2))

        self.assertEqual(len(and1.child), 2)
Exemple #12
0
    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)
Exemple #13
0
 def __init__(self):
     shape1, shape2, shape3, shape4 = sg.sample_shape(4)
     objs1 = tg.Select(shape=shape1, when=sg.random_when())
     objs2 = tg.Select(shape=shape2, when=sg.random_when())
     objs3 = tg.Select(shape=shape3, when=sg.random_when())
     objs4 = tg.Select(shape=shape4, when=sg.random_when())
     a1 = tg.GetColor(objs1)
     a2 = tg.GetColor(objs2)
     a3 = tg.GetColor(objs3)
     a4 = tg.GetColor(objs4)
     self._operator = tg.And(tg.IsSame(a1, a2), tg.IsSame(a3, a4))
Exemple #14
0
 def __init__(self):
     color1, color2, color3, color4 = sg.sample_color(4)
     objs1 = tg.Select(color=color1, when=sg.random_when())
     objs2 = tg.Select(color=color2, when=sg.random_when())
     objs3 = tg.Select(color=color3, when=sg.random_when())
     objs4 = tg.Select(color=color4, when=sg.random_when())
     a1 = tg.GetShape(objs1)
     a2 = tg.GetShape(objs2)
     a3 = tg.GetShape(objs3)
     a4 = tg.GetShape(objs4)
     self._operator = tg.And(tg.IsSame(a1, a2), tg.IsSame(a3, a4))
Exemple #15
0
    def testAndOperatorSize(self):
        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)
        and1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2))

        task = tg.Task(and1)
        self.assertEqual(task.operator_size, 9)
Exemple #16
0
    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))
Exemple #17
0
 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)
Exemple #18
0
    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)
Exemple #19
0
    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)
Exemple #20
0
    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))
Exemple #21
0
    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)
Exemple #22
0
    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)
Exemple #23
0
    def testIsSameGuessObjsetLast1(self):
        objset = sg.ObjectSet(n_epoch=10)
        objs1 = tg.Select(shape=sg.Shape('square'), when='last1')
        objs2 = tg.Select(shape=sg.Shape('circle'), when='last1')
        attr1 = tg.GetColor(objs1)
        attr2 = tg.GetColor(objs2)
        task = tg.Task(tg.IsSame(attr1, attr2))

        objset = task.guess_objset(objset, epoch_now=1, should_be=True)
        self.assertEqual(2, len(objset.select(epoch_now=0, when='now')))
        c1 = objset.select(epoch_now=0, shape=sg.Shape('square'),
                           when='now')[0].color
        c2 = objset.select(epoch_now=0, shape=sg.Shape('circle'),
                           when='now')[0].color
        self.assertEqual(c1, c2)
Exemple #24
0
    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)
Exemple #25
0
    def testTopoSort(self):
        objs = tg.Select()
        color = tg.GetColor(objs)
        task = tg.Task(color)

        sorted_nodes = task.topological_sort()
        self.assertListEqual(sorted_nodes, [color, objs])
Exemple #26
0
    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)
Exemple #27
0
    def testGetSpaceGuessObjset(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.GetShape(objs2))

        n_epoch = 2
        objset = sg.ObjectSet(n_epoch=n_epoch)
        for i_epoch in range(n_epoch)[::-1]:
            objset = task.guess_objset(objset, i_epoch)
        o1 = objset.select(0, color=sg.Color('red'), when='now')[0]
        o2 = objset.select(1, color=sg.Color('blue'), when='now')[0]
        self.assertLess(o2.loc.value[0], o1.loc.value[0])
Exemple #28
0
    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)
Exemple #29
0
    def __init__(self):
        color1, color2, color3 = sg.sample_color(3)
        shape3, shape4 = sg.sample_shape(2)
        when1 = sg.random_when()
        when2 = sg.random_when()

        objs1 = tg.Select(color=color1, when=when1)
        objs2 = tg.Select(color=color2, when=when2)
        s1 = tg.GetShape(objs1)
        s2 = tg.GetShape(objs2)
        bool1 = tg.IsSame(s1, s2)
        objs3 = tg.Select(color=color3, shape=shape3)
        objs4 = tg.Select(color=color3, shape=shape4)
        go1 = tg.Go(objs3)
        go2 = tg.Go(objs4)
        self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
Exemple #30
0
    def testGetAllNodes(self):
        objs = tg.Select()
        color = tg.GetColor(objs)
        task = tg.Task(color)

        all_nodes = task._all_nodes
        for op in [objs, color]:
            self.assertIn(op, all_nodes)