def _initFunctions(self): # initialize excite/decay functions if self._exciteFunctionType == 'Fixed': self._exciteFunction = FixedExciteFunction() elif self._exciteFunctionType == 'Logistic': self._exciteFunction = LogisticExciteFunction() elif self._exciteFunctionType == 'Linear': self._exciteFunction = LinearExciteFunction() else: raise NotImplementedError('unknown excite function type'+exciteFunctionType) if self._decayFunctionType == 'NoDecay': self._decayFunction = NoDecayFunction() elif self._decayFunctionType == 'Exponential': self._decayFunction = ExponentialDecayFunction(self._decayTimeConst) elif self._decayFunctionType == 'Linear': self._decayFunction = LinearDecayFunction(self._decayLinearConst) else: raise NotImplementedError('unknown decay function type'+decayFunctionType)
def __init__( self, # union_temporal_pooler.py parameters activeOverlapWeight=1.0, predictedActiveOverlapWeight=0.0, maxUnionActivity=0.20, exciteFunctionType='Fixed', decayFunctionType='NoDecay', decayTimeConst=20.0, synPermPredActiveInc=0.0, synPermPreviousPredActiveInc=0.0, historyLength=0, minHistory=0, **kwargs): """ Please see spatial_pooler.py in NuPIC for super class parameter descriptions. Class-specific parameters: ------------------------------------- @param activeOverlapWeight: A multiplicative weight applied to the overlap between connected synapses and active-cell input @param predictedActiveOverlapWeight: A multiplicative weight applied to the overlap between connected synapses and predicted-active-cell input @param fixedPoolingActivationBurst: A Boolean, which, if True, has the Union Temporal Pooler grant a fixed amount of pooling activation to columns whenever they win the inhibition step. If False, columns' pooling activation is calculated based on their current overlap. @param exciteFunction: If fixedPoolingActivationBurst is False, this specifies the ExciteFunctionBase used to excite pooling activation. @param decayFunction: Specifies the DecayFunctionBase used to decay pooling activation. @param maxUnionActivity: Maximum sparsity of the union SDR @param decayTimeConst Time constant for the decay function @param minHistory don't perform union (output all zeros) until buffer length >= minHistory """ super(UnionTemporalPooler, self).__init__(**kwargs) self._activeOverlapWeight = activeOverlapWeight self._predictedActiveOverlapWeight = predictedActiveOverlapWeight self._maxUnionActivity = maxUnionActivity self._exciteFunctionType = exciteFunctionType self._decayFunctionType = decayFunctionType self._synPermPredActiveInc = synPermPredActiveInc self._synPermPreviousPredActiveInc = synPermPreviousPredActiveInc self._historyLength = historyLength self._minHistory = minHistory # initialize excite/decay functions if exciteFunctionType == 'Fixed': self._exciteFunction = FixedExciteFunction() elif exciteFunctionType == 'Logistic': self._exciteFunction = LogisticExciteFunction() else: raise NotImplementedError('unknown excite function type' + exciteFunctionType) if decayFunctionType == 'NoDecay': self._decayFunction = NoDecayFunction() elif decayFunctionType == 'Exponential': self._decayFunction = ExponentialDecayFunction(decayTimeConst) else: raise NotImplementedError('unknown decay function type' + decayFunctionType) # The maximum number of cells allowed in a single union SDR self._maxUnionCells = int(self.getNumColumns() * self._maxUnionActivity) # Scalar activation of potential union SDR cells; most active cells become # the union SDR self._poolingActivation = numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE) # include a small amount of tie-breaker when sorting pooling activation numpy.random.seed(1) self._poolingActivation_tieBreaker = numpy.random.randn( self.getNumColumns()) * _TIE_BREAKER_FACTOR # time since last pooling activation increment # initialized to be a large number self._poolingTimer = numpy.ones(self.getNumColumns(), dtype=REAL_DTYPE) * 1000 # pooling activation level after the latest update, used for sigmoid decay function self._poolingActivationInitLevel = numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE) # Current union SDR; the output of the union pooler algorithm self._unionSDR = numpy.array([], dtype=UINT_DTYPE) # Indices of active cells from spatial pooler self._activeCells = numpy.array([], dtype=UINT_DTYPE) # lowest possible pooling activation level self._poolingActivationlowerBound = 0.1 self._preActiveInput = numpy.zeros(self.getNumInputs(), dtype=REAL_DTYPE) # predicted inputs from the last n steps self._prePredictedActiveInput = numpy.zeros( (self.getNumInputs(), self._historyLength), dtype=REAL_DTYPE)
def setUp(self): self.fcn = LogisticExciteFunction(xMidpoint=5, minValue=10, maxValue=20, steepness=1)