예제 #1
0
 def testFlashCards(self):
     mat1 = [[1,0,0],[0,1,1]]
     mat2 = [[1,0,1],[0,1,0]]
     mat3 = [[0,1,1],[1,0,0]]
     swap = FlashCards(3, mat1, mat2, mat3)
     
     data = [[0,0,0],[0,0,0]]
     iterator = iter(swap.dataGenerator())
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat2)
     next = iterator.next()
     self.assertEqual(next, mat2)
     next = iterator.next()
     self.assertEqual(next, mat2)
     next = iterator.next()
     self.assertEqual(next, mat3)
     next = iterator.next()
     self.assertEqual(next, mat3)
     next = iterator.next()
     self.assertEqual(next, mat3)
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat1)
     next = iterator.next()
     self.assertEqual(next, mat2)
예제 #2
0
 def setUp(self):
     mat1 = [[1,0,0],[0,1,1]]
     mat2 = [[1,0,1],[0,1,0]]
     mat3 = [[0,1,1],[1,0,0]]
     self.matrices = [mat1, mat2, mat3]
     cards = FlashCards(1, mat1, mat2, mat3)
     htm = HTM()
     htm.initialize_input(mat1)
     htm.execute(dataGenerator=cards.dataGenerator(), ticks=3*10, learning=True)
     
     self.htm = htm
예제 #3
0
    def testFullFieldStaticImage(self):
        print_htm_state = False
        
        h = HTM(cellsPerColumn=1)
        h.initialize_input(self.sea_anemone)
        
        #learn the different static data images
        swap = FlashCards(90, self.sea_anemone, self.seastar, self.sea_cucumber, self.hermitcrab)
        h.execute(self.sea_anemone, swap.updateMatrix, ticks=90*4*3)
        
        #run the htm network through and save the state in a history object
        swap = FlashCards(10, self.sea_anemone, self.seastar, self.sea_cucumber, self.hermitcrab)
        history = ExciteHistory(temporal=False)
        h.execute(self.sea_anemone, swap.updateMatrix, ticks=10*4, learning=False, postTick=history.update)
        
        #label the different static data images
        recognize = ObjectRecognize()
        recognize.label('sea_anemone', history.data[-31])
        recognize.label('seastar', history.data[-21])
        recognize.label('sea_cucumber', history.data[-11])
        recognize.label('hermitcrab', history.data[-1])
        
        if print_htm_state:
            print "\n\n*************** Recognition Labeling **************\n\n"
            print history.text_graph()


        #test recognition of the different static data images
        swap.reset()
        history = ExciteHistory(temporal=False)
        h.execute(self.sea_anemone, swap.updateMatrix, ticks=10*4, learning=False, postTick=history.update)

        if print_htm_state:
            print "\n\n*************** Recognition Testing **************\n\n"
            print history.text_graph()
        
        
        #show and test recognition data
        testnames = ['sea_anemone', 'seastar', 'sea_cucumber', 'hermitcrab']
        testdata = history.data[9:40:10]
        
        print recognize.getMatchText(testnames, testdata)
        
        for x, labelrow in enumerate(recognize.getMatchData(testnames, testdata)):
            for y, match_percent in enumerate(labelrow):
                if x == y:
                    self.assertGreaterEqual(match_percent, 0.9, 
                        msg='htm did not correctly recognize the %s (%.1f%% match)' % (
                            testnames[x], match_percent*100))
                else:
                    self.assertLessEqual(match_percent, 0.8,
                        msg='htm thought it recognized a %s, when it saw a %s (%.1f%% match)' %(
                            testnames[x], testnames[y], match_percent*100))
예제 #4
0
    def setUp(self):
        mat1 = [[1, 0, 0], [0, 1, 1]]
        mat2 = [[1, 0, 1], [0, 1, 0]]
        mat3 = [[0, 1, 1], [1, 0, 0]]
        self.matrices = [mat1, mat2, mat3]
        cards = FlashCards(1, mat1, mat2, mat3)
        htm = HTM()
        htm.initialize_input(mat1)
        htm.execute(dataGenerator=cards.dataGenerator(),
                    ticks=3 * 10,
                    learning=True)

        self.htm = htm
예제 #5
0
    def testFullFieldStaticImage(self):
        print_htm_state = False

        h = HTM(cellsPerColumn=1)
        h.initialize_input(self.sea_anemone, compressionFactor=3.5)

        #learn the different static data images
        swap = FlashCards(90, self.sea_anemone, self.seastar,
                          self.sea_cucumber, self.hermitcrab)
        h.execute(swap.dataGenerator(), ticks=90 * 4 * 3 - 1)

        #run the htm network through and save the state in a history object
        swap = FlashCards(10, self.sea_anemone, self.seastar,
                          self.sea_cucumber, self.hermitcrab)
        history = ExciteHistory(temporal=False)
        h.execute(swap.dataGenerator(),
                  ticks=10 * 4 - 1,
                  learning=False,
                  postTick=history.update)

        #label the different static data images
        recognize = ObjectRecognize()
        recognize.label('sea_anemone', history.data[-31])
        recognize.label('seastar', history.data[-21])
        recognize.label('sea_cucumber', history.data[-11])
        recognize.label('hermitcrab', history.data[-1])

        if print_htm_state:
            print "\n\n*************** Recognition Labeling **************\n\n"
            print history.text_graph()

        #test recognition of the different static data images
        swap.reset()
        history = ExciteHistory(temporal=False)
        h.execute(swap.dataGenerator(),
                  ticks=10 * 4 - 1,
                  learning=False,
                  postTick=history.update)

        if print_htm_state:
            print "\n\n*************** Recognition Testing **************\n\n"
            print history.text_graph()

        #show and test recognition data
        testnames = ['sea_anemone', 'seastar', 'sea_cucumber', 'hermitcrab']
        testdata = history.data[9:40:10]

        print recognize.getMatchText(testnames, testdata)

        for x, labelrow in enumerate(
                recognize.getMatchData(testnames, testdata)):
            for y, match_percent in enumerate(labelrow):
                if x == y:
                    self.assertGreaterEqual(
                        match_percent,
                        0.9,
                        msg=
                        'htm did not correctly recognize the %s (%.1f%% match)'
                        % (testnames[x], match_percent * 100))
                else:
                    self.assertLessEqual(
                        match_percent,
                        0.8,
                        msg=
                        'htm thought it recognized a %s, when it saw a %s (%.1f%% match)'
                        % (testnames[x], testnames[y], match_percent * 100))
예제 #6
0
 def testFlashCards(self):
     mat1 = [[1,0,0],[0,1,1]]
     mat2 = [[1,0,1],[0,1,0]]
     mat3 = [[0,1,1],[1,0,0]]
     swap = FlashCards(3, mat1, mat2, mat3)
     
     data = [[0,0,0],[0,0,0]]
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat2)
     swap.updateMatrix(data)
     self.assertEqual(data, mat2)
     swap.updateMatrix(data)
     self.assertEqual(data, mat2)
     swap.updateMatrix(data)
     self.assertEqual(data, mat3)
     swap.updateMatrix(data)
     self.assertEqual(data, mat3)
     swap.updateMatrix(data)
     self.assertEqual(data, mat3)
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat1)
     swap.updateMatrix(data)
     self.assertEqual(data, mat2)