def compute(self, inputVector, learn, activeArray, burstingColumns,
              predictedCells):
    """
    This is the primary public method of the class. This function takes an input
    vector and outputs the indices of the active columns.

    New parameters defined here:
    ----------------------------
    @param inputVector:         The active cells from a Temporal Memory
    @param learn:               A Boolean specifying whether learning will be
                                performed
    @param activeArray:         An array representing the active columns
                                produced by this method
    @param burstingColumns:     A numpy array with numColumns elements having
                                binary values with 1 representing a
                                currently bursting column in Temporal Memory.

    @param predictedCells: A numpy array with numInputs elements. A 1
                                    indicates that this cell switching from
                                    predicted state in the previous time step to
                                    active state in the current timestep
    """
    assert (numpy.size(inputVector) == self._numInputs)
    assert (numpy.size(predictedCells) == self._numInputs)

    self._updateBookeepingVars(learn)
    inputVector = numpy.array(inputVector, dtype=realDType)
    predictedCells = numpy.array(predictedCells, dtype=realDType)
    inputVector.reshape(-1)

    if self._spVerbosity > 3:
      print " Input bits: ", inputVector.nonzero()[0]
      print " predictedCells: ", predictedCells.nonzero()[0]

    # Phase 1: Calculate overlap scores
    # The overlap score has 4 components:
    # (1) Overlap between correctly predicted input cells and pooling TP cells
    # (2) Overlap between active input cells and all TP cells
    #     (like standard SP calculation)
    # (3) Overlap between correctly predicted input cells and all TP cells
    # (4) Overlap from bursting columns in TM and all TP cells

    # 1) Calculate pooling overlap
    if self.usePoolingRule:
      overlapsPooling = self._calculatePoolingActivity(predictedCells, learn)

      if self._spVerbosity > 4:
        print "usePoolingRule: Overlaps after step 1:"
        print "   ", overlapsPooling

    else:
      overlapsPooling = 0

    # 2) Calculate overlap between active input cells and connected synapses
    overlapsAllInput = self._calculateOverlap(inputVector)

    # 3) overlap with predicted inputs
    # NEW: Isn't this redundant with 1 and 2)? This looks at connected synapses
    # only.
    # If 1) is called with learning=False connected synapses are used and
    # it is somewhat redundant although there is a boosting factor in 1) which
    # makes 1's effect stronger. If 1) is called with learning=True it's less
    # redundant
    overlapsPredicted = self._calculateOverlap(predictedCells)

    if self._spVerbosity > 4:
      print "Overlaps with all inputs:"
      print " Number of On Bits: ", inputVector.sum()
      print "   ", overlapsAllInput

      print "Overlaps with predicted inputs:"
      print "   ", overlapsPredicted

    # 4) consider bursting columns
    if self.useBurstingRule:
      overlapsBursting = self._calculateBurstingColumns(burstingColumns)

      if self._spVerbosity > 4:
        print "Overlaps with bursting inputs:"
        print "   ", overlapsBursting
    else:
      overlapsBursting = 0

    overlaps = (overlapsPooling + overlapsPredicted +  overlapsAllInput +
               overlapsBursting)

    # Apply boosting when learning is on
    if learn:
      boostedOverlaps = self._boostFactors * overlaps
      if self._spVerbosity > 4:
        print "Overlaps after boosting:"
        print "   ", boostedOverlaps

    else:
      boostedOverlaps = overlaps


    # Apply inhibition to determine the winning columns
    activeColumns = self._inhibitColumns(boostedOverlaps)

    if learn:
      self._adaptSynapses(inputVector, activeColumns, predictedCells)
      self._updateDutyCycles(overlaps, activeColumns)
      self._bumpUpWeakColumns()
      self._updateBoostFactors()
      if self._isUpdateRound():
        self._updateInhibitionRadius()
        self._updateMinDutyCycles()

    activeArray.fill(0)
    if activeColumns.size > 0:
      activeArray[activeColumns] = 1

    # update pooling state of cells
    activeColumnIndices = numpy.where(overlapsPredicted[activeColumns] > 0)[0]
    activeColWithPredictedInput = activeColumns[activeColumnIndices]

    numUnPredictedInput = float(len(burstingColumns.nonzero()[0]))
    numPredictedInput = float(len(predictedCells))
    fracUnPredicted = numUnPredictedInput / (numUnPredictedInput +
                                             numPredictedInput)

    self._updatePoolingState(activeColWithPredictedInput, fracUnPredicted)

    if self._spVerbosity > 2:
      activeColumns.sort()
      print "The following columns are finally active:"
      print "   ", activeColumns
      print "The following columns are in pooling state:"
      print "   ", self._poolingActivation.nonzero()[0]
      # print "Inputs to pooling columns"
      # print "   ",overlapsPredicted[self._poolingColumns]

    return activeColumns
def compute ( self , inputVector , learn , activeArray , burstingColumns , predictedCells ) : assert ( numpy . size ( inputVector ) == self . _numInputs ) assert ( numpy . size ( predictedCells ) == self . _numInputs ) self . _updateBookeepingVars ( learn ) inputVector = numpy . array ( inputVector , dtype = realDType ) predictedCells = numpy . array ( predictedCells , dtype = realDType ) inputVector . reshape ( - 1 ) if self . _spVerbosity > 3 : print " Input bits: " , inputVector . nonzero ( ) [ 0 ] print " predictedCells: " , predictedCells . nonzero ( ) [ 0 ] if self . usePoolingRule : overlapsPooling = self . _calculatePoolingActivity ( predictedCells , learn ) if self . _spVerbosity > 4 : print "usePoolingRule: Overlaps after step 1:" print "   " , overlapsPooling else : overlapsPooling = 0 overlapsAllInput = self . _calculateOverlap ( inputVector ) overlapsPredicted = self . _calculateOverlap ( predictedCells ) if self . _spVerbosity > 4 : print "Overlaps with all inputs:" print " Number of On Bits: " , inputVector . sum ( ) print "   " , overlapsAllInput print "Overlaps with predicted inputs:" print "   " , overlapsPredicted if self . useBurstingRule : overlapsBursting = self . _calculateBurstingColumns ( burstingColumns ) if self . _spVerbosity > 4 : print "Overlaps with bursting inputs:" print "   " , overlapsBursting else : overlapsBursting = 0 overlaps = ( overlapsPooling + overlapsPredicted + overlapsAllInput + overlapsBursting ) if learn : boostedOverlaps = self . _boostFactors * overlaps if self . _spVerbosity > 4 : print "Overlaps after boosting:" print "   " , boostedOverlaps else : boostedOverlaps = overlaps activeColumns = self . _inhibitColumns ( boostedOverlaps ) if learn : self . _adaptSynapses ( inputVector , activeColumns , predictedCells ) self . _updateDutyCycles ( overlaps , activeColumns ) self . _bumpUpWeakColumns ( ) self . _updateBoostFactors ( ) if self . _isUpdateRound ( ) : self . _updateInhibitionRadius ( ) self . _updateMinDutyCycles ( ) activeArray . fill ( 0 ) if activeColumns . size > 0 : activeArray [ activeColumns ] = 1 activeColumnIndices = numpy . where ( overlapsPredicted [ activeColumns ] > 0 ) [ 0 ] activeColWithPredictedInput = activeColumns [ activeColumnIndices ] numUnPredictedInput = float ( len ( burstingColumns . nonzero ( ) [ 0 ] ) ) numPredictedInput = float ( len ( predictedCells ) ) fracUnPredicted = numUnPredictedInput / ( numUnPredictedInput + numPredictedInput ) self . _updatePoolingState ( activeColWithPredictedInput , fracUnPredicted ) if self . _spVerbosity > 2 : activeColumns . sort ( ) print "The following columns are finally active:" print "   " , activeColumns print "The following columns are in pooling state:" print "   " , self . _poolingActivation . nonzero ( ) [ 0 ] return activeColumns
This is the primary public method of the class. This function takes an input
    vector and outputs the indices of the active columns.

    New parameters defined here:
    ----------------------------
    @param inputVector:         The active cells from a Temporal Memory
    @param learn:               A Boolean specifying whether learning will be
                                performed
    @param activeArray:         An array representing the active columns
                                produced by this method
    @param burstingColumns:     A numpy array with numColumns elements having
                                binary values with 1 representing a
                                currently bursting column in Temporal Memory.

    @param predictedCells: A numpy array with numInputs elements. A 1
                                    indicates that this cell switching from
                                    predicted state in the previous time step to
                                    active state in the current timestep