Temporal Memory

Temporal Memory implementation in Python.

class nupic.research.temporal_memory.TemporalMemory(columnDimensions=(2048, ), cellsPerColumn=32, activationThreshold=13, initialPermanence=0.21, connectedPermanence=0.5, minThreshold=10, maxNewSynapseCount=20, permanenceIncrement=0.1, permanenceDecrement=0.1, predictedSegmentDecrement=0.0, maxSegmentsPerCell=255, maxSynapsesPerSegment=255, seed=42, **kwargs)

Class implementing the Temporal Memory algorithm.

activateCells(activeColumns, learn=True)

Calculate the active cells, using the current active columns and dendrite segments. Grow and reinforce synapses.

@param activeColumns (iter) A sorted list of active column indices.

@param learn (bool) If true, reinforce / punish / grow synapses.

Pseudocode: for each column

if column is active and has active distal dendrite segments
call activatePredictedColumn
if column is active and doesn’t have active distal dendrite segments
call burstColumn
if column is inactive and has matching distal dendrite segments
call punishPredictedColumn
activateDendrites(learn=True)

Calculate dendrite segment activity, using the current active cells.

@param learn (bool) If true, segment activations will be recorded. This information is used during segment cleanup.

Pseudocode: for each distal dendrite segment with activity >= activationThreshold

mark the segment as active
for each distal dendrite segment with unconnected activity >= minThreshold
mark the segment as matching
activatePredictedColumn(column, columnActiveSegments, columnMatchingSegments, prevActiveCells, prevWinnerCells, learn)

Determines which cells in a predicted column should be added to winner cells list, and learns on the segments that correctly predicted this column.

@param column (int) Index of bursting column.

@param columnActiveSegments (iter) Active segments in this column.

@param columnMatchingSegments (iter) Matching segments in this column.

@param prevActiveCells (list) Active cells in t-1.

@param prevWinnerCells (list) Winner cells in t-1.

@param learn (bool) If true, grow and reinforce synapses.

@return cellsToAdd (list) A list of predicted cells that will be added to active cells and winner cells.

burstColumn(column, columnMatchingSegments, prevActiveCells, prevWinnerCells, learn)

Activates all of the cells in an unpredicted active column, chooses a winner cell, and, if learning is turned on, learns on one segment, growing a new segment if necessary.

@param column (int) Index of bursting column.

@param columnMatchingSegments (iter) Matching segments in this column, or None if there aren’t any.

@param prevActiveCells (list) Active cells in t-1.

@param prevWinnerCells (list) Winner cells in t-1.

@param learn (bool) Whether or not learning is enabled.

@return (tuple) Contains:
cells (iter), winnerCell (int),
cellsForColumn(column)

Returns the indices of cells that belong to a column.

@param column (int) Column index

@return (list) Cell indices

columnForCell(cell)

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

@param cell (int) Cell index

@return (int) Column index

compute(activeColumns, learn=True)

Perform one time step of the Temporal Memory algorithm.

This method calls activateCells, then calls activateDendrites. Using the TemporalMemory via its compute method ensures that you’ll always be able to call getPredictiveCells to get predictions for the next time step.

@param activeColumns (iter) Indices of active columns

@param learn (bool) Whether or not learning is enabled

static connectionsFactory(*args, **kwargs)

Create a Connections instance. TemporalMemory subclasses may override this method to choose a different Connections implementation, or to augment the instance otherwise returned by the default Connections implementation.

See Connections for constructor signature and usage.

@return: Connections instance

getActivationThreshold()

Returns the activation threshold. @return (int) The activation threshold.

getActiveCells()

Returns the indices of the active cells.

@return (list) Indices of active cells.

getActiveSegments()

Returns the active segments.

@return (list) Active segments

static getCellIndex(cell)

Returns the index of the cell.

@param cell (int) cell to find the index of

classmethod getCellIndices(cells)

Returns the indices of the cells passed in.

@param cells (list) cells to find the indices of

getCellsPerColumn()

Returns the number of cells per column.

@return (int) The number of cells per column.

getColumnDimensions()

Returns the dimensions of the columns in the region. @return (tuple) Column dimensions

getConnectedPermanence()

Get the connected permanence. @return (float) The connected permanence.

getInitialPermanence()

Get the initial permanence. @return (float) The initial permanence.

getMatchingSegments()

Returns the matching segments.

@return (list) Matching segments

getMaxNewSynapseCount()

Returns the max new synapse count. @return (int) The max new synapse count.

getMaxSegmentsPerCell()

Get the maximum number of segments per cell @return (int) max number of segments per cell

getMaxSynapsesPerSegment()

Get the maximum number of synapses per segment. @return (int) max number of synapses per segment

getMinThreshold()

Returns the min threshold. @return (int) The min threshold.

getPermanenceDecrement()

Get the permanence decrement. @return (float) The permanence decrement.

getPermanenceIncrement()

Get the permanence increment. @return (float) The permanence increment.

getPredictedSegmentDecrement()

Get the predicted segment decrement. @return (float) The predicted segment decrement.

getPredictiveCells()

Returns the indices of the predictive cells.

@return (list) Indices of predictive cells.

getWinnerCells()

Returns the indices of the winner cells.

@return (list) Indices of winner cells.

mapCellsToColumns(cells)

Maps cells to the columns they belong to.

@param cells (set) Cells

@return (dict) Mapping from columns to their cells in cells

numberOfCells()

Returns the number of cells in this layer.

@return (int) Number of cells

numberOfColumns()

Returns the number of columns in this layer.

@return (int) Number of columns

punishPredictedColumn(column, columnActiveSegments, columnMatchingSegments, prevActiveCells, prevWinnerCells)

Punishes the Segments that incorrectly predicted a column to be active.

@param column (int) Index of bursting column.

@param columnActiveSegments (iter) Active segments for this column, or None if there aren’t any.

@param columnMatchingSegments (iter) Matching segments for this column, or None if there aren’t any.

@param prevActiveCells (list) Active cells in t-1.

@param prevWinnerCells (list) Winner cells in t-1.

classmethod read(proto)

Reads deserialized data from proto object.

@param proto (DynamicStructBuilder) Proto object

@return (TemporalMemory) TemporalMemory instance

reset()

Indicates the start of a new sequence. Clears any predictions and makes sure synapses don’t grow to the currently active cells in the next time step.

setActivationThreshold(activationThreshold)

Sets the activation threshold. @param activationThreshold (int) activation threshold.

setConnectedPermanence(connectedPermanence)

Sets the connected permanence. @param connectedPermanence (float) The connected permanence.

setInitialPermanence(initialPermanence)

Sets the initial permanence. @param initialPermanence (float) The initial permanence.

setMaxNewSynapseCount(maxNewSynapseCount)

Sets the max new synapse count. @param maxNewSynapseCount (int) Max new synapse count.

setMinThreshold(minThreshold)

Sets the min threshold. @param minThreshold (int) min threshold.

setPermanenceDecrement(permanenceDecrement)

Sets the permanence decrement. @param permanenceDecrement (float) The permanence decrement.

setPermanenceIncrement(permanenceIncrement)

Sets the permanence increment. @param permanenceIncrement (float) The permanence increment.

setPredictedSegmentDecrement(predictedSegmentDecrement)

Sets the predicted segment decrement. @param predictedSegmentDecrement (float) The predicted segment decrement.

write(proto)

Writes serialized data to proto object.

@param proto (DynamicStructBuilder) Proto object