コード例 #1
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)
コード例 #2
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #3
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #4
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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):
     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))
コード例 #6
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    def testIsSameGuessObjsetManyEpochs(self):
        objs1 = tg.Select(shape=sg.Shape('square'), when='last1')
        objs2 = tg.Select(shape=sg.Shape('circle'), when='now')
        attr1 = tg.GetColor(objs1)
        attr2 = tg.GetColor(objs2)
        task = tg.Task(tg.IsSame(attr1, attr2))

        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)
コード例 #7
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #8
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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])
コード例 #9
0
    def __init__(self):
        shape1, shape2, shape3 = sg.sample_shape(3)
        color1, color2 = sg.sample_color(2)
        when1 = sg.random_when()
        when2 = sg.random_when()

        objs1 = tg.Select(shape=shape1, when=when1)
        objs2 = tg.Select(shape=shape2, when=when2)
        a1 = tg.GetColor(objs1)
        a2 = tg.GetColor(objs2)
        bool1 = tg.IsSame(a1, a2)

        objs3 = tg.Select(color=color1, shape=shape3)
        objs4 = tg.Select(color=color2, shape=shape3)
        go1 = tg.Go(objs3)
        go2 = tg.Go(objs4)
        self._operator = tg.Switch(bool1, go1, go2, both_options_avail=True)
コード例 #10
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
コード例 #11
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())
        color11 = tg.GetColor(objs1)
        color21 = tg.GetColor(objs2)
        color12, color22 = sg.random_color(), sg.random_color()
        if random.random() > 0.5:
            bool1 = tg.IsSame(color11, color12)
        else:
            bool1 = tg.IsSame(color11, color12)
        if random.random() > 0.5:
            bool2 = tg.IsSame(color21, color22)
        else:
            bool2 = tg.IsSame(color21, color22)

        self._operator = tg.And(bool1, bool2)
コード例 #12
0
 def __init__(self):
     objs1 = tg.Select(shape=sg.random_shape(), when=sg.random_when())
     a2 = sg.random_color()
     a1 = tg.GetColor(objs1)
     if random.random() > 0.5:
         self._operator = tg.IsSame(a1, a2)
     else:
         self._operator = tg.IsSame(a2, a1)
コード例 #13
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
 def testGetGuessObjset(self):
     objset = sg.ObjectSet(n_epoch=10)
     objs = tg.Select()
     task = tg.Task(tg.GetColor(objs))
     epoch_now = 1
     objset = task.guess_objset(objset, epoch_now)
     l = len(objset.select(epoch_now, when='now'))
     self.assertEqual(1, l)
コード例 #14
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #15
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #16
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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)
コード例 #17
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=sg.random_when(),
                       space_type=sg.random_space())
     self._operator = tg.GetColor(objs2)
コード例 #18
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
 def testBasicIsSameGuessObject(self):
     objset = sg.ObjectSet(n_epoch=10)
     objs1 = tg.Select(shape=sg.Shape('square'), when='now')
     attr1 = tg.GetColor(objs1)
     task = tg.Task(tg.IsSame(attr1, sg.Color('red')))
     epoch_now = 1
     objset = task.guess_objset(objset, epoch_now, should_be=True)
     c1 = objset.select(epoch_now, shape=sg.Shape('square'),
                        when='now')[0].color
     self.assertEqual(c1, sg.Color('red'))
コード例 #19
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    def testGetGuessObjsetShouldBe(self):
        objset = sg.ObjectSet(n_epoch=10)
        objs = tg.Select(when='now')
        task = tg.Task(tg.GetColor(objs))

        for epoch_now in range(10):
            color = sg.random_color()
            objset = task.guess_objset(objset, epoch_now, should_be=color)
            o = objset.select(epoch_now, when='now')[0]
            self.assertEqual(color, o.color)
コード例 #20
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    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))
コード例 #21
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    def testGetCall(self):
        objset = sg.ObjectSet(n_epoch=10)
        obj1 = tg.Select(color=sg.Color('red'), when='now')
        color1 = tg.GetColor(obj1)

        epoch_now = 1
        color1_eval = color1(objset, epoch_now)
        self.assertEqual(color1_eval, const.INVALID)

        objset.add(sg.Object([sg.Color('red')], when='now'), epoch_now)
        color1_eval = color1(objset, epoch_now)
        self.assertEqual(color1_eval, sg.Color('red'))
コード例 #22
0
ファイル: task_generator_test.py プロジェクト: yazici/cog
    def testIsSameGuessObjsetWithDistractors(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))

        n_epoch = 10
        objset = sg.ObjectSet(n_epoch=n_epoch)
        obj1 = sg.Object(
            [sg.Color('green'), sg.Shape('square')],
            when='now',
            deletable=True)
        objset.add(obj1, 0, add_if_exist=True)
        obj1 = sg.Object([sg.Color('red'), sg.Shape('circle')],
                         when='now',
                         deletable=True)
        objset.add(obj1, 0, add_if_exist=True)
        objset = task.guess_objset(objset, 0, should_be=True)
        objset.add_distractor(1)
        objset = task.guess_objset(objset, 1, should_be=True)
        self.assertTrue(task(objset, 1))
コード例 #23
0
    def __init__(self):
        shape1, shape2 = sg.sample_shape(2)
        when1 = sg.random_when()
        a2 = sg.random_color()
        color1, color2 = sg.sample_color(2)

        objs1 = tg.Select(shape=shape1, when=when1)
        a1 = tg.GetColor(objs1)

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

        objs2 = tg.Select(color=color1, shape=shape2)
        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)
コード例 #24
0
 def __init__(self):
     when = sg.random_when()
     shape = sg.random_shape()
     objs1 = tg.Select(shape=shape, when=when)
     self._operator = tg.GetColor(objs1)
コード例 #25
0
 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)
コード例 #26
0
 def __init__(self):
     self._shape1 = sg.random_shape()
     objs1 = tg.Select(shape=self._shape1, when='now')
     color1 = tg.GetColor(objs1)
     objs2 = tg.Select(color=color1, shape=self._shape1, when='last1')
     self._operator = tg.Exist(objs2)
コード例 #27
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)