public class SpatialPooler
extends java.lang.Object
Constructor and Description 

SpatialPooler()
Constructs a new
SpatialPooler 
Modifier and Type  Method and Description 

void 
adaptSynapses(Connections c,
int[] inputVector,
int[] activeColumns)
The primary method in charge of learning.

double 
avgColumnsPerInput(Connections c)
The average number of columns per input, taking into account the topology
of the inputs and columns.

double 
avgConnectedSpanForColumnND(Connections c,
int columnIndex)
The range of connectedSynapses per column, averaged for each dimension.

void 
bumpUpWeakColumns(Connections c)
This method increases the permanence values of synapses of columns whose
activity level has been too low.

int[] 
calculateOverlap(Connections c,
int[] inputVector)
This function determines each column's overlap with the current input
vector.

double[] 
calculateOverlapPct(Connections c,
int[] overlaps)
Return the overlap to connected counts ratio for a given column

void 
compute(Connections c,
int[] inputVector,
int[] activeArray,
boolean learn,
boolean stripNeverLearned)
This is the primary public method of the SpatialPooler class.

void 
connectAndConfigureInputs(Connections c)
Step two of pooler initialization kept separate from initialization
of static members so that they may be set at a different point in
the initialization (as sometimes needed by tests).

TIntArrayList 
getNeighborsND(Connections c,
int columnIndex,
SparseMatrix<?> topology,
int inhibitionRadius,
boolean wrapAround)
Similar to _getNeighbors1D and _getNeighbors2D (Not included in this implementation),
this function Returns a list of indices corresponding to the neighbors of a given column.

int[] 
inhibitColumns(Connections c,
double[] overlaps)
Performs inhibition.

int[] 
inhibitColumnsGlobal(Connections c,
double[] overlaps,
double density)
Perform global inhibition.

int[] 
inhibitColumnsLocal(Connections c,
double[] overlaps,
double density)
Performs inhibition.

void 
init(Connections c)
Initializes the specified
Connections object which contains
the memory and structural anatomy this spatial pooler uses to implement
its algorithms. 
void 
initMatrices(Connections c)
Called to initialize the structural anatomy with configured values and prepare
the anatomical entities for activation.

double[] 
initPermanence(Connections c,
int[] potentialPool,
int index,
double connectedPct)
Initializes the permanences of a column.

static double 
initPermConnected(Connections c)
Returns a randomly generated permanence value for a synapse that is
initialized in a connected state.

static double 
initPermNonConnected(Connections c)
Returns a randomly generated permanence value for a synapses that is to be
initialized in a nonconnected state.

boolean 
isUpdateRound(Connections c)
Returns true if enough rounds have passed to warrant updates of
duty cycles

int 
mapColumn(Connections c,
int columnIndex)
Maps a column to its respective input index, keeping to the topology of
the region.

int[] 
mapPotential(Connections c,
int columnIndex,
boolean wrapAround)
Maps a column to its input bits.

void 
raisePermanenceToThreshold(Connections c,
double[] perm,
int[] maskPotential)
This method ensures that each column has enough connections to input bits
to allow it to become active.

void 
raisePermanenceToThresholdSparse(Connections c,
double[] perm)
This method ensures that each column has enough connections to input bits
to allow it to become active.

TIntArrayList 
stripUnlearnedColumns(Connections c,
int[] activeColumns)
Removes the set of columns who have never been active from the set of
active columns selected in the inhibition round.

void 
updateBookeepingVars(Connections c,
boolean learn)
Updates counter instance variables each cycle.

void 
updateBoostFactors(Connections c)
Update the boost factors for all columns.

void 
updateDutyCycles(Connections c,
int[] overlaps,
int[] activeColumns)
Updates the duty cycles for each column.

double[] 
updateDutyCyclesHelper(Connections c,
double[] dutyCycles,
double[] newInput,
double period)
Updates a duty cycle estimate with a new value.

void 
updateInhibitionRadius(Connections c)
Update the inhibition radius.

void 
updateMinDutyCycles(Connections c)
Updates the minimum duty cycles defining normal activity for a column.

void 
updateMinDutyCyclesGlobal(Connections c)
Updates the minimum duty cycles in a global fashion.

void 
updateMinDutyCyclesLocal(Connections c)
Updates the minimum duty cycles.

void 
updatePermanencesForColumn(Connections c,
double[] perm,
Column column,
int[] maskPotential,
boolean raisePerm)
This method updates the permanence matrix with a column's new permanence
values.

void 
updatePermanencesForColumnSparse(Connections c,
double[] perm,
Column column,
int[] maskPotential,
boolean raisePerm)
This method updates the permanence matrix with a column's new permanence
values.

public void init(Connections c)
Connections
object which contains
the memory and structural anatomy this spatial pooler uses to implement
its algorithms.c
 a Connections
objectpublic void initMatrices(Connections c)
c
 public void connectAndConfigureInputs(Connections c)
c
 the Connections
memorypublic void compute(Connections c, int[] inputVector, int[] activeArray, boolean learn, boolean stripNeverLearned)
inputVector
 An array of 0's and 1's that comprises the input to
the spatial pooler. The array will be treated as a one
dimensional array, therefore the dimensions of the array
do not have to match the exact dimensions specified in the
class constructor. In fact, even a list would suffice.
The number of input bits in the vector must, however,
match the number of bits specified by the call to the
constructor. Therefore there must be a '0' or '1' in the
array for every input bit.activeArray
 An array whose size is equal to the number of columns.
Before the function returns this array will be populated
with 1's at the indices of the active columns, and 0's
everywhere else.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' freezes the SP
and has many uses. For example, you might want to feed in
various inputs and examine the resulting SDR's.public TIntArrayList stripUnlearnedColumns(Connections c, int[] activeColumns)
activeColumns
 An array containing the indices of the active columnspublic void updateMinDutyCycles(Connections c)
c
 public void updateMinDutyCyclesGlobal(Connections c)
Connections.getMinOverlapDutyCycles()
and
minPctActiveDutyCycle respectively. Functionality it is equivalent to
updateMinDutyCyclesLocal(Connections)
, but this function exploits the globalness of the
computation to perform it in a straightforward, and more efficient manner.c
 public void updateMinDutyCyclesLocal(Connections c)
updateMinDutyCyclesGlobal(Connections)
, here the values can be
quite different for different columns.c
 public void updateDutyCycles(Connections c, int[] overlaps, int[] activeColumns)
c
 the Connections
(spatial pooler memory)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 array containing the indices of the active columns,
the sparse set of columns which survived inhibitionpublic double[] updateDutyCyclesHelper(Connections c, double[] dutyCycles, double[] newInput, double period)
c
 the Connections
(spatial pooler memory)dutyCycles
 An array containing one or more duty cycle values that need
to be updatednewInput
 A new numerical value used to update the duty cycleperiod
 The period of the duty cyclepublic double avgConnectedSpanForColumnND(Connections c, int columnIndex)
c
 the Connections
(spatial pooler memory)columnIndex
 the current column for which to avg.public void updateInhibitionRadius(Connections c)
c
 the Connections
(spatial pooler memory)public double avgColumnsPerInput(Connections c)
c
 the Connections
(spatial pooler memory)public void adaptSynapses(Connections c, int[] inputVector, int[] activeColumns)
c
 the Connections
(spatial pooler memory)inputVector
 a integer array that comprises the input to
the spatial pooler. There exists an entry in the array
for every input bit.activeColumns
 an array containing the indices of the columns that
survived inhibition.public void bumpUpWeakColumns(Connections c)
c
 public void raisePermanenceToThreshold(Connections c, double[] perm, int[] maskPotential)
c
 the Connections
memoryperm
 the permanence valuesmaskPotential
 public void raisePermanenceToThresholdSparse(Connections c, double[] perm)
c
 The Connections
memoryperm
 permanence valuespublic void updatePermanencesForColumn(Connections c, double[] perm, Column column, int[] maskPotential, boolean raisePerm)
c
 the Connections
which is the memory model.perm
 An array 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
 The column in the permanence, potential and connectivity matricesmaskPotential
 The indexes of inputs in the specified Column
's pool.raisePerm
 a boolean value indicating whether the permanence valuespublic void updatePermanencesForColumnSparse(Connections c, double[] perm, Column column, int[] maskPotential, boolean raisePerm)
c
 the Connections
which is the memory model.perm
 An array of permanence values for a column. The array is
"sparse", i.e. it contains an entry for each input bit, even
if the permanence value is 0.column
 The column in the permanence, potential and connectivity matricesraisePerm
 a boolean value indicating whether the permanence valuespublic static double initPermConnected(Connections c)
public static double initPermNonConnected(Connections c)
public double[] initPermanence(Connections c, int[] potentialPool, int index, double connectedPct)
c
 the Connections
which is the memory modelpotentialPool
 An array 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.
WARNING: potentialPool is sparse, not an array of "1's"index
 the index of the column being initializedconnectedPct
 A value between 0 or 1 specifying the percent of the input
bits that will start off in a connected state.public int mapColumn(Connections c, int columnIndex)
columnIndex
 The index identifying a column in the permanence, potential
and connectivity matrices.public int[] mapPotential(Connections c, int columnIndex, boolean wrapAround)
c
 Connections
the main memory modelcolumnIndex
 The index identifying a column in the permanence, potential
and connectivity matrices.wrapAround
 A boolean value indicating that boundaries should be
ignored.public TIntArrayList getNeighborsND(Connections c, int columnIndex, SparseMatrix<?> topology, int inhibitionRadius, boolean wrapAround)
c
 matrix configured to this SpatialPooler
's dimensions
for transformation work.columnIndex
 The index identifying a column in the permanence, potential
and connectivity matrices.topology
 A SparseMatrix
with dimensionality info.inhibitionRadius
 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
laid out in one dimension, columns 1 and 10 will be
considered adjacent if wrapAround is set to true:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]public boolean isUpdateRound(Connections c)
c
 the Connections
memory encapsulationpublic void updateBookeepingVars(Connections c, boolean learn)
c
 the Connections
memory encapsulationlearn
 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.public int[] calculateOverlap(Connections c, int[] inputVector)
c
 the Connections
memory encapsulationinputVector
 an input array of 0's and 1's that comprises the input to
the spatial pooler.public double[] calculateOverlapPct(Connections c, int[] overlaps)
c
 overlaps
 public int[] inhibitColumns(Connections c, double[] overlaps)
c
 the Connections
matrixoverlaps
 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.public int[] inhibitColumnsGlobal(Connections c, double[] overlaps, double density)
c
 the Connections
matrixoverlaps
 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.public int[] inhibitColumnsLocal(Connections c, double[] overlaps, double density)
c
 the Connections
matrixoverlaps
 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.public void updateBoostFactors(Connections c)