Example #1
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))
Example #2
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))
Example #3
0
    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()

    htm.execute(flipDataGenerator(htm), ticks=180, postTick=history.update)

    print """*************** Graph History **************
Y-Axis: All cells in the network, with the 4 cells per column grouped together
X-Axis: Time
Colors:
\tblack: no activity
\tgray: predicting
\twhite: active
    
Notice that the network settles down very quickly at the left, but not completely.  You will typically see artifacts around 100 steps in (about halfway across the image).

At each time step, the input data is flipping bits. So you will see some cells alternating at every time step, some cells that are active either way, and some cells that are never active.  
"""
Example #4
0
        [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)
    
    #this method should update the data matrix in place
    def dataUpdate(data):
        'flip all bits in data matrix'
        for x in xrange(len(data)):
            data[x]=map(lambda bit: not bit, data[x])
    
    #track htm's data history with
    history = ExciteHistory()
    
    htm.execute(data, dataUpdate, ticks=90, postTick=history.update)
    
    #TODO show output more effectively
    for cell in htm.cells:
        print cell
    for col in htm.columns:
        print col
        
    print "\n\n*************** Graph History **************\n\n"
        
    print history.text_graph()
    
    #TODO save htm state to disk