示例#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)
示例#2
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)
示例#3
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))
示例#4
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)
示例#5
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)
示例#6
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
示例#7
0
    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)
示例#8
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())
        shape11 = tg.GetShape(objs1)
        shape21 = tg.GetShape(objs2)
        shape12, shape22 = sg.random_shape(), sg.random_shape()
        if random.random() > 0.5:
            bool1 = tg.IsSame(shape11, shape12)
        else:
            bool1 = tg.IsSame(shape11, shape12)
        if random.random() > 0.5:
            bool2 = tg.IsSame(shape21, shape22)
        else:
            bool2 = tg.IsSame(shape21, shape22)

        self._operator = tg.And(bool1, bool2)
示例#9
0
 def __init__(self):
     objs1 = tg.Select(color=sg.random_color(), when=sg.random_when())
     a2 = sg.random_shape()
     a1 = tg.GetShape(objs1)
     if random.random() > 0.5:
         self._operator = tg.IsSame(a1, a2)
     else:
         self._operator = tg.IsSame(a2, a1)
示例#10
0
    def testAndGuessObjset(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)
        task = tg.Task(tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2)))

        objset = sg.ObjectSet(n_epoch=10)
        obj0 = sg.Object([sg.Color('green'), sg.Shape('square')], when='now')
        obj1 = sg.Object([sg.Color('red'), sg.Shape('circle')], when='now')
        objset.add(obj0, epoch_now=0)
        objset.add(obj1, epoch_now=1)
        objset = task.guess_objset(objset, epoch_now=2, should_be=True)
        obj2 = objset.last_added_obj
        self.assertEqual(obj1.color.value, obj2.color.value)
        self.assertEqual(obj1.shape.value, obj2.shape.value)
示例#11
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=sg.random_when(),
                       space_type=sg.random_space())
     self._operator = tg.GetShape(objs2)
示例#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)
示例#13
0
    def testGetGuessObjsetLast1(self):
        objs1 = tg.Select(color=sg.Color('red'), when='last1')
        task = tg.Task(tg.GetShape(objs1))

        n_epoch = 10
        objset = task.generate_objset(n_epoch,
                                      n_distractor=0,
                                      average_memory_span=2)
        target = [task(objset, epoch_now) for epoch_now in range(n_epoch)]

        n_invalid = sum([t == const.INVALID for t in target])

        self.assertLessEqual(n_invalid, 1)
示例#14
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])
示例#15
0
    def testAverageMemorySpan(self):
        n_epoch = 1000
        average_memory_span = 10

        objs1 = tg.Select(color=sg.Color('red'), when='last1')
        task = tg.Task(tg.GetShape(objs1))
        time1 = tg.GetTime(objs1)

        objset = task.generate_objset(n_epoch,
                                      n_distractor=1,
                                      average_memory_span=average_memory_span)
        memory_spans = list()
        for epoch_now in range(1, n_epoch):
            time1_val = time1(objset, epoch_now)
            memory_span = epoch_now - time1_val
            memory_spans.append(memory_span)

        avg_mem_span_estimation = sum(memory_spans) * 1.0 / len(memory_spans)
        self.assertLess(abs(avg_mem_span_estimation - average_memory_span), 2)
示例#16
0
    def __init__(self):
        color1, color2 = sg.sample_color(2)
        when1 = sg.random_when()
        a2 = sg.random_shape()
        shape1, shape2 = sg.sample_shape(2)

        objs1 = tg.Select(color=color1, when=when1)
        a1 = tg.GetShape(objs1)

        if random.random() > 0.5:
            bool1 = tg.IsSame(a1, a2)
        else:
            bool1 = tg.IsSame(a2, a1)

        objs2 = tg.Select(color=color2, shape=shape1)
        objs3 = tg.Select(color=color2, shape=shape2)
        go1 = tg.Go(objs2)
        go2 = tg.Go(objs3)
        self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
示例#17
0
    def manualAverageMemorySpan(self):
        n_epoch = 6
        average_memory_span = 1.67

        memory_spans = list()
        for _ in range(3000):
            objs1 = tg.Select(color=sg.Color('red'), when='last1')
            task = tg.Task(tg.GetShape(objs1))
            time1 = tg.GetTime(objs1)

            objset = task.generate_objset(
                n_epoch,
                n_distractor=1,
                average_memory_span=average_memory_span)
            for epoch_now in range(1, n_epoch):
                time1_val = time1(objset, epoch_now)
                memory_span = epoch_now - time1_val
                memory_spans.append(memory_span)

        avg_mem_span_estimation = sum(memory_spans) * 1.0 / len(memory_spans)
        print("avg_mem_span_estimation:", avg_mem_span_estimation)
示例#18
0
 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)
示例#19
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)
示例#20
0
 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)
示例#21
0
 def __init__(self):
     when = sg.random_when()
     color = sg.random_color()
     objs1 = tg.Select(color=color, when=when)
     self._operator = tg.GetShape(objs1)