NuPIC Core
Core algorithms for NuPIC(the Numenta Platform for Intelligent Computing), implemented in C++

CLA spatial pooler implementation in C++. More...
#include <SpatialPooler.hpp>
Public Member Functions  
virtual void  initialize (vector< UInt > inputDimensions, vector< UInt > columnDimensions, UInt potentialRadius=16, Real potentialPct=0.5, bool globalInhibition=true, Real localAreaDensity=1.0, UInt numActiveColumnsPerInhArea=10, UInt stimulusThreshold=0, Real synPermInactiveDec=0.01, Real synPermActiveInc=0.1, Real synPermConnected=0.1, Real minPctOverlapDutyCycles=0.001, Real minPctActiveDutyCycles=0.001, UInt dutyCyclePeriod=1000, Real maxBoost=10.0, Int seed=1, UInt spVerbosity=0, bool wrapAround=true) 
Initialize the spatial pooler using the given parameters. More...  
virtual void  compute (UInt inputVector[], bool learn, UInt activeVector[], bool stripNeverLearned) 
This is the main workshorse method of the SpatialPooler class. More...  
virtual void  compute (UInt inputVector[], bool learn, UInt activeVector[]) 
Same as above but with stripUnlearnedColumns set to true.  
void  stripUnlearnedColumns (UInt activeArray[]) 
Removes the set of columns who have never been active from the set of active columns selected in the inhibition round. More...  
virtual UInt  version () const 
Get the version number of this spatial pooler. More...  
virtual void  save (ostream &outStream) 
Save (serialize) the current state of the spatial pooler to the specified output stream. More...  
virtual void  load (istream &inStream) 
Load (deserialize) and initialize the spatial pooler from the specified input stream. More...  
virtual UInt  persistentSize () 
Returns the number of bytes that a save operation would result in. More...  
vector< UInt >  getColumnDimensions () 
Returns the dimensions of the columns in the region. More...  
vector< UInt >  getInputDimensions () 
Returns the dimensions of the input vector. More...  
UInt  getNumColumns () 
Returns the total number of columns. More...  
UInt  getNumInputs () 
Returns the total number of inputs. More...  
UInt  getPotentialRadius () 
Returns the potential radius. More...  
void  setPotentialRadius (UInt potentialRadius) 
Sets the potential radius. More...  
Real  getPotentialPct () 
Returns the potential percent. More...  
void  setPotentialPct (Real potentialPct) 
Sets the potential percent. More...  
bool  getGlobalInhibition () 
void  setGlobalInhibition (bool globalInhibition) 
Sets global inhibition. More...  
Int  getNumActiveColumnsPerInhArea () 
Returns the number of active columns per inhibition area. More...  
void  setNumActiveColumnsPerInhArea (UInt numActiveColumnsPerInhArea) 
Sets the number of active columns per inhibition area. More...  
Real  getLocalAreaDensity () 
Returns the local area density. More...  
void  setLocalAreaDensity (Real localAreaDensity) 
Sets the local area density. More...  
UInt  getStimulusThreshold () 
Returns the stimulus threshold. More...  
void  setStimulusThreshold (UInt stimulusThreshold) 
Sets the stimulus threshold. More...  
UInt  getInhibitionRadius () 
Returns the inhibition radius. More...  
void  setInhibitionRadius (UInt inhibitionRadius) 
Sets the inhibition radius. More...  
UInt  getDutyCyclePeriod () 
Returns the duty cycle period. More...  
void  setDutyCyclePeriod (UInt dutyCyclePeriod) 
Sets the duty cycle period. More...  
Real  getMaxBoost () 
Returns the maximum boost value. More...  
void  setMaxBoost (Real maxBoost) 
Sets the maximum boost value. More...  
UInt  getIterationNum () 
Returns the iteration number. More...  
void  setIterationNum (UInt iterationNum) 
Sets the iteration number. More...  
UInt  getIterationLearnNum () 
Returns the learning iteration number. More...  
void  setIterationLearnNum (UInt iterationLearnNum) 
Sets the learning iteration number. More...  
UInt  getSpVerbosity () 
Returns the verbosity level. More...  
void  setSpVerbosity (UInt spVerbosity) 
Sets the verbosity level. More...  
bool  getWrapAround () 
Returns boolean value of wrapAround which indicates if receptive fields should wrap around from the beginning the input dimensions to the end. More...  
void  setWrapAround (bool wrapAround) 
Sets wrapAround. More...  
UInt  getUpdatePeriod () 
Returns the update period. More...  
void  setUpdatePeriod (UInt updatePeriod) 
Sets the update period. More...  
Real  getSynPermTrimThreshold () 
Returns the permanence trim threshold. More...  
void  setSynPermTrimThreshold (Real synPermTrimThreshold) 
Sets the permanence trim threshold. More...  
Real  getSynPermActiveInc () 
Returns the permanence increment amount for active synapses inputs. More...  
void  setSynPermActiveInc (Real synPermActiveInc) 
Sets the permanence increment amount for active synapses inputs. More...  
Real  getSynPermInactiveDec () 
Returns the permanence decrement amount for inactive synapses. More...  
void  setSynPermInactiveDec (Real synPermInactiveDec) 
Returns the permanence decrement amount for inactive synapses. More...  
Real  getSynPermBelowStimulusInc () 
Returns the permanence increment amount for columns that have not been recently active. More...  
void  setSynPermBelowStimulusInc (Real synPermBelowStimulusInc) 
Sets the permanence increment amount for columns that have not been recently active. More...  
Real  getSynPermConnected () 
Returns the permanence amount that qualifies a synapse as being connected. More...  
void  setSynPermConnected (Real setSynPermConnected) 
Sets the permanence amount that qualifies a synapse as being connected. More...  
Real  getMinPctOverlapDutyCycles () 
Returns the minimum tolerated overlaps, given as percent of neighbors overlap score. More...  
void  setMinPctOverlapDutyCycles (Real minPctOverlapDutyCycles) 
Sets the minimum tolerated overlaps, given as percent of neighbors overlap score. More...  
Real  getMinPctActiveDutyCycles () 
Returns the minimum tolerated activity duty cycle, given as percent of neighbors' activity duty cycle. More...  
void  setMinPctActiveDutyCycles (Real minPctActiveDutyCycles) 
Sets the minimum tolerated activity duty cycle, given as percent of neighbors' activity duty cycle. More...  
void  getBoostFactors (Real boostFactors[]) 
Returns the boost factors for all columns. More...  
void  setBoostFactors (Real boostFactors[]) 
Sets the boost factors for all columns. More...  
void  getOverlapDutyCycles (Real overlapDutyCycles[]) 
Returns the overlap duty cycles for all columns. More...  
void  setOverlapDutyCycles (Real overlapDutyCycles[]) 
Sets the overlap duty cycles for all columns. More...  
void  getActiveDutyCycles (Real activeDutyCycles[]) 
Returns the activity duty cycles for all columns. More...  
void  setActiveDutyCycles (Real activeDutyCycles[]) 
Sets the activity duty cycles for all columns. More...  
void  getMinOverlapDutyCycles (Real minOverlapDutyCycles[]) 
Returns the minimum overlap duty cycles for all columns. More...  
void  setMinOverlapDutyCycles (Real minOverlapDutyCycles[]) 
Sets the minimum overlap duty cycles for all columns. More...  
void  getMinActiveDutyCycles (Real minActiveDutyCycles[]) 
Returns the minimum activity duty cycles for all columns. More...  
void  setMinActiveDutyCycles (Real minActiveDutyCycles[]) 
Sets the minimum activity duty cycles for all columns. More...  
void  getPotential (UInt column, UInt potential[]) 
Returns the potential mapping for a given column. More...  
void  setPotential (UInt column, UInt potential[]) 
Sets the potential mapping for a given column. More...  
void  getPermanence (UInt column, Real permanence[]) 
Returns the permanence values for a given column. More...  
void  setPermanence (UInt column, Real permanence[]) 
Sets the permanence values for a given column. More...  
void  getConnectedSynapses (UInt column, UInt connectedSynapses[]) 
Returns the connected synapses for a given column. More...  
void  getConnectedCounts (UInt connectedCounts[]) 
Returns the number of connected synapses for all columns. More...  
void  printParameters () 
Print the main SP creation parameters to stdout.  
UInt  mapColumn_ (UInt column) 
Maps a column to its respective input index, keeping to the topology of the region. More...  
vector< UInt >  mapPotential_ (UInt column, bool wrapAround) 
Maps a column to its input bits. More...  
Real  initPermConnected_ () 
Returns a randomly generated permanence value for a synapses that is initialized in a connected state. More...  
Real  initPermNonConnected_ () 
Returns a randomly generated permanence value for a synapses that is to be initialized in a nonconnected state. More...  
vector< Real >  initPermanence_ (vector< UInt > &potential, Real connectedPct) 
Initializes the permanences of a column. More...  
void  updatePermanencesForColumn_ (vector< Real > &perm, UInt column, bool raisePerm=true) 
This method updates the permanence matrix with a column's new permanence values. More...  
void  calculateOverlap_ (UInt inputVector[], vector< UInt > &overlap) 
This function determines each column's overlap with the current input vector. More...  
void  inhibitColumns_ (vector< Real > &overlaps, vector< UInt > &activeColumns) 
Performs inhibition. More...  
void  inhibitColumnsGlobal_ (vector< Real > &overlaps, Real density, vector< UInt > &activeColumns) 
Perform global inhibition. More...  
void  inhibitColumnsLocal_ (vector< Real > &overlaps, Real density, vector< UInt > &activeColumns) 
Performs local inhibition. More...  
void  getNeighbors1D_ (UInt column, vector< UInt > &dimensions, UInt radius, bool wrapAround, vector< UInt > &neighbors) 
Returns a list of indices corresponding to the neighbors of a given column. More...  
void  getNeighbors2D_ (UInt column, vector< UInt > &dimensions, UInt radius, bool wrapAround, vector< UInt > &neighbors) 
Returns a list of indices corresponding to the neighbors of a given column. More...  
void  getNeighborsND_ (UInt column, vector< UInt > &dimensions, UInt radius, bool wrapAround, vector< UInt > &neighbors) 
Similar to _getNeighbors1D and _getNeighbors2D, this function returns a list of indices corresponding to the neighbors of a given column. More...  
void  adaptSynapses_ (UInt inputVector[], vector< UInt > &activeColumns) 
The primary method in charge of learning. More...  
void  bumpUpWeakColumns_ () 
This method increases the permanence values of synapses of columns whose activity level has been too low. More...  
void  updateInhibitionRadius_ () 
Update the inhibition radius. More...  
Real  avgColumnsPerInput_ () 
REturns the average number of columns per input, taking into account the topology of the inputs and columns. More...  
Real  avgConnectedSpanForColumn1D_ (UInt column) 
The range of connected synapses for column. More...  
Real  avgConnectedSpanForColumn2D_ (UInt column) 
The range of connectedSynapses per column, averaged for each dimension. More...  
Real  avgConnectedSpanForColumnND_ (UInt column) 
The range of connectedSynapses per column, averaged for each dimension. More...  
void  updateMinDutyCycles_ () 
Updates the minimum duty cycles defining normal activity for a column. More...  
void  updateMinDutyCyclesGlobal_ () 
Updates the minimum duty cycles in a global fashion. More...  
void  updateMinDutyCyclesLocal_ () 
Updates the minimum duty cycles. More...  
void  updateDutyCycles_ (vector< UInt > &overlaps, UInt activeArray[]) 
Updates the duty cycles for each column. More...  
void  updateBoostFactors_ () 
Update the boost factors for all columns. More...  
void  updateBookeepingVars_ (bool learn) 
Updates counter instance variables each round. More...  
bool  isUpdateRound_ () 
void  seed_ (UInt64 seed) 
Initialize the random seed. More...  
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.  
Static Public Member Functions  
static void  updateDutyCyclesHelper_ (vector< Real > &dutyCycles, vector< UInt > &newValues, UInt period) 
Updates a duty cycle estimate with a new value. More...  
CLA spatial pooler implementation in C++.
The Spatial Pooler is responsible for creating a sparse distributed representation of the input. Given an input it computes a set of sparse active columns and simultaneously updates its permanences, duty cycles, etc.
The primary public interfaces to this function are the "initialize" and "compute" methods.
Example usage:
SpatialPooler sp; sp.initialize(inputDimensions, columnDimensions, <parameters>); while (true) { <get input vector> sp.compute(inputVector, learn, activeColumns) <do something with output> }
Definition at line 67 of file SpatialPooler.hpp.
void nta::algorithms::spatial_pooler::SpatialPooler::adaptSynapses_  (  UInt  inputVector[], 
vector< UInt > &  activeColumns  
) 
The primary method in charge of learning.
Adapts the permanence values of the synapses based on the input vector, and the chosen columns after inhibition round. Permanence values are increased for synapses connected to input bits that are turned on, and decreased for synapses connected to inputs bits that are turned off.
inputVector  an int array of 0's and 1's that comprises the input to the spatial pooler. There exists an entry in the array for every input bit. 
activeColumns  an int vector containing the indices of the columns that survived inhibition. 
Real nta::algorithms::spatial_pooler::SpatialPooler::avgColumnsPerInput_  (  ) 
REturns the average number of columns per input, taking into account the topology of the inputs and columns.
This value is used to calculate the inhibition radius. This function supports an arbitrary number of dimensions. If the number of column dimensions does not match the number of input dimensions, we treat the missing, or phantom dimensions as 'ones'.
The range of connected synapses for column.
This is used to calculate the inhibition radius. This variation of the function only supports a 1 dimensional column toplogy.
column  An int number identifying a column in the permanence, potential and connectivity matrices. 
The range of connectedSynapses per column, averaged for each dimension.
This vaule is used to calculate the inhibition radius. This variation of the function only supports a 2 dimensional column topology.
column  An int number identifying a column in the permanence, potential and connectivity matrices. 
The range of connectedSynapses per column, averaged for each dimension.
This vaule is used to calculate the inhibition radius. This variation of the function supports arbitrary column dimensions.
column  An int number identifying a column in the permanence, potential and connectivity matrices. 
void nta::algorithms::spatial_pooler::SpatialPooler::bumpUpWeakColumns_  (  ) 
This method increases the permanence values of synapses of columns whose activity level has been too low.
Such columns are identified by having an overlap duty cycle that drops too much below those of their peers. The permanence values for such columns are increased.
void nta::algorithms::spatial_pooler::SpatialPooler::calculateOverlap_  (  UInt  inputVector[], 
vector< UInt > &  overlap  
) 
This function determines each column's overlap with the current input vector.
The overlap of a column is the number of synapses for that column that are connected (permance value is greater than '_synPermConnected') to input bits which are turned on. Overlap values that are lower than the 'stimulusThreshold' are ignored. The implementation takes advantage of the SpraseBinaryMatrix class to perform this calculation efficiently.
inputVector  a int array of 0's and 1's that comprises the input to the spatial pooler. 
overlap  an int vector containing the overlap score for each column. The overlap score for a column is defined as the number of synapses in a "connected state" (connected synapses) that are connected to input bits which are turned on. 

virtual 
This is the main workshorse method of the SpatialPooler class.
This method takes an input vector and computes the set of output active columns. If 'learn' is set to True, this method also performs learning.
inputVector  An array of integer 0's and 1's that comprises the input to the spatial pooler. The length of the array must match the total number of input bits implied by the constructor (also returned by the method getNumInputs). In cases where the input is multidimensional, inputVector is a flattened array of inputs. 
learn  A boolean value indicating whether learning should be performed. Learning entails updating the permanence values of the synapses, duty cycles, etc. Learning is typically on but setting learning to 'off' is useful for analyzing the current state of the SP. For example, you might want to feed in various inputs and examine the resulting SDR's. Note that if learning is off, boosting is turned off and columns that have never won will be removed from activeVector. TODO: we may want to keep boosting on even when learning is off. 
activeVector  An array representing the winning columns after inhinition. The size of the array is equal to the number of columns (also returned by the method getNumColumns). This array will be populated with 1's at the indices of the active columns, and 0's everywhere else. In the case where the output is multidimensional, activeVector represents a flattened array of outputs. 
stripNeverLearned  A boolean value indicating when to strip columns from the predictions if they have never learned. The default behavior is to strip unlearned columns but this should be disabled when using a random, unlearned spatial pooler. NOTE: if you rely on this behavior then you should additionally call the stripNeverLearned method directly on the activeVector output as we will be changing the default to false and then removing this parameter entirely in the near future. 
void nta::algorithms::spatial_pooler::SpatialPooler::getActiveDutyCycles  (  Real  activeDutyCycles[]  ) 
Returns the activity duty cycles for all columns.
'activeDutyCycles' size must match the number of columns.
activeDutyCycles  real array to store activity duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::getBoostFactors  (  Real  boostFactors[]  ) 
Returns the boost factors for all columns.
'boostFactors' size must match the number of columns.
boostFactors  real array to store boost factors of all columns. 
vector<UInt> nta::algorithms::spatial_pooler::SpatialPooler::getColumnDimensions  (  ) 
Returns the dimensions of the columns in the region.
void nta::algorithms::spatial_pooler::SpatialPooler::getConnectedCounts  (  UInt  connectedCounts[]  ) 
Returns the number of connected synapses for all columns.
'connectedCounts' size must match the number of columns.
connectedCounts  integer array to store the connected synapses for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::getConnectedSynapses  (  UInt  column, 
UInt  connectedSynapses[]  
) 
Returns the connected synapses for a given column.
'connectedSynapses' size must match the number of inputs.
column  integer of column index. 
connectedSynapses  integer array to store the connected synapses for a given column. 
UInt nta::algorithms::spatial_pooler::SpatialPooler::getDutyCyclePeriod  (  ) 
Returns the duty cycle period.
bool nta::algorithms::spatial_pooler::SpatialPooler::getGlobalInhibition  (  ) 
UInt nta::algorithms::spatial_pooler::SpatialPooler::getInhibitionRadius  (  ) 
Returns the inhibition radius.
vector<UInt> nta::algorithms::spatial_pooler::SpatialPooler::getInputDimensions  (  ) 
Returns the dimensions of the input vector.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getIterationLearnNum  (  ) 
Returns the learning iteration number.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getIterationNum  (  ) 
Returns the iteration number.
Real nta::algorithms::spatial_pooler::SpatialPooler::getLocalAreaDensity  (  ) 
Returns the local area density.
Returns a value less than 0 if parameter is unused".
Real nta::algorithms::spatial_pooler::SpatialPooler::getMaxBoost  (  ) 
Returns the maximum boost value.
void nta::algorithms::spatial_pooler::SpatialPooler::getMinActiveDutyCycles  (  Real  minActiveDutyCycles[]  ) 
Returns the minimum activity duty cycles for all columns.
'_minActiveDutyCycles' size must match the number of columns.
minActiveDutyCycles  real array to store the minimum activity duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::getMinOverlapDutyCycles  (  Real  minOverlapDutyCycles[]  ) 
Returns the minimum overlap duty cycles for all columns.
minOverlapDutyCycles  real arry to store mininum overlap duty cycles for all columns. 'minOverlapDutyCycles' size must match the number of columns. 
Real nta::algorithms::spatial_pooler::SpatialPooler::getMinPctActiveDutyCycles  (  ) 
Returns the minimum tolerated activity duty cycle, given as percent of neighbors' activity duty cycle.
Real nta::algorithms::spatial_pooler::SpatialPooler::getMinPctOverlapDutyCycles  (  ) 
Returns the minimum tolerated overlaps, given as percent of neighbors overlap score.
void nta::algorithms::spatial_pooler::SpatialPooler::getNeighbors1D_  (  UInt  column, 
vector< UInt > &  dimensions,  
UInt  radius,  
bool  wrapAround,  
vector< UInt > &  neighbors  
) 
Returns a list of indices corresponding to the neighbors of a given column.
In this variation of the method, which only supports a one dimensional column toplogy, a column's neighbors are those neighbors who are 'radius' indices away. This information is needed to perform inhibition. This method is a subset of _getNeighborsND and is only included for illustration purposes, and potentially enhanced performance for spatial pooler implementations that only require a onedimensional topology.
column  An integer number. The index identifying a column in the permanence, potential and connectivity matrices. 
dimensions  An int array containg a dimensions for the column space. A 2x3 grid will be represented by [2,3]. 
radius  An integer number Indicates how far away from a given column are other columns to be considered its neighbors. In the previous 2x3 example, each column with coordinates: [2+/radius, 3+/radius] is considered a neighbor. 
wrapAround  A boolean value indicating whether to consider columns at the border of a dimensions to be adjacent to columns at the other end of the dimension. For example, if the columns are layed out in one deimnsion, columns 1 and 10 will be considered adjacent if wrapAround is set to true: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. 
neighbors  An int arrayof indices corresponding to the neighbors of a given column. 
void nta::algorithms::spatial_pooler::SpatialPooler::getNeighbors2D_  (  UInt  column, 
vector< UInt > &  dimensions,  
UInt  radius,  
bool  wrapAround,  
vector< UInt > &  neighbors  
) 
Returns a list of indices corresponding to the neighbors of a given column.
Since the permanence values are stored in such a way that information about toplogy is lost, this method allows for reconstructing the toplogy of the inputs, which are flattened to one array. Given a column's index, its neighbors are defined as those columns that are 'radius' indices away from it in each dimension. The method returns a list of the flat indices of these columns. This method is a subset of _getNeighborsND and is only included for illustration purposes, and potentially enhanced performance for spatial pooler implementations that only require a twodimensional topology.
column  An integer number. The index identifying a column in the permanence, potential and connectivity matrices. 
dimensions  An int array containg a dimensions for the column space. A 2x3 grid will be represented by [2,3]. 
radius  An integer number Indicates how far away from a given column are other columns to be considered its neighbors. In the previous 2x3 example, each column with coordinates: [2+/radius, 3+/radius] is considered a neighbor. 
wrapAround  A boolean value indicating whether to consider columns at the border of a dimensions to be adjacent to columns at the other end of the dimension. For example, if the columns are layed out in one deimnsion, columns 1 and 10 will be considered adjacent if wrapAround is set to true: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. 
neighbors  An int array of indices corresponding to the neighbors of a given column. 
void nta::algorithms::spatial_pooler::SpatialPooler::getNeighborsND_  (  UInt  column, 
vector< UInt > &  dimensions,  
UInt  radius,  
bool  wrapAround,  
vector< UInt > &  neighbors  
) 
Similar to _getNeighbors1D and _getNeighbors2D, this function returns a list of indices corresponding to the neighbors of a given column.
Since the permanence values are stored in such a way that information about toplogy is lost. This method allows for reconstructing the toplogy of the inputs, which are flattened to one array. Given a column's index, its neighbors are defined as those columns that are 'radius' indices away from it in each dimension. The method returns a list of the flat indices of these columns.
column  An integer number. The index identifying a column in the permanence, potential and connectivity matrices. 
dimensions  An int array containg a dimensions for the column space. A 2x3 grid will be represented by [2,3]. 
radius  An integer number Indicates how far away from a given column are other columns to be considered its neighbors. In the previous 2x3 example, each column with coordinates: [2+/radius, 3+/radius] is considered a neighbor. 
wrapAround  A boolean value indicating whether to consider columns at the border of a dimensions to be adjacent to columns at the other end of the dimension. For example, if the columns are layed out in one deimnsion, columns 1 and 10 will be considered adjacent if wrapAround is set to true: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. 
neighbors  An int arrayof indices corresponding to the neighbors of a given column. 
Int nta::algorithms::spatial_pooler::SpatialPooler::getNumActiveColumnsPerInhArea  (  ) 
Returns the number of active columns per inhibition area.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getNumColumns  (  ) 
Returns the total number of columns.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getNumInputs  (  ) 
Returns the total number of inputs.
void nta::algorithms::spatial_pooler::SpatialPooler::getOverlapDutyCycles  (  Real  overlapDutyCycles[]  ) 
Returns the overlap duty cycles for all columns.
'overlapDutyCycles' size must match the number of columns.
overlapDutyCycles  real array to store overlap duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::getPermanence  (  UInt  column, 
Real  permanence[]  
) 
Returns the permanence values for a given column.
'permanence' size must match the number of inputs.
column  integer of column index. 
permanence  real array to store permanence values for the selected column. 
Returns the potential mapping for a given column.
'potential' size must match the number of inputs.
column  integer of column index. 
potential  integer array of potential mapping for the selected column. 
Real nta::algorithms::spatial_pooler::SpatialPooler::getPotentialPct  (  ) 
Returns the potential percent.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getPotentialRadius  (  ) 
Returns the potential radius.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getSpVerbosity  (  ) 
Returns the verbosity level.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getStimulusThreshold  (  ) 
Returns the stimulus threshold.
Real nta::algorithms::spatial_pooler::SpatialPooler::getSynPermActiveInc  (  ) 
Returns the permanence increment amount for active synapses inputs.
Real nta::algorithms::spatial_pooler::SpatialPooler::getSynPermBelowStimulusInc  (  ) 
Returns the permanence increment amount for columns that have not been recently active.
Real nta::algorithms::spatial_pooler::SpatialPooler::getSynPermConnected  (  ) 
Returns the permanence amount that qualifies a synapse as being connected.
Real nta::algorithms::spatial_pooler::SpatialPooler::getSynPermInactiveDec  (  ) 
Returns the permanence decrement amount for inactive synapses.
Real nta::algorithms::spatial_pooler::SpatialPooler::getSynPermTrimThreshold  (  ) 
Returns the permanence trim threshold.
UInt nta::algorithms::spatial_pooler::SpatialPooler::getUpdatePeriod  (  ) 
Returns the update period.
bool nta::algorithms::spatial_pooler::SpatialPooler::getWrapAround  (  ) 
Returns boolean value of wrapAround which indicates if receptive fields should wrap around from the beginning the input dimensions to the end.
void nta::algorithms::spatial_pooler::SpatialPooler::inhibitColumns_  (  vector< Real > &  overlaps, 
vector< UInt > &  activeColumns  
) 
Performs inhibition.
This method calculates the necessary values needed to actually perform inhibition and then delegates the task of picking the active columns to helper functions.
overlaps  an array containing the overlap score for each column. The overlap score for a column is defined as the number of synapses in a "connected state" (connected synapses) that are connected to input bits which are turned on. 
activeColumns  an int array containing the indices of the active columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::inhibitColumnsGlobal_  (  vector< Real > &  overlaps, 
Real  density,  
vector< UInt > &  activeColumns  
) 
Perform global inhibition.
Performing global inhibition entails picking the top 'numActive' columns with the highest overlap score in the entire region. At most half of the columns in a local neighborhood are allowed to be active.
overlaps  a real array containing the overlap score for each column. The overlap score for a column is defined as the number of synapses in a "connected state" (connected synapses) that are connected to input bits which are turned on. 
density  a real number of the fraction of columns to survive inhibition. 
activeColumns  an int array containing the indices of the active columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::inhibitColumnsLocal_  (  vector< Real > &  overlaps, 
Real  density,  
vector< UInt > &  activeColumns  
) 
Performs local inhibition.
Local inhibition is performed on a column by column basis. Each column observes the overlaps of its neighbors and is selected if its overlap score is within the top 'numActive' in its local neighborhood. At most half of the columns in a local neighborhood are allowed to be active.
overlaps  an array containing the overlap score for each column. The overlap score for a column is defined as the number of synapses in a "connected state" (connected synapses) that are connected to input bits which are turned on. 
density  The fraction of columns to survive inhibition. This value is only an intended target. Since the surviving columns are picked in a local fashion, the exact fraction of survining columns is likely to vary. 
activeColumns  an int array containing the indices of the active columns. 

virtual 
Initialize the spatial pooler using the given parameters.
inputDimensions  A list of integers representing the dimensions of the input vector. Format is [height, width, depth, ...], where each value represents the size of the dimension. For a topology of one dimesion with 100 inputs use [100]. For a two dimensional topology of 10x5 use [10,5]. 
columnDimensions  A list of integers representing the dimensions of the columns in the region. Format is [height, width, depth, ...], where each value represents the size of the dimension. For a topology of one dimesion with 2000 columns use 2000, or [2000]. For a three dimensional topology of 32x64x16 use [32, 64, 16]. 
potentialRadius  This parameter deteremines the extent of the input that each column can potentially be connected to. This can be thought of as the input bits that are visible to each column, or a 'receptive field' of the field of vision. A large enough value will result in global coverage, meaning that each column can potentially be connected to every input bit. This parameter defines a square (or hyper square) area: a column will have a max square potential pool with sides of length (2 * potentialRadius + 1). 
potentialPct  The percent of the inputs, within a column's potential radius, that a column can be connected to. If set to 1, the column will be connected to every input within its potential radius. This parameter is used to give each column a unique potential pool when a large potentialRadius causes overlap between the columns. At initialization time we choose ((2*potentialRadius + 1)^(# inputDimensions) * potentialPct) input bits to comprise the column's potential pool. 
globalInhibition  If true, then during inhibition phase the winning columns are selected as the most active columns from the region as a whole. Otherwise, the winning columns are selected with resepct to their local neighborhoods. Global inhibition boosts performance significantly but there is no topology at the output. 
localAreaDensity  The desired density of active columns within a local inhibition area (the size of which is set by the internally calculated inhibitionRadius, which is in turn determined from the average size of the connected potential pools of all columns). The inhibition logic will insure that at most N columns remain ON within a local inhibition area, where N = localAreaDensity * (total number of columns in inhibition area). If localAreaDensity is set to a negative value output sparsity will be determined by the numActivePerInhArea. 
numActiveColumnsPerInhArea  An alternate way to control the sparsity of active columns. If numActivePerInhArea is specified then localAreaDensity must be less than 0, and vice versa. When numActivePerInhArea > 0, the inhibition logic will insure that at most 'numActivePerInhArea' columns remain ON within a local inhibition area (the size of which is set by the internally calculated inhibitionRadius). When using this method, as columns learn and grow their effective receptive fields, the inhibitionRadius will grow, and hence the net density of the active columns will decrease. This is in contrast to the localAreaDensity method, which keeps the density of active columns the same regardless of the size of their receptive fields. 
stimulusThreshold  This is a number specifying the minimum number of synapses that must be active in order for a column to turn ON. The purpose of this is to prevent noisy input from activating columns. 
synPermInactiveDec  The amount by which the permanence of an inactive synapse is decremented in each learning step. 
synPermActiveInc  The amount by which the permanence of an active synapse is incremented in each round. 
synPermConnected  The default connected threshold. Any synapse whose permanence value is above the connected threshold is a "connected synapse", meaning it can contribute to the cell's firing. 
minPctOverlapDutyCycles  A number between 0 and 1.0, used to set a floor on how often a column should have at least stimulusThreshold active inputs. Periodically, each column looks at the overlap duty cycle of all other column within its inhibition radius and sets its own internal minimal acceptable duty cycle to: minPctDutyCycleBeforeInh * max(other columns' duty cycles). On each iteration, any column whose overlap duty cycle falls below this computed value will get all of its permanence values boosted up by synPermActiveInc. Raising all permanences in response to a subpar duty cycle before inhibition allows a cell to search for new inputs when either its previously learned inputs are no longer ever active, or when the vast majority of them have been "hijacked" by other columns. 
minPctActiveDutyCycles  A number between 0 and 1.0, used to set a floor on how often a column should be activate. Periodically, each column looks at the activity duty cycle of all other columns within its inhibition radius and sets its own internal minimal acceptable duty cycle to: minPctDutyCycleAfterInh * max(other columns' duty cycles). 
On each iteration, any column whose duty cycle after inhibition falls below this computed value will get its internal boost factor increased.
dutyCyclePeriod  The period used to calculate duty cycles. Higher values make it take longer to respond to changes in boost. Shorter values make it potentially more unstable and likely to oscillate. 
maxBoost  The maximum overlap boost factor. Each column's overlap gets multiplied by a boost factor before it gets considered for inhibition. The actual boost factor for a column is a number between 1.0 and maxBoost. A boost factor of 1.0 is used if the duty cycle is >= minOverlapDutyCycle, maxBoost is used if the duty cycle is 0, and any duty cycle in between is linearly extrapolated from these 2 endpoints. 
seed  Seed for our random number generator. If seed is < 0 a randomly generated seed is used. The behavior of the spatial pooler is deterministic once the seed is set. 
spVerbosity  spVerbosity level: 0, 1, 2, or 3 
wrapAround  boolean value that determines whether or not inputs at the beginning and end of an input dimension are considered neighbors for the purpose of mapping inputs to columns. 
vector<Real> nta::algorithms::spatial_pooler::SpatialPooler::initPermanence_  (  vector< UInt > &  potential, 
Real  connectedPct  
) 
Initializes the permanences of a column.
The method returns a 1D array the size of the input, where each entry in the array represents the initial permanence value between the input bit at the particular index in the array, and the column represented by the 'index' parameter.
potential  A int vector specifying the potential pool of the column. Permanence values will only be generated for input bits 
corresponding to indices for which the mask value is 1.
connectedPct  A real value between 0 or 1 specifying the percent of the input bits that will start off in a connected state. 
Real nta::algorithms::spatial_pooler::SpatialPooler::initPermConnected_  (  ) 
Returns a randomly generated permanence value for a synapses that is initialized in a connected state.
The basic idea here is to initialize permanence values very close to synPermConnected so that a small number of learning steps could make it disconnected or connected.
Note: experimentation was done a long time ago on the best way to initialize permanence values, but the history for this particular scheme has been lost.
Real nta::algorithms::spatial_pooler::SpatialPooler::initPermNonConnected_  (  ) 
Returns a randomly generated permanence value for a synapses that is to be initialized in a nonconnected state.
bool nta::algorithms::spatial_pooler::SpatialPooler::isUpdateRound_  (  ) 

virtual 
Load (deserialize) and initialize the spatial pooler from the specified input stream.
inStream  A valid istream. 
Maps a column to its respective input index, keeping to the topology of the region.
It takes the index of the column as an argument and determines what is the index of the flattened input vector that is to be the center of the column's potential pool. It distributes the columns over the inputs uniformly. The return value is an integer representing the index of the input bit. Examples of the expected output of this method: If the topology is one dimensional, and the column index is 0, this method will return the input index 0. If the column index is 1, and there are 3 columns over 7 inputs, this method will return the input index 3. If the topology is two dimensional, with column dimensions [3, 5] and input dimensions [7, 11], and the column index is 3, the method returns input index 8.
index  The index identifying a column in the permanence, potential and connectivity matrices. 
wrapAround  A boolean value indicating that boundaries should be ignored. 
vector<UInt> nta::algorithms::spatial_pooler::SpatialPooler::mapPotential_  (  UInt  column, 
bool  wrapAround  
) 
Maps a column to its input bits.
This method encapsultes the topology of the region. It takes the index of the column as an argument and determines what are the indices of the input vector that are located within the column's potential pool. The return value is a list containing the indices of the input bits. The current implementation of the base class only supports a 1 dimensional topology of columsn with a 1 dimensional topology of inputs. To extend this class to support 2D topology you will need to override this method. Examples of the expected output of this method: If the potentialRadius is greater than or equal to the entire input space, (global visibility), then this method returns an array filled with all the indices If the topology is one dimensional, and the potentialRadius is 5, this method will return an array containing 5 consecutive values centered on the index of the column (wrapping around if necessary). If the topology is two dimensional (not implemented), and the potentialRadius is 5, the method should return an array containing 25 '1's, where the exact indices are to be determined by the mapping from 1D index to 2D position.
column  An int index identifying a column in the permanence, potential and connectivity matrices. 
wrapAround  A boolean value indicating that boundaries should be region boundaries ignored. 

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.

virtual 
Save (serialize) the current state of the spatial pooler to the specified output stream.
outStream  A valid ostream. 
void nta::algorithms::spatial_pooler::SpatialPooler::seed_  (  UInt64  seed  ) 
Initialize the random seed.
seed  64bit int of random seed 
void nta::algorithms::spatial_pooler::SpatialPooler::setActiveDutyCycles  (  Real  activeDutyCycles[]  ) 
Sets the activity duty cycles for all columns.
'activeDutyCycles' size must match the number of columns.
activeDutyCycles  real array of the activity duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::setBoostFactors  (  Real  boostFactors[]  ) 
Sets the boost factors for all columns.
'boostFactors' size must match the number of columns.
boostFactors  real array of boost factors of all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::setDutyCyclePeriod  (  UInt  dutyCyclePeriod  ) 
Sets the duty cycle period.
dutyCyclePeriod  integer number of duty cycle period. 
void nta::algorithms::spatial_pooler::SpatialPooler::setGlobalInhibition  (  bool  globalInhibition  ) 
Sets global inhibition.
globalInhibition  boolen varable of whether global inhibition is enabled. 
void nta::algorithms::spatial_pooler::SpatialPooler::setInhibitionRadius  (  UInt  inhibitionRadius  ) 
Sets the inhibition radius.
inhibitionRadius  integer of inhibition radius. 
void nta::algorithms::spatial_pooler::SpatialPooler::setIterationLearnNum  (  UInt  iterationLearnNum  ) 
Sets the learning iteration number.
iterationLearnNum  integer of learning iteration number. 
void nta::algorithms::spatial_pooler::SpatialPooler::setIterationNum  (  UInt  iterationNum  ) 
Sets the iteration number.
iterationNum  integer number of iteration number. 
void nta::algorithms::spatial_pooler::SpatialPooler::setLocalAreaDensity  (  Real  localAreaDensity  ) 
Sets the local area density.
Invalidates the 'numActivePerInhArea' parameter".
localAreaDensity  real number of local area density. 
void nta::algorithms::spatial_pooler::SpatialPooler::setMaxBoost  (  Real  maxBoost  ) 
Sets the maximum boost value.
maxBoost  real number of maximum boost value, must be larger than 1.0 
void nta::algorithms::spatial_pooler::SpatialPooler::setMinActiveDutyCycles  (  Real  minActiveDutyCycles[]  ) 
Sets the minimum activity duty cycles for all columns.
'_minActiveDutyCycles' size must match the number of columns.
minActiveDutyCycles  real array of the minimum activity duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::setMinOverlapDutyCycles  (  Real  minOverlapDutyCycles[]  ) 
Sets the minimum overlap duty cycles for all columns.
'_minOverlapDutyCycles' size must match the number of columns.
minOverlapDutyCycles  real array of the minimum overlap duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::setMinPctActiveDutyCycles  (  Real  minPctActiveDutyCycles  ) 
Sets the minimum tolerated activity duty cycle, given as percent of neighbors' activity duty cycle.
minPctActiveDutyCycles  real number of the minimum tolerated activity duty cycle. 
void nta::algorithms::spatial_pooler::SpatialPooler::setMinPctOverlapDutyCycles  (  Real  minPctOverlapDutyCycles  ) 
Sets the minimum tolerated overlaps, given as percent of neighbors overlap score.
minPctOverlapDutyCycles  real number of the minimum tolerated overlaps. 
void nta::algorithms::spatial_pooler::SpatialPooler::setNumActiveColumnsPerInhArea  (  UInt  numActiveColumnsPerInhArea  ) 
Sets the number of active columns per inhibition area.
Invalidates the 'localAreaDensity' parameter.
numActiveColumnsPerInhArea  integer number of active columns per inhibition area. 
void nta::algorithms::spatial_pooler::SpatialPooler::setOverlapDutyCycles  (  Real  overlapDutyCycles[]  ) 
Sets the overlap duty cycles for all columns.
'overlapDutyCycles' size must match the number of columns.
overlapDutyCycles  real array of the overlap duty cycles for all columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::setPermanence  (  UInt  column, 
Real  permanence[]  
) 
Sets the permanence values for a given column.
'permanence' size must match the number of inputs.
column  integer of column index. 
permanence  real array of permanence values for the selected column. 
Sets the potential mapping for a given column.
'potential' size must match the number of inputs.
column  integer of column index. 
potential  integer array of potential mapping for the selected column. 
void nta::algorithms::spatial_pooler::SpatialPooler::setPotentialPct  (  Real  potentialPct  ) 
Sets the potential percent.
potentialPct  real number of potential percent. 
void nta::algorithms::spatial_pooler::SpatialPooler::setPotentialRadius  (  UInt  potentialRadius  ) 
Sets the potential radius.
potentialRadius  integer number of potential raduis. 
void nta::algorithms::spatial_pooler::SpatialPooler::setSpVerbosity  (  UInt  spVerbosity  ) 
Sets the verbosity level.
spVerbosity  integer of verbosity level. 
void nta::algorithms::spatial_pooler::SpatialPooler::setStimulusThreshold  (  UInt  stimulusThreshold  ) 
Sets the stimulus threshold.
stimulusThreshold  (positive) integer number of stimulus threshold 
void nta::algorithms::spatial_pooler::SpatialPooler::setSynPermActiveInc  (  Real  synPermActiveInc  ) 
Sets the permanence increment amount for active synapses inputs.
synPermActiveInc  real number of the permanence increment amount for active synapses inputs, must be >0. 
void nta::algorithms::spatial_pooler::SpatialPooler::setSynPermBelowStimulusInc  (  Real  synPermBelowStimulusInc  ) 
Sets the permanence increment amount for columns that have not been recently active.
synPermBelowStimulusInc  real number of the permanence increment amount for columns that have not been recently active, must be larger than 0. 
void nta::algorithms::spatial_pooler::SpatialPooler::setSynPermConnected  (  Real  setSynPermConnected  ) 
Sets the permanence amount that qualifies a synapse as being connected.
setSynPermConnected  real number of the permanence amount that qualifies a synapse as being connected. 
void nta::algorithms::spatial_pooler::SpatialPooler::setSynPermInactiveDec  (  Real  synPermInactiveDec  ) 
Returns the permanence decrement amount for inactive synapses.
synPermInactiveDec  real number of the permanence decrement amount for inactive synapses. 
void nta::algorithms::spatial_pooler::SpatialPooler::setSynPermTrimThreshold  (  Real  synPermTrimThreshold  ) 
Sets the permanence trim threshold.
synPermTrimThreshold  real number of the permanence trim threshold. 
void nta::algorithms::spatial_pooler::SpatialPooler::setUpdatePeriod  (  UInt  updatePeriod  ) 
Sets the update period.
updatePeriod  integer of update period. 
void nta::algorithms::spatial_pooler::SpatialPooler::setWrapAround  (  bool  wrapAround  ) 
Sets wrapAround.
wrapAround  boolean value 
void nta::algorithms::spatial_pooler::SpatialPooler::stripUnlearnedColumns  (  UInt  activeArray[]  ) 
Removes the set of columns who have never been active from the set of active columns selected in the inhibition round.
Such columns cannot represent learned pattern and are therefore meaningless if only inference is required.
activeArray  An int array containing the indices of the active columns. 
void nta::algorithms::spatial_pooler::SpatialPooler::updateBookeepingVars_  (  bool  learn  ) 
Updates counter instance variables each round.
learn  a boolean value indicating whether learning should be performed. Learning entails updating the permanence values of the synapses, and hence modifying the 'state' of the model. setting learning to 'off' might be useful for indicating separate training vs. testing sets. 
void nta::algorithms::spatial_pooler::SpatialPooler::updateBoostFactors_  (  ) 
Update the boost factors for all columns.
The boost factors are used to increase the overlap of inactive columns to improve their chances of becoming active. and hence encourage participation of more columns in the learning process. This is a line defined as: y = mx + b boost = (1maxBoost)/minDuty * dutyCycle + maxFiringBoost. Intuitively this means that columns that have been active enough have a boost factor of 1, meaning their overlap is not boosted. Columns whose active duty cycle drops too much below that of their neighbors are boosted depending on how infrequently they have been active. The more infrequent, the more they are boosted. The exact boost factor is linearly interpolated between the points (dutyCycle:0, boost:maxFiringBoost) and (dutyCycle:minDuty, boost:1.0).
boostFactor ^ maxBoost _  \  \ 1 _  \ _ _ _ _ _ _ _  +> activeDutyCycle  minActiveDutyCycle
void nta::algorithms::spatial_pooler::SpatialPooler::updateDutyCycles_  (  vector< UInt > &  overlaps, 
UInt  activeArray[]  
) 
Updates the duty cycles for each column.
The OVERLAP duty cycle is a moving average of the number of inputs which overlapped with the each column. The ACTIVITY duty cycles is a moving average of the frequency of activation for each column.
overlaps  an int vector containing the overlap score for each column. The overlap score for a column is defined as the number of synapses in a "connected state" (connected synapses) that are connected to input bits which are turned on. 
activeArray  An int array containing the indices of the active columns, the sprase set of columns which survived inhibition 

static 
Updates a duty cycle estimate with a new value.
This is a helper function that is used to update several duty cycle variables in the Column class, such as: overlapDutyCucle, activeDutyCycle, minPctDutyCycleBeforeInh, minPctDutyCycleAfterInh, etc. returns the updated duty cycle. Duty cycles are updated according to the following formula:
(period  1)*dutyCycle + newValue dutyCycle :=  period
dutyCycles  A real array containing one or more duty cycle values that need to be updated. 
newValues  A int vector used to update the duty cycle. 
period  A int number indicating the period of the duty cycle 
void nta::algorithms::spatial_pooler::SpatialPooler::updateInhibitionRadius_  (  ) 
Update the inhibition radius.
The inhibition radius is a meausre of the square (or hypersquare) of columns that each a column is "conencted to" on average. Since columns are not connected to each other directly, we determine this quantity by first figuring out how many inputs a column is connected to, and then multiplying it by the total number of columns that exist for each input. For multiple dimension the aforementioned calculations are averaged over all dimensions of inputs and columns. This value is meaningless if global inhibition is enabled.
void nta::algorithms::spatial_pooler::SpatialPooler::updateMinDutyCycles_  (  ) 
Updates the minimum duty cycles defining normal activity for a column.
A column with activity duty cycle below this minimum threshold is boosted.
void nta::algorithms::spatial_pooler::SpatialPooler::updateMinDutyCyclesGlobal_  (  ) 
Updates the minimum duty cycles in a global fashion.
Sets the minimum duty cycles for the overlap and activation of all columns to be a percent of the maximum in the region, specified by minPctOverlapDutyCycle and minPctActiveDutyCycle respectively. Functionaly it is equivalent to _updateMinDutyCyclesLocal, but this function exploits the globalilty of the compuation to perform it in a straightforward, and more efficient manner.
void nta::algorithms::spatial_pooler::SpatialPooler::updateMinDutyCyclesLocal_  (  ) 
Updates the minimum duty cycles.
The minimum duty cycles are determined locally. Each column's minimum duty cycles are set to be a percent of the maximum duty cycles in the column's neighborhood. Unlike _updateMinDutyCycles
void nta::algorithms::spatial_pooler::SpatialPooler::updatePermanencesForColumn_  (  vector< Real > &  perm, 
UInt  column,  
bool  raisePerm = true 

) 
This method updates the permanence matrix with a column's new permanence values.
The column is identified by its index, which reflects the row in the matrix, and the permanence is given in 'dense' form, i.e. a full arrray containing all the zeros as well as the nonzero values. It is in charge of implementing 'clipping'  ensuring that the permanence values are always between 0 and 1  and 'trimming'  enforcing sparsity by zeroing out all permanence values below '_synPermTrimThreshold'. It also maintains the consistency between 'self._permanences' (the matrix storeing the permanence values), 'self._connectedSynapses', (the matrix storing the bits each column is connected to), and 'self._connectedCounts' (an array storing the number of input bits each column is connected to). Every method wishing to modify the permanence matrix should do so through this method.
perm  An int vector of permanence values for a column. The array is "dense", i.e. it contains an entry for each input bit, even if the permanence value is 0. 
column  An int number identifying a column in the permanence, potential and connectivity matrices. 
raisePerm  a boolean value indicating whether the permanence values should be raised until a minimum number are synapses are in a connected state. Should be set to 'false' when a direct assignment is required. 

inlinevirtual 
Get the version number of this spatial pooler.
Definition at line 290 of file SpatialPooler.hpp.