Class implementing the Temporal Memory algorithm.
More...
Inherits object.
Class implementing the Temporal Memory algorithm.
def __init__ 
( 

self, 



columnDimensions = (2048, , 



cellsPerColumn = 32 , 



activationThreshold = 13 , 



initialPermanence = 0.21 , 



connectedPermanence = 0.50 , 



minThreshold = 10 , 



maxNewSynapseCount = 20 , 



permanenceIncrement = 0.10 , 



permanenceDecrement = 0.10 , 



predictedSegmentDecrement = 0.0 , 



seed = 42 

) 
 
 Parameters

columnDimensions  (list) Dimensions of the column space 
cellsPerColumn  (int) Number of cells per column 
activationThreshold  (int) If the number of active connected synapses on a segment is at least this threshold, the segment is said to be active. 
initialPermanence  (float) Initial permanence of a new synapse. 
connectedPermanence  (float) If the permanence value for a synapse is greater than this value, it is said to be connected. 
minThreshold  (int) If the number of synapses active on a segment is at least this threshold, it is selected as the best matching cell in a bursting column. 
maxNewSynapseCount  (int) The maximum number of synapses added to a segment during learning. 
permanenceIncrement  (float) Amount by which permanences of synapses are incremented during learning. 
permanenceDecrement  (float) Amount by which permanences of synapses are decremented during learning. 
predictedSegmentDecrement  (float) Amount by which active permanences of synapses of previously predicted but inactive segments are decremented. 
seed  (int) Seed for the random number generator. 
def __eq__ 
( 

self, 



other 

) 
 
Equality operator for TemporalMemory instances.
Checks if two instances are functionally identical
(might have different internal state).
 Parameters

def __ne__ 
( 

self, 



other 

) 
 
Nonequality operator for TemporalMemory instances.
Checks if two instances are not functionally identical
(might have different internal state).
 Parameters

def activateCorrectlyPredictiveCells 
( 

self, 



prevPredictiveCells, 



prevMatchingCells, 



activeColumns 

) 
 
Phase 1: Activate the correctly predictive cells.
Pseudocode:
 for each prev predictive cell
 if in active column
 mark it as active
 mark it as winner cell
 mark column as predicted
 if not in active column
 mark it as an predicted but inactive cell
 Parameters

prevPredictiveCells  (set) Indices of predictive cells in t1 
activeColumns  (set) Indices of active columns in t 
 Returns
 (tuple) Contains:
activeCells
(set), winnerCells
(set), predictedColumns
(set), predictedInactiveCells
(set)
def activeSynapsesForSegment 
( 

segment, 



activeCells, 



connections 

) 
 

static 
Returns the synapses on a segment that are active due to lateral input from active cells.
 Parameters

segment  (int) Segment index 
activeCells  (set) Indices of active cells 
connections  (Connections) Connectivity of layer 
 Returns
 (set) Indices of active synapses on segment
def adaptSegment 
( 

self, 



segment, 



activeSynapses, 



connections, 



permanenceIncrement, 



permanenceDecrement 

) 
 
Updates synapses on segment.
Strengthens active synapses; weakens inactive synapses.
 Parameters

segment  (int) Segment index 
activeSynapses  (set) Indices of active synapses 
connections  (Connections) Connectivity of layer 
permanenceIncrement  (float) Amount to increment active synapses 
permanenceDecrement  (float) Amount to decrement inactive synapses 
def bestMatchingCell 
( 

self, 



cells, 



activeCells, 



connections 

) 
 
Gets the cell with the best matching segment (see TM.bestMatchingSegment
) that has the largest number of active synapses of all best matching segments.
If none were found, pick the least used cell (see `TM.leastUsedCell`).
 Parameters

cells  (set) Indices of cells 
activeCells  (set) Indices of active cells 
connections  (Connections) Connectivity of layer 
 Returns
 (tuple) Contains:
cell
(int), bestSegment
(int)
def bestMatchingSegment 
( 

self, 



cell, 



activeCells, 



connections 

) 
 
Gets the segment on a cell with the largest number of activate synapses, including all synapses with nonzero permanences.
 Parameters

cell  (int) Cell index 
activeCells  (set) Indices of active cells 
connections  (Connections) Connectivity of layer 
 Returns
 (tuple) Contains:
segment
(int), connectedActiveSynapses
(set)
def burstColumns 
( 

self, 



activeColumns, 



predictedColumns, 



prevActiveCells, 



prevWinnerCells, 



connections 

) 
 
Phase 2: Burst unpredicted columns.
Pseudocode:
 for each unpredicted active column
 mark all cells as active
 mark the best matching cell as winner cell
 (learning)
 if it has no matching segment
 (optimization) if there are prev winner cells
 add a segment to it
 mark the segment as learning
 Parameters

activeColumns  (set) Indices of active columns in t 
predictedColumns  (set) Indices of predicted columns in t 
prevActiveCells  (set) Indices of active cells in t1 
prevWinnerCells  (set) Indices of winner cells in t1 
connections  (Connections) Connectivity of layer 
 Returns
 (tuple) Contains:
activeCells
(set), winnerCells
(set), learningSegments
(set)
def cellsForColumn 
( 

self, 



column 

) 
 
Returns the indices of cells that belong to a column.
 Parameters

 Returns
 (set) Cell indices
def columnForCell 
( 

self, 



cell 

) 
 
Returns the index of the column that a cell belongs to.
 Parameters

 Returns
 (int) Column index
def compute 
( 

self, 



activeColumns, 



learn = True 

) 
 
Feeds input record through TM, performing inference and learning.
Updates member variables with new state.
 Parameters

activeColumns  (set) Indices of active columns in t 
def computeFn 
( 

self, 



activeColumns, 



prevPredictiveCells, 



prevActiveSegments, 



prevActiveCells, 



prevWinnerCells, 



prevMatchingSegments, 



prevMatchingCells, 



connections, 



learn = True 

) 
 
'Functional' version of compute.
Returns new state.
 Parameters

activeColumns  (set) Indices of active columns in t 
prevPredictiveCells  (set) Indices of predictive cells in t1 
prevActiveSegments  (set) Indices of active segments in t1 
prevActiveCells  (set) Indices of active cells in t1 
prevWinnerCells  (set) Indices of winner cells in t1 
prevMatchingSegments  (set) Indices of matching segments in t1 
prevMatchingCells  (set) Indices of matching cells in t1 
connections  (Connections) Connectivity of layer 
learn  (bool) Whether or not learning is enabled 
 Returns
 (tuple) Contains:
activeCells
(set), winnerCells
(set), activeSegments
(set), predictiveCells
(set), 'matchingSegments'(set), 'matchingCells' (set)
def computePredictiveCells 
( 

self, 



activeCells, 



connections 

) 
 
Phase 4: Compute predictive cells due to lateral input on distal dendrites.
Pseudocode:
 for each distal dendrite segment with activity >= activationThreshold
 mark the segment as active
 mark the cell as predictive
 if predictedSegmentDecrement > 0
 for each distal dendrite segment with unconnected
activity >= minThreshold
 mark the segment as matching
 mark the cell as matching
Forward propagates activity from active cells to the synapses that touch
them, to determine which synapses are active.
 Parameters

activeCells  (set) Indices of active cells in t 
connections  (Connections) Connectivity of layer 
 Returns
 (tuple) Contains:
activeSegments
(set), predictiveCells
(set), matchingSegments
(set), matchingCells
(set)
def learnOnSegments 
( 

self, 



prevActiveSegments, 



learningSegments, 



prevActiveCells, 



winnerCells, 



prevWinnerCells, 



connections, 



predictedInactiveCells, 



prevMatchingSegments 

) 
 
Phase 3: Perform learning by adapting segments.
Pseudocode:
 (learning) for each prev active or learning segment
 if learning segment or from winner cell
 strengthen active synapses
 weaken inactive synapses
 if learning segment
 add some synapses to the segment
 subsample from prev winner cells
 if predictedSegmentDecrement > 0
 for each previously matching segment
 if cell is a predicted inactive cell
 weaken active synapses but don't touch inactive synapses
 Parameters

prevActiveSegments  (set) Indices of active segments in t1 
learningSegments  (set) Indices of learning segments in t 
prevActiveCells  (set) Indices of active cells in t1 
winnerCells  (set) Indices of winner cells in t 
prevWinnerCells  (set) Indices of winner cells in t1 
connections  (Connections) Connectivity of layer 
predictedInactiveCells  (set) Indices of predicted inactive cells 
prevMatchingSegments  (set) Indices of segments with 
def leastUsedCell 
( 

self, 



cells, 



connections 

) 
 
Gets the cell with the smallest number of segments.
Break ties randomly.
 Parameters

cells  (set) Indices of cells 
connections  (Connections) Connectivity of layer 
 Returns
 (int) Cell index
def mapCellsToColumns 
( 

self, 



cells 

) 
 
Maps cells to the columns they belong to.
 Parameters

 Returns
 (dict) Mapping from columns to their cells in
cells
def numberOfCells 
( 

self  ) 

Returns the number of cells in this layer.
 Returns
 (int) Number of cells
def numberOfColumns 
( 

self  ) 

Returns the number of columns in this layer.
 Returns
 (int) Number of columns
def pickCellsToLearnOn 
( 

self, 



n, 



segment, 



winnerCells, 



connections 

) 
 
Pick cells to form distal connections to.
TODO: Respect topology and learningRadius
 Parameters

n  (int) Number of cells to pick 
segment  (int) Segment index 
winnerCells  (set) Indices of winner cells in t 
connections  (Connections) Connectivity of layer 
 Returns
 (set) Indices of cells picked
Reads deserialized data from proto object.
 Parameters

proto  (DynamicStructBuilder) Proto object 
 Returns
 (TemporalMemory) TemporalMemory instance
Indicates the start of a new sequence.
Resets sequence state of the TM.
def write 
( 

self, 



proto 

) 
 
Writes serialized data to proto object.
 Parameters

proto  (DynamicStructBuilder) Proto object 
The documentation for this class was generated from the following file:
 nupic/research/temporal_memory.py