Exemple #1
0
 def __init__(self, cellsPerColumn=None):
     self.inhibitionRadius = config.getint('init', 'inhibitionRadius')
     if cellsPerColumn:
         self.cellsPerColumn = cellsPerColumn
     else:
         self.cellsPerColumn = config.getint('init','cells_per_column')
         
     self._inputCells = [[]] #a 2-d map of cells monitoring input
     self._updateSegments = UpdateSegments()
Exemple #2
0
    def __init__(self, cellsPerColumn=None):
        self.inhibitionRadius = config.getint('init', 'inhibitionRadius')
        if cellsPerColumn:
            self.cellsPerColumn = cellsPerColumn
        else:
            self.cellsPerColumn = config.getint('init', 'cells_per_column')

        self._inputCells = [[]]  #a 2-d map of cells monitoring input
        self._updateSegments = UpdateSegments()
Exemple #3
0
    def testCreateSegment(self):
        h = HTM()
        h.initialize_input([[1, 1, 1], [1, 1, 1]])
        cell = Cell()
        startingSegments = config.getint("init", "segments_per_cell")
        self.assertEqual(startingSegments, len(cell.segments))
        cell.create_segment(h)
        self.assertEqual(startingSegments + 1, len(cell.segments))

        # make sure newly created segment has the right number of synapses
        self.assertNotEqual(0, len(cell.segments[-1].synapses))
Exemple #4
0
 def testInit(self):
     htm = self.htm
     
     self._initialize()
     self.assertEqual(htm.width, 2)
     self.assertEqual(htm.length, 3)
     cols = 0
     for col in htm.columns:
         cols += 1
         self.assertEqual(len(col.synapses), config.getint('init', 'synapses_per_segment'))
         
     self.assertEqual(cols, 6)
Exemple #5
0
    def testInit(self):
        htm = self.htm

        self._initialize()
        self.assertEqual(htm.width, 2)
        self.assertEqual(htm.length, 3)
        cols = 0
        for col in htm.columns:
            cols += 1
            self.assertEqual(len(col.synapses),
                             config.getint('init', 'synapses_per_segment'))

        self.assertEqual(cols, 6)
Exemple #6
0
 def testCreateSegment(self):
     htm = Mock()
     learning = Mock()
     learning.wasLearning = True
     active = Mock()
     active.wasLearning = False
     active.wasActive = True
     htm.cells = [learning, active, active]
     cell = Cell()
     
     self.assertNotEqual(cell, learning)
     
     startingSegments = config.getint('init','segments_per_cell')
     self.assertEqual(startingSegments, len(cell.segments))
     cell.create_segment(htm, nextStep=False)
     self.assertEqual(startingSegments+1, len(cell.segments))
     cell.create_segment(htm, nextStep=True)
     self.assertEqual(startingSegments+2, len(cell.segments))
     
     #make sure newly created segment has the right number of synapses
     self.assertNotEqual(0, len(cell.segments[-2].synapses))
     self.assertNotEqual(0, len(cell.segments[-1].synapses))
Exemple #7
0
'''
Created on Nov 26, 2010

@author: Numenta, Inc.
translated to python by Jason Carver

Reproduced from "HTM Cortical Learning Algorithms" v0.1.1 at:
http://www.numenta.com/htm-overview/education.php 
'''

from carver.htm.config import config
from carver.htm.synapse import CONNECTED_CUTOFF
from carver.htm.segment import Segment

#one column out of n should fire:
desiredLocalActivity = config.getint('constants','desiredLocalActivity')

def pool_spatial(htm):
    '''
    A couple notable deviations:
    *column overlap boost and cutoff are swapped from pseudocode, details inline
        see _spatial_overlap
    *time and inputData removed from code - used a data producer model, linked to htm 
    *getBestMatchingSegment now takes an argument for whether it is a nextStep segment or a sequence one
        inspired by binarybarry on http://www.numenta.com/phpBB2/viewtopic.php?t=1403
    '''
    
    _spatial_overlap(htm)
    
    activeColumns = _spatial_inhibition(htm)
            
Exemple #8
0
'''
Created on Nov 27, 2010

@author: Jason
'''
from carver.htm.config import config
from carver.htm.segment import Segment
from carver.htm.synapse import MIN_THRESHOLD, SYNAPSES_PER_SEGMENT
import random

SEGMENTS_PER_CELL = config.getint('init', 'segments_per_cell')


class Cell(object):
    '''
    Cell in an HTM network
    '''
    def __init__(self, column=None, layer=None):
        '''
        @param layer the inner layer of the cell, so an HTM with 3 cells per column
            would have cells with layers 0, 1 and 2
        '''
        self.column = column
        self.layer = layer

        self.active = False
        self.__wasActive = False  #read-only
        self.predicting = False
        self.__predicted = False  #read-only
        self.learning = False
        self.__wasLearning = False  #read-only
Exemple #9
0
'''
Created on Nov 27, 2010

@author: Jason Carver
'''
from carver.htm.config import config

CONNECTED_CUTOFF = 0.2 #this is the permanence cutoff to be considered connected
PERMANENCE_INCREMENT = 0.04 #TODO: choose a reasonable number
PERMANENCE_DECREMENT = 0.04 #TODO: choose a reasonable number
MIN_THRESHOLD = config.getint('constants','min_synapses_per_segment_threshold')
SYNAPSES_PER_SEGMENT = config.getint('init', 'synapses_per_segment')

class Synapse(object):
    '''
    a single synapse between dendrite and axon
    '''


    def __init__(self, input, permanence = (CONNECTED_CUTOFF-.001)):
        '''
        @param input: the source of data coming into the synapse
        synapses on distal dendrites will have a Cell as input
        synapses on proximal dendrites will have an InputCell as input
        '''
        self.permanence = permanence
        self.input = input
        
    @property
    def connected(self):
        return self.permanence >= CONNECTED_CUTOFF
Exemple #10
0
'''
Created on Dec 2, 2010

@author: Jason Carver
'''
from carver.htm.config import config
from carver.htm.synapse import Synapse
import random

#how many synapses need to fire to trigger a segment fire
FRACTION_SEGMENT_ACTIVATION_THRESHOLD = float(
    config.getint('constants', 'percent_synapses_per_segment_threshold')) / 100
MAX_NEW_SYNAPSES = config.getint('constants', 'max_new_synapses')


class Segment(object):
    '''
    A group of synapses that act as a non-linear threshold detector.
    After a certain number of synapses fire, the segment  
    
    Note: a typical threshold for how many synapses on a dendrite need to fire 
    for a spike is 15 (not sure how many synapses total) source 0.1.1 HTM doc,
    Appendix A, distal dendrites, page 55.
    '''
    def __init__(self, distal=True, nextStep=False):
        '''
        @param nextStep: boolean for whether this segment indicates predicted 
            firing in the very next time step 
        '''
        self.synapses = []
        self.distal = distal
Exemple #11
0
'''
Created on Dec 2, 2010

@author: Jason Carver
'''
from carver.htm.config import config
from carver.htm.synapse import Synapse
import random

#how many synapses need to fire to trigger a segment fire
FRACTION_SEGMENT_ACTIVATION_THRESHOLD = float(config.getint('constants','percent_synapses_per_segment_threshold'))/100
MAX_NEW_SYNAPSES = config.getint('constants','max_new_synapses')

class Segment(object):
    '''
    A group of synapses that act as a non-linear threshold detector.
    After a certain number of synapses fire, the segment  
    
    Note: a typical threshold for how many synapses on a dendrite need to fire 
    for a spike is 15 (not sure how many synapses total) source 0.1.1 HTM doc,
    Appendix A, distal dendrites, page 55.
    '''


    def __init__(self, distal=True, nextStep=False):
        '''
        @param nextStep: boolean for whether this segment indicates predicted 
            firing in the very next time step 
        '''
        self.synapses = []
        self.distal = distal
Exemple #12
0
 def __init__(self, cellsPerColumn=None):
     self.inhibitionRadius = config.getint('init', 'inhibitionRadius')
     if cellsPerColumn:
         self.cellsPerColumn = cellsPerColumn
     else:
         self.cellsPerColumn = config.getint('init','cells_per_column')
Exemple #13
0
'''
Created on Nov 27, 2010

@author: Jason
'''
from carver.htm.config import config
from carver.htm.segment import Segment
from carver.htm.synapse import MIN_THRESHOLD, SYNAPSES_PER_SEGMENT
import random

SEGMENTS_PER_CELL = config.getint('init','segments_per_cell')

class Cell(object):
    '''
    Cell in an HTM network
    '''


    def __init__(self):
        '''
        
        '''
        self.active = False
        self.__wasActive = False #read-only
        self.predicting = False
        self.__predicted = False #read-only
        self.learning = False
        self.__wasLearning = False #read-only
        
        self.segments = [Segment() for i in xrange(SEGMENTS_PER_CELL)]
       
Exemple #14
0
'''
Created on Nov 27, 2010

@author: Jason Carver
'''
from carver.htm.config import config

CONNECTED_CUTOFF = 0.2  #this is the permanence cutoff to be considered connected
PERMANENCE_INCREMENT = 0.04  #TODO: choose a reasonable number
PERMANENCE_DECREMENT = 0.04  #TODO: choose a reasonable number
MIN_THRESHOLD = config.getint('constants',
                              'min_synapses_per_segment_threshold')
SYNAPSES_PER_SEGMENT = config.getint('init', 'synapses_per_segment')


class Synapse(object):
    '''
    a single synapse between dendrite and axon
    '''
    def __init__(self, input, permanence=(CONNECTED_CUTOFF - .001)):
        '''
        @param input: the source of data coming into the synapse
        synapses on distal dendrites will have a Cell as input
        synapses on proximal dendrites will have an InputCell as input
        '''
        self.permanence = permanence
        self.input = input

    @property
    def connected(self):
        return self.permanence >= CONNECTED_CUTOFF
Exemple #15
0
"""
Created on Nov 26, 2010

@author: Numenta, Inc.
translated to python by Jason Carver

Reproduced from "HTM Cortical Learning Algorithms" v0.1.1 at:
http://www.numenta.com/htm-overview/education.php 
"""

from carver.htm.config import config
from carver.htm.synapse import CONNECTED_CUTOFF
from carver.htm.column import Column

# one column out of n should fire:
desiredLocalActivity = config.getint("constants", "desiredLocalActivity")


def pool_spatial(htm):
    """
    A couple notable deviations:
    *column overlap boost and cutoff are swapped from pseudocode, details inline
        see _spatial_overlap
    *time and inputData removed from code - used a data producer model, linked to htm 
    """

    _spatial_overlap(htm)

    activeColumns = _spatial_inhibition(htm)

    inhibitionRadius = _spatial_learning(htm, activeColumns)
Exemple #16
0
'''
Created on Nov 26, 2010

@author: Numenta, Inc.
translated to python by Jason Carver

Reproduced from "HTM Cortical Learning Algorithms" v0.1.1 at:
http://www.numenta.com/htm-overview/education.php 
'''

from carver.htm.config import config
from carver.htm.synapse import CONNECTED_CUTOFF
from carver.htm.segment import Segment

#one column out of n should fire:
desiredLocalActivity = config.getint('constants', 'desiredLocalActivity')


def pool_spatial(htm):
    '''
    A couple notable deviations:
    *column overlap boost and cutoff are swapped from pseudocode, details inline
        see _spatial_overlap
    *time and inputData removed from code - used a data producer model, linked to htm 
    *getBestMatchingSegment now takes an argument for whether it is a nextStep segment or a sequence one
        inspired by binarybarry on http://www.numenta.com/phpBB2/viewtopic.php?t=1403
    '''

    _spatial_overlap(htm)

    activeColumns = _spatial_inhibition(htm)
Exemple #17
0
 def __init__(self):
     self.inhibitionRadius = config.getint('init', 'inhibitionRadius')
     self.cellsPerColumn = config.getint('init','cells_per_column')