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
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))
def setUp(self): self.htm = HTM() self.data = [[1, 0, 1], [0, 0, 1]] #2d format, same dimensions as htm (for now) pass
#start with non-flipped data yield htm._data while True: #flip all data dataFlipped = deepcopy(htm._data) for x in xrange(len(dataFlipped)): for y in xrange(len(dataFlipped[0])): dataFlipped[x][y] = not dataFlipped[x][y] yield dataFlipped if __name__ == '__main__': htm = HTM() #prepare the initial data image in 2d format, same dimensions as htm, for now data = [ [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1, 1], [0, 0, 1, 0, 1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 0, 1], [0, 0, 0, 1, 1, 0, 0, 0, 1, 1], ] htm.initialize_input(data) #track htm's data history with history = ExciteHistory()
def setUp(self): self.col = Column(HTM(), 0, 0, 4) pass