NuPIC Core
Core algorithms for NuPIC(the Numenta Platform for Intelligent Computing), implemented in C++
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | List of all members
nupic::algorithms::temporal_memory::TemporalMemory Class Reference

CLA temporal memory implementation in C++. More...

#include <TemporalMemory.hpp>

Public Member Functions

 TemporalMemory (vector< UInt > columnDimensions, UInt cellsPerColumn=32, UInt activationThreshold=13, Permanence initialPermanence=0.21, Permanence connectedPermanence=0.50, UInt minThreshold=10, UInt maxNewSynapseCount=20, Permanence permanenceIncrement=0.10, Permanence permanenceDecrement=0.10, Int seed=1)
 Initialize the temporal memory (TM) using the given parameters. More...
 
virtual UInt version () const
 Get the version number of for the TM implementation. More...
 
void seed_ (UInt64 seed)
 This only updates _rng to a new Random using seed. More...
 
virtual void reset ()
 Indicates the start of a new sequence. More...
 
virtual void compute (UInt activeColumnsSize, UInt activeColumns[], bool learn=true)
 Feeds input record through TM, performing inference and learning. More...
 
tuple< set< Cell >, set< Cell >
, vector< Segment >, set< Cell >
, set< UInt > > 
computeFn (UInt activeColumnsSize, UInt activeColumns[], set< Cell > &prevPredictiveCells, vector< Segment > &prevActiveSegments, set< Cell > &prevActiveCells, set< Cell > &prevWinnerCells, Connections &connections, bool learn=true)
 'Functional' version of compute. More...
 
virtual tuple< set< Cell >
, set< Cell >, set< UInt > > 
activateCorrectlyPredictiveCells (set< Cell > &prevPredictiveCells, set< UInt > &activeColumns)
 Phase 1 : Activate the correctly predictive cells. More...
 
virtual tuple< set< Cell >
, set< Cell >, vector< Segment > > 
burstColumns (set< UInt > &activeColumns, set< UInt > &predictedColumns, set< Cell > &prevActiveCells, set< Cell > &prevWinnerCells, Connections &connections)
 Phase 2 : Burst unpredicted columns. More...
 
virtual void learnOnSegments (vector< Segment > &prevActiveSegments, vector< Segment > &learningSegments, set< Cell > &prevActiveCells, set< Cell > &winnerCells, set< Cell > &prevWinnerCells, Connections &connections)
 Phase 3 : Perform learning by adapting segments. More...
 
virtual tuple< vector< Segment >
, set< Cell > > 
computePredictiveCells (set< Cell > &activeCells, Connections &connections)
 Phase 4 : Compute predictive cells due to lateral input on distal dendrites. More...
 
tuple< bool, Cell, bool, SegmentbestMatchingCell (vector< Cell > &cells, set< Cell > &activeCells, Connections &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. More...
 
tuple< bool, Segment, IntbestMatchingSegment (Cell &cell, set< Cell > &activeCells, Connections &connections)
 Gets the segment on a cell with the largest number of activate synapses, including all synapses with non - zero permanences. More...
 
Cell leastUsedCell (vector< Cell > &cells, Connections &connections)
 Gets the cell with the smallest number of segments. More...
 
vector< SynapseactiveSynapsesForSegment (Segment &segment, set< Cell > &activeCells, Connections &connections)
 Returns the synapses on a segment that are active due to lateral input from active cells. More...
 
void adaptSegment (Segment &segment, vector< Synapse > &activeSynapses, Connections &connections)
 Updates synapses on segment. More...
 
set< CellpickCellsToLearnOn (Int n, Segment &segment, set< Cell > &winnerCells, Connections &connections)
 Pick cells to form distal connections to. More...
 
Int columnForCell (Cell &cell)
 Returns the index of the column that a cell belongs to. More...
 
vector< CellcellsForColumn (Int column)
 Returns the indices of cells that belong to a column. More...
 
UInt numberOfCells (void)
 Returns the number of cells in this layer. More...
 
map< Int, set< Cell > > mapCellsToColumns (set< Cell > &cells)
 Maps cells to the columns they belong to. More...
 
vector< UIntgetColumnDimensions () const
 Returns the dimensions of the columns in the region. More...
 
UInt numberOfColumns () const
 Returns the total number of columns. More...
 
UInt getCellsPerColumn () const
 Returns the number of cells per column. More...
 
UInt getActivationThreshold () const
 Returns the activation threshold. More...
 
Permanence getInitialPermanence () const
 Returns the initial permanence. More...
 
Permanence getConnectedPermanence () const
 Returns the connected permanance. More...
 
UInt getMinThreshold () const
 Returns the minimum threshold. More...
 
UInt getMaxNewSynapseCount () const
 Returns the maximum new synapse count. More...
 
Permanence getPermanenceIncrement () const
 Returns the permanence increment. More...
 
Permanence getPermanenceDecrement () const
 Returns the permanence decrement. More...
 
bool _validateColumn (UInt column)
 Raises an error if column index is invalid. More...
 
bool _validateCell (Cell &cell)
 Raises an error if cell index is invalid. More...
 
bool _validateSegment (Segment &segment)
 Raises an error if segment is invalid. More...
 
bool _validatePermanence (Real permanence)
 Raises an error if segment is invalid. More...
 
virtual void save (ostream &outStream) const
 Save (serialize) the current state of the spatial pooler to the specified file. More...
 
virtual void load (istream &inStream)
 Load (deserialize) and initialize the spatial pooler from the specified input stream. More...
 
virtual UInt persistentSize () const
 Returns the number of bytes that a save operation would result in. More...
 
void printParameters ()
 Print the main TM creation parameters.
 
void printState (vector< UInt > &state)
 Print the given UInt array in a nice format.
 
void printState (vector< Real > &state)
 Print the given Real array in a nice format.
 

Detailed Description

CLA temporal memory implementation in C++.

The primary public interfaces to this function are the "initialize" and "compute" methods.

Example usage:

SpatialPooler sp;
sp.initialize(inputDimensions, columnDimensions, <parameters>);

TemporalMemory tm;
tm.initialize(columnDimensions, <parameters>);

while (true) {
   <get input vector, streaming spatiotemporal information>
   sp.compute(inputVector, learn, activeColumns)
   tm.compute(number of activeColumns, activeColumns, learn)
   <do something with output, e.g. add classifiers>

Definition at line 67 of file TemporalMemory.hpp.

Constructor & Destructor Documentation

nupic::algorithms::temporal_memory::TemporalMemory::TemporalMemory ( vector< UInt columnDimensions,
UInt  cellsPerColumn = 32,
UInt  activationThreshold = 13,
Permanence  initialPermanence = 0.21,
Permanence  connectedPermanence = 0.50,
UInt  minThreshold = 10,
UInt  maxNewSynapseCount = 20,
Permanence  permanenceIncrement = 0.10,
Permanence  permanenceDecrement = 0.10,
Int  seed = 1 
)

Initialize the temporal memory (TM) using the given parameters.

Parameters
columnDimensionsDimensions of the column space
cellsPerColumnNumber of cells per column
activationThresholdIf the number of active connected synapses on a segment is at least this threshold, the segment is said to be active.
initialPermanenceInitial permanence of a new synapse.
connectedPermanenceIf the permanence value for a synapse is greater than this value, it is said to be connected.
minThresholdIf 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.
maxNewSynapseCountThe maximum number of synapses added to a segment during learning.
permanenceIncrementAmount by which permanences of synapses are incremented during learning.
permanenceDecrementAmount by which permanences of synapses are decremented during learning.
seedSeed for the random number generator.

Member Function Documentation

bool nupic::algorithms::temporal_memory::TemporalMemory::_validateCell ( Cell cell)

Raises an error if cell index is invalid.

Parameters
cellCell index
bool nupic::algorithms::temporal_memory::TemporalMemory::_validateColumn ( UInt  column)

Raises an error if column index is invalid.

Parameters
columnColumn index
bool nupic::algorithms::temporal_memory::TemporalMemory::_validatePermanence ( Real  permanence)

Raises an error if segment is invalid.

Parameters
permanence(float) Permanence
bool nupic::algorithms::temporal_memory::TemporalMemory::_validateSegment ( Segment segment)

Raises an error if segment is invalid.

Parameters
segmentsegment index
virtual tuple<set<Cell>, set<Cell>, set<UInt> > nupic::algorithms::temporal_memory::TemporalMemory::activateCorrectlyPredictiveCells ( set< Cell > &  prevPredictiveCells,
set< UInt > &  activeColumns 
)
virtual

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
Parameters
prevPredictiveCellsIndices of predictive cells in t-1
activeColumnsIndices of active columns in t
Returns
(tuple)Contains: activeCells (set), winnerCells (set), predictedColumns (set)
vector<Synapse> nupic::algorithms::temporal_memory::TemporalMemory::activeSynapsesForSegment ( Segment segment,
set< Cell > &  activeCells,
Connections connections 
)

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

Parameters
segmentSegment index
activeCellsIndices of active cells
connectionsConnectivity of layer
Returns
(set) Indices of active synapses on segment
void nupic::algorithms::temporal_memory::TemporalMemory::adaptSegment ( Segment segment,
vector< Synapse > &  activeSynapses,
Connections connections 
)

Updates synapses on segment.

Strengthens active synapses; weakens inactive synapses.

Parameters
segmentSegment index
activeSynapsesIndices of active synapses
connectionsConnectivity of layer
tuple<bool, Cell, bool, Segment> nupic::algorithms::temporal_memory::TemporalMemory::bestMatchingCell ( vector< Cell > &  cells,
set< Cell > &  activeCells,
Connections 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
cellsIndices of cells
activeCellsIndices of active cells
connectionsConnectivity of layer
Returns
(tuple)Contains: foundCell (bool), bestCell (int), foundSegment (bool), bestSegment (int)
tuple<bool, Segment, Int> nupic::algorithms::temporal_memory::TemporalMemory::bestMatchingSegment ( Cell cell,
set< Cell > &  activeCells,
Connections connections 
)

Gets the segment on a cell with the largest number of activate synapses, including all synapses with non - zero permanences.

Parameters
cellCell index
activeCellsIndices of active cells
connectionsConnectivity of layer
Returns
(tuple)Contains: segment (int), connectedActiveSynapses (set)
virtual tuple<set<Cell>, set<Cell>, vector<Segment> > nupic::algorithms::temporal_memory::TemporalMemory::burstColumns ( set< UInt > &  activeColumns,
set< UInt > &  predictedColumns,
set< Cell > &  prevActiveCells,
set< Cell > &  prevWinnerCells,
Connections connections 
)
virtual

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 t-1
prevWinnerCells(set)Indices of winner cells in t-1
connections(Connections)Connectivity of layer
Returns
(tuple)Contains: activeCells (set), winnerCells (set), learningSegments (set)
vector<Cell> nupic::algorithms::temporal_memory::TemporalMemory::cellsForColumn ( Int  column)

Returns the indices of cells that belong to a column.

Parameters
columnColumn index
Returns
(set) Cell indices
Int nupic::algorithms::temporal_memory::TemporalMemory::columnForCell ( Cell cell)

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

Parameters
cellCell index
Returns
(int) Column index
virtual void nupic::algorithms::temporal_memory::TemporalMemory::compute ( UInt  activeColumnsSize,
UInt  activeColumns[],
bool  learn = true 
)
virtual

Feeds input record through TM, performing inference and learning.

Updates member variables with new state.

Parameters
activeColumnsSizeNumber of active columns
activeColumnsIndices of active columns in t
learnWhether or not learning is enabled
tuple<set<Cell>, set<Cell>, vector<Segment>, set<Cell>, set<UInt> > nupic::algorithms::temporal_memory::TemporalMemory::computeFn ( UInt  activeColumnsSize,
UInt  activeColumns[],
set< Cell > &  prevPredictiveCells,
vector< Segment > &  prevActiveSegments,
set< Cell > &  prevActiveCells,
set< Cell > &  prevWinnerCells,
Connections connections,
bool  learn = true 
)

'Functional' version of compute.

Returns new state.

Parameters
activeColumnsIndices of active columns in t
prevPredictiveCellsIndices of predictive cells in t-1
prevActiveSegmentsIndices of active segments in t-1
prevActiveCellsIndices of active cells in t-1
prevWinnerCellsIndices of winner cells in t-1
connectionsConnectivity of layer
learnWhether or not learning is enabled
Returns
(tuple)Contains: activeCells (set), winnerCells (set), activeSegments (set), predictiveCells (set), 'predictedColumns' (set)
virtual tuple<vector<Segment>, set<Cell> > nupic::algorithms::temporal_memory::TemporalMemory::computePredictiveCells ( set< Cell > &  activeCells,
Connections connections 
)
virtual

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

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)
UInt nupic::algorithms::temporal_memory::TemporalMemory::getActivationThreshold ( ) const

Returns the activation threshold.

Returns
Integer number of the activation threshold
UInt nupic::algorithms::temporal_memory::TemporalMemory::getCellsPerColumn ( ) const

Returns the number of cells per column.

Returns
Integer number of cells per column
vector<UInt> nupic::algorithms::temporal_memory::TemporalMemory::getColumnDimensions ( ) const

Returns the dimensions of the columns in the region.

Returns
Integer number of column dimension
Permanence nupic::algorithms::temporal_memory::TemporalMemory::getConnectedPermanence ( ) const

Returns the connected permanance.

Returns
Returns the connected permanance
Permanence nupic::algorithms::temporal_memory::TemporalMemory::getInitialPermanence ( ) const

Returns the initial permanence.

Returns
Initial permanence
UInt nupic::algorithms::temporal_memory::TemporalMemory::getMaxNewSynapseCount ( ) const

Returns the maximum new synapse count.

Returns
Integer number of maximum new synapse count
UInt nupic::algorithms::temporal_memory::TemporalMemory::getMinThreshold ( ) const

Returns the minimum threshold.

Returns
Integer number of minimum threshold
Permanence nupic::algorithms::temporal_memory::TemporalMemory::getPermanenceDecrement ( ) const

Returns the permanence decrement.

Returns
Returns the Permanence decrement
Permanence nupic::algorithms::temporal_memory::TemporalMemory::getPermanenceIncrement ( ) const

Returns the permanence increment.

Returns
Returns the Permanence increment
virtual void nupic::algorithms::temporal_memory::TemporalMemory::learnOnSegments ( vector< Segment > &  prevActiveSegments,
vector< Segment > &  learningSegments,
set< Cell > &  prevActiveCells,
set< Cell > &  winnerCells,
set< Cell > &  prevWinnerCells,
Connections connections 
)
virtual

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
Parameters
prevActiveSegments(set)Indices of active segments in t-1
learningSegments(set)Indices of learning segments in t
prevActiveCells(set)Indices of active cells in t-1
winnerCells(set)Indices of winner cells in t
prevWinnerCells(set)Indices of winner cells in t-1
connections(Connections)Connectivity of layer
Cell nupic::algorithms::temporal_memory::TemporalMemory::leastUsedCell ( vector< Cell > &  cells,
Connections connections 
)

Gets the cell with the smallest number of segments.

Break ties randomly.

Parameters
cellsIndices of cells
connectionsConnectivity of layer
Returns
(int) Cell index
virtual void nupic::algorithms::temporal_memory::TemporalMemory::load ( istream &  inStream)
virtual

Load (deserialize) and initialize the spatial pooler from the specified input stream.

Parameters
inStreamA valid istream.
map<Int, set<Cell> > nupic::algorithms::temporal_memory::TemporalMemory::mapCellsToColumns ( set< Cell > &  cells)

Maps cells to the columns they belong to.

Parameters
cellsCells
Returns
(dict) Mapping from columns to their cells in cells
UInt nupic::algorithms::temporal_memory::TemporalMemory::numberOfCells ( void  )

Returns the number of cells in this layer.

Returns
(int) Number of cells
UInt nupic::algorithms::temporal_memory::TemporalMemory::numberOfColumns ( ) const

Returns the total number of columns.

Returns
Integer number of column numbers
virtual UInt nupic::algorithms::temporal_memory::TemporalMemory::persistentSize ( ) const
virtual

Returns the number of bytes that a save operation would result in.

Note: this method is currently somewhat inefficient as it just does a full save into an ostream and counts the resulting size.

Returns
Integer number of bytes
set<Cell> nupic::algorithms::temporal_memory::TemporalMemory::pickCellsToLearnOn ( Int  n,
Segment segment,
set< Cell > &  winnerCells,
Connections connections 
)

Pick cells to form distal connections to.

TODO : Respect topology and learningRadius

Parameters
nNumber of cells to pick
segmentSegment index
winnerCellsIndices of winner cells in t
connectionsConnectivity of layer
Returns
(set) Indices of cells picked
virtual void nupic::algorithms::temporal_memory::TemporalMemory::reset ( )
virtual

Indicates the start of a new sequence.

Resets sequence state of the TM.

virtual void nupic::algorithms::temporal_memory::TemporalMemory::save ( ostream &  outStream) const
virtual

Save (serialize) the current state of the spatial pooler to the specified file.

Parameters
fdA valid file descriptor.
void nupic::algorithms::temporal_memory::TemporalMemory::seed_ ( UInt64  seed)

This only updates _rng to a new Random using seed.

Returns
Integer version number.
virtual UInt nupic::algorithms::temporal_memory::TemporalMemory::version ( ) const
inlinevirtual

Get the version number of for the TM implementation.

Returns
Integer version number.

Definition at line 120 of file TemporalMemory.hpp.


The documentation for this class was generated from the following file: