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()
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()
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))
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)
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))
''' 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)
''' 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
''' 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
''' 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
''' 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
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')
''' 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)]
''' 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
""" 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)
''' 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)
def __init__(self): self.inhibitionRadius = config.getint('init', 'inhibitionRadius') self.cellsPerColumn = config.getint('init','cells_per_column')