desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
':param stimulusThreshold: (float) value to set.'
| def setStimulusThreshold(self, stimulusThreshold):
| self._stimulusThreshold = stimulusThreshold
|
':returns: (int) the inhibition radius'
| def getInhibitionRadius(self):
| return self._inhibitionRadius
|
':param inhibitionRadius: (int) value to set'
| def setInhibitionRadius(self, inhibitionRadius):
| self._inhibitionRadius = inhibitionRadius
|
':returns: (int) the duty cycle period'
| def getDutyCyclePeriod(self):
| return self._dutyCyclePeriod
|
':param dutyCyclePeriod: (int) value to set.'
| def setDutyCyclePeriod(self, dutyCyclePeriod):
| self._dutyCyclePeriod = dutyCyclePeriod
|
':returns: (float) the maximum boost value used.'
| def getBoostStrength(self):
| return self._boostStrength
|
'Sets the maximum boost value.
:param boostStrength: (float) value to set'
| def setBoostStrength(self, boostStrength):
| self._boostStrength = boostStrength
|
':returns: the iteration number'
| def getIterationNum(self):
| return self._iterationNum
|
':param iterationNum: (int) value to set'
| def setIterationNum(self, iterationNum):
| self._iterationNum = iterationNum
|
':returns: (int) The number of iterations that have been learned.'
| def getIterationLearnNum(self):
| return self._iterationLearnNum
|
':param iterationLearnNum: (int) value to set'
| def setIterationLearnNum(self, iterationLearnNum):
| self._iterationLearnNum = iterationLearnNum
|
':returns: (int) the verbosity level, larger is more verbose.'
| def getSpVerbosity(self):
| return self._spVerbosity
|
':param spVerbosity: (int) value to set, larger is more verbose.'
| def setSpVerbosity(self, spVerbosity):
| self._spVerbosity = spVerbosity
|
':returns: (int) The period at which active duty cycles are updated.'
| def getUpdatePeriod(self):
| return self._updatePeriod
|
':param updatePeriod: (int) The period at which active duty cycles are
updated.'
| def setUpdatePeriod(self, updatePeriod):
| self._updatePeriod = updatePeriod
|
'Sparsity is enforced by trimming out all permanence values below this value.
:returns: (float) the permanence trim threshold'
| def getSynPermTrimThreshold(self):
| return self._synPermTrimThreshold
|
'Sparsity is enforced by trimming out all permanence values below this value.
:param synPermTrimThreshold: (float) the permanence trim threshold'
| def setSynPermTrimThreshold(self, synPermTrimThreshold):
| self._synPermTrimThreshold = synPermTrimThreshold
|
':returns: (float) the permanence increment amount for active synapses inputs'
| def getSynPermActiveInc(self):
| return self._synPermActiveInc
|
'Sets the permanence increment amount for active synapses.
:param synPermActiveInc: (float) value to set.'
| def setSynPermActiveInc(self, synPermActiveInc):
| self._synPermActiveInc = synPermActiveInc
|
':returns: (float) the permanence decrement amount for inactive synapses.'
| def getSynPermInactiveDec(self):
| return self._synPermInactiveDec
|
'Sets the permanence decrement amount for inactive synapses.
:param synPermInactiveDec: (float) value to set.'
| def setSynPermInactiveDec(self, synPermInactiveDec):
| self._synPermInactiveDec = synPermInactiveDec
|
':returns: (float) the permanence increment amount for columns that have not
been recently active.'
| def getSynPermBelowStimulusInc(self):
| return self._synPermBelowStimulusInc
|
'Sets the permanence increment amount for columns that have not been
recently active.
:param synPermBelowStimulusInc: (float) value to set.'
| def setSynPermBelowStimulusInc(self, synPermBelowStimulusInc):
| self._synPermBelowStimulusInc = synPermBelowStimulusInc
|
':returns: (float) the permanence amount that qualifies a synapse as being
connected.'
| def getSynPermConnected(self):
| return self._synPermConnected
|
'Sets the permanence amount that qualifies a synapse as being
connected.
:param synPermConnected: (float) value to set.'
| def setSynPermConnected(self, synPermConnected):
| self._synPermConnected = synPermConnected
|
':returns: (float) the minimum tolerated overlaps, given as percent of
neighbors overlap score'
| def getMinPctOverlapDutyCycles(self):
| return self._minPctOverlapDutyCycles
|
'Sets the minimum tolerated activity duty cycle, given as percent of
neighbors\' activity duty cycle.
:param minPctOverlapDutyCycles: (float) value to set.'
| def setMinPctOverlapDutyCycles(self, minPctOverlapDutyCycles):
| self._minPctOverlapDutyCycles = minPctOverlapDutyCycles
|
'Gets the boost factors for all columns. Input list will be overwritten.
:param boostFactors: (list) size must match number of columns.'
| def getBoostFactors(self, boostFactors):
| boostFactors[:] = self._boostFactors[:]
|
'Sets the boost factors for all columns. ``boostFactors`` size must match
the number of columns.
:param boostFactors: (iter) value to set.'
| def setBoostFactors(self, boostFactors):
| self._boostFactors[:] = boostFactors[:]
|
'Gets the overlap duty cycles for all columns. ``overlapDutyCycles``
size must match the number of columns.
:param overlapDutyCycles: (list) will be overwritten.'
| def getOverlapDutyCycles(self, overlapDutyCycles):
| overlapDutyCycles[:] = self._overlapDutyCycles[:]
|
'Sets the overlap duty cycles for all columns. ``overlapDutyCycles``
size must match the number of columns.
:param overlapDutyCycles: (list) value to set.'
| def setOverlapDutyCycles(self, overlapDutyCycles):
| self._overlapDutyCycles[:] = overlapDutyCycles
|
'Gets the activity duty cycles for all columns. Input list will be
overwritten.
:param activeDutyCycles: (list) size must match number of columns.'
| def getActiveDutyCycles(self, activeDutyCycles):
| activeDutyCycles[:] = self._activeDutyCycles[:]
|
'Sets the activity duty cycles for all columns. ``activeDutyCycles`` size
must match the number of columns.
:param activeDutyCycles: (list) value to set.'
| def setActiveDutyCycles(self, activeDutyCycles):
| self._activeDutyCycles[:] = activeDutyCycles
|
':returns: (list) the minimum overlap duty cycles for all columns.
``minOverlapDutyCycles`` size must match the number of columns.'
| def getMinOverlapDutyCycles(self, minOverlapDutyCycles):
| minOverlapDutyCycles[:] = self._minOverlapDutyCycles[:]
|
'Sets the minimum overlap duty cycles for all columns.
``minOverlapDutyCycles`` size must match the number of columns.
:param minOverlapDutyCycles: (iter) value to set.'
| def setMinOverlapDutyCycles(self, minOverlapDutyCycles):
| self._minOverlapDutyCycles[:] = minOverlapDutyCycles[:]
|
':param columnIndex: (int) column index to get potential for.
:param potential: (list) will be overwritten with column potentials. Must
match the number of inputs.'
| def getPotential(self, columnIndex, potential):
| assert (columnIndex < self._numColumns)
potential[:] = self._potentialPools[columnIndex]
|
'Sets the potential mapping for a given column. ``potential`` size must match
the number of inputs, and must be greater than ``stimulusThreshold``.
:param columnIndex: (int) column index to set potential for.
:param potential: (list) value to set.'
| def setPotential(self, columnIndex, potential):
| assert (columnIndex < self._numColumns)
potentialSparse = numpy.where((potential > 0))[0]
if (len(potentialSparse) < self._stimulusThreshold):
raise Exception((('This is likely due to a ' + 'value of stimulusThreshold that is too large relative ') + 'to t... |
'Returns the permanence values for a given column. ``permanence`` size
must match the number of inputs.
:param columnIndex: (int) column index to get permanence for.
:param permanence: (list) will be overwritten with permanences.'
| def getPermanence(self, columnIndex, permanence):
| assert (columnIndex < self._numColumns)
permanence[:] = self._permanences[columnIndex]
|
'Sets the permanence values for a given column. ``permanence`` size must
match the number of inputs.
:param columnIndex: (int) column index to set permanence for.
:param permanence: (list) value to set.'
| def setPermanence(self, columnIndex, permanence):
| assert (columnIndex < self._numColumns)
self._updatePermanencesForColumn(permanence, columnIndex, raisePerm=False)
|
':param connectedSynapses: (list) will be overwritten
:returns: (iter) the connected synapses for a given column.
``connectedSynapses`` size must match the number of inputs'
| def getConnectedSynapses(self, columnIndex, connectedSynapses):
| assert (columnIndex < self._numColumns)
connectedSynapses[:] = self._connectedSynapses[columnIndex]
|
':param connectedCounts: (list) will be overwritten
:returns: (int) the number of connected synapses for all columns.
``connectedCounts`` size must match the number of columns.'
| def getConnectedCounts(self, connectedCounts):
| connectedCounts[:] = self._connectedCounts[:]
|
':returns: (iter) the overlap score for each column.'
| def getOverlaps(self):
| return self._overlaps
|
':returns: (list) the boosted overlap score for each column.'
| def getBoostedOverlaps(self):
| return self._boostedOverlaps
|
'This is the primary public method of the SpatialPooler class. This
function takes a input vector and outputs the indices of the active columns.
If \'learn\' is set to True, this method also updates the permanences of the
columns.
:param inputVector: A numpy array of 0\'s and 1\'s that comprises the input
to the spatia... | def compute(self, inputVector, learn, activeArray):
| if (not isinstance(inputVector, numpy.ndarray)):
raise TypeError(('Input vector must be a numpy array, not %s' % str(type(inputVector))))
if (inputVector.size != self._numInputs):
raise ValueError(("Input vector dimensions don't match. Expecting %s bu... |
'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. This should not be done when using a random, unlearned SP
since you would end up with no acti... | def stripUnlearnedColumns(self, activeArray):
| neverLearned = numpy.where((self._activeDutyCycles == 0))[0]
activeArray[neverLearned] = 0
|
'Updates the minimum duty cycles defining normal activity for a column. A
column with activity duty cycle below this minimum threshold is boosted.'
| def _updateMinDutyCycles(self):
| if (self._globalInhibition or (self._inhibitionRadius > self._numInputs)):
self._updateMinDutyCyclesGlobal()
else:
self._updateMinDutyCyclesLocal()
|
'Updates the minimum duty cycles in a global fashion. Sets the minimum duty
cycles for the overlap all columns to be a percent of the maximum in the
region, specified by minPctOverlapDutyCycle. Functionality it is equivalent
to _updateMinDutyCyclesLocal, but this function exploits the globality of
the computation to pe... | def _updateMinDutyCyclesGlobal(self):
| self._minOverlapDutyCycles.fill((self._minPctOverlapDutyCycles * self._overlapDutyCycles.max()))
|
'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
_updateMinDutyCyclesGlobal, here the values can be quite different for
different columns.'
| def _updateMinDutyCyclesLocal(self):
| for column in xrange(self._numColumns):
neighborhood = self._getColumnNeighborhood(column)
maxActiveDuty = self._activeDutyCycles[neighborhood].max()
maxOverlapDuty = self._overlapDutyCycles[neighborhood].max()
self._minOverlapDutyCycles[column] = (maxOverlapDuty * self._minPctOverla... |
'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.
Parameters:
:param overlaps:
An array containing the overlap score for each col... | def _updateDutyCycles(self, overlaps, activeColumns):
| overlapArray = numpy.zeros(self._numColumns, dtype=realDType)
activeArray = numpy.zeros(self._numColumns, dtype=realDType)
overlapArray[(overlaps > 0)] = 1
activeArray[activeColumns] = 1
period = self._dutyCyclePeriod
if (period > self._iterationNum):
period = self._iterationNum
self... |
'Update the inhibition radius. The inhibition radius is a measure of the
square (or hypersquare) of columns that each a column is "connected to"
on average. Since columns are 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 m... | def _updateInhibitionRadius(self):
| if self._globalInhibition:
self._inhibitionRadius = int(self._columnDimensions.max())
return
avgConnectedSpan = numpy.average([self._avgConnectedSpanForColumnND(i) for i in xrange(self._numColumns)])
columnsPerInput = self._avgColumnsPerInput()
diameter = (avgConnectedSpan * columnsPerIn... |
'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, o... | def _avgColumnsPerInput(self):
| numDim = max(self._columnDimensions.size, self._inputDimensions.size)
colDim = numpy.ones(numDim)
colDim[:self._columnDimensions.size] = self._columnDimensions
inputDim = numpy.ones(numDim)
inputDim[:self._inputDimensions.size] = self._inputDimensions
columnsPerInput = (colDim.astype(realDType) ... |
'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 topology.
Parameters:
:param columnIndex: The index identifying a column in the permanence,
potential and connectivity matrices'
| def _avgConnectedSpanForColumn1D(self, columnIndex):
| assert (self._inputDimensions.size == 1)
connected = self._connectedSynapses[columnIndex].nonzero()[0]
if (connected.size == 0):
return 0
else:
return ((max(connected) - min(connected)) + 1)
|
'The range of connectedSynapses per column, averaged for each dimension.
This value is used to calculate the inhibition radius. This variation of
the function only supports a 2 dimensional column topology.
Parameters:
:param columnIndex: The index identifying a column in the permanence,
potential and connectivity ma... | def _avgConnectedSpanForColumn2D(self, columnIndex):
| assert (self._inputDimensions.size == 2)
connected = self._connectedSynapses[columnIndex]
(rows, cols) = connected.reshape(self._inputDimensions).nonzero()
if ((rows.size == 0) and (cols.size == 0)):
return 0
rowSpan = ((rows.max() - rows.min()) + 1)
colSpan = ((cols.max() - cols.min()) ... |
'The range of connectedSynapses per column, averaged for each dimension.
This value is used to calculate the inhibition radius. This variation of
the function supports arbitrary column dimensions.
Parameters:
:param index: The index identifying a column in the permanence, potential
and connectivity matrices.'
| def _avgConnectedSpanForColumnND(self, columnIndex):
| dimensions = self._inputDimensions
connected = self._connectedSynapses[columnIndex].nonzero()[0]
if (connected.size == 0):
return 0
maxCoord = numpy.empty(self._inputDimensions.size)
minCoord = numpy.empty(self._inputDimensions.size)
maxCoord.fill((-1))
minCoord.fill(max(self._inputD... |
'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 o... | def _adaptSynapses(self, inputVector, activeColumns):
| inputIndices = numpy.where((inputVector > 0))[0]
permChanges = numpy.zeros(self._numInputs, dtype=realDType)
permChanges.fill(((-1) * self._synPermInactiveDec))
permChanges[inputIndices] = self._synPermActiveInc
for columnIndex in activeColumns:
perm = self._permanences[columnIndex]
... |
'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.'
| def _bumpUpWeakColumns(self):
| weakColumns = numpy.where((self._overlapDutyCycles < self._minOverlapDutyCycles))[0]
for columnIndex in weakColumns:
perm = self._permanences[columnIndex].astype(realDType)
maskPotential = numpy.where((self._potentialPools[columnIndex] > 0))[0]
perm[maskPotential] += self._synPermBelowSt... |
'This method ensures that each column has enough connections to input bits
to allow it to become active. Since a column must have at least
\'self._stimulusThreshold\' overlaps in order to be considered during the
inhibition phase, columns without such minimal number of connections, even
if all the input bits they are c... | def _raisePermanenceToThreshold(self, perm, mask):
| if (len(mask) < self._stimulusThreshold):
raise Exception((('This is likely due to a ' + 'value of stimulusThreshold that is too large relative ') + 'to the input size. [len(mask) < self._stimulusThreshold]'))
numpy.clip(perm, self._synPermMin,... |
'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
array containing all the zeros as well as the non-zero values. It is in
charge of implementing \'clip... | def _updatePermanencesForColumn(self, perm, columnIndex, raisePerm=True):
| maskPotential = numpy.where((self._potentialPools[columnIndex] > 0))[0]
if raisePerm:
self._raisePermanenceToThreshold(perm, maskPotential)
perm[(perm < self._synPermTrimThreshold)] = 0
numpy.clip(perm, self._synPermMin, self._synPermMax, out=perm)
newConnected = numpy.where((perm >= (self._... |
'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 o... | def _initPermConnected(self):
| p = (self._synPermConnected + ((self._synPermMax - self._synPermConnected) * self._random.getReal64()))
p = (int((p * 100000)) / 100000.0)
return p
|
'Returns a randomly generated permanence value for a synapses that is to be
initialized in a non-connected state.'
| def _initPermNonConnected(self):
| p = (self._synPermConnected * self._random.getReal64())
p = (int((p * 100000)) / 100000.0)
return p
|
'Initializes the permanences of a column. The method
returns a 1-D 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.
Parameters:
:param potential: A numpy a... | def _initPermanence(self, potential, connectedPct):
| perm = numpy.zeros(self._numInputs, dtype=realDType)
for i in xrange(self._numInputs):
if (potential[i] < 1):
continue
if (self._random.getReal64() <= connectedPct):
perm[i] = self._initPermConnected()
else:
perm[i] = self._initPermNonConnected()
p... |
'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 v... | def _mapColumn(self, index):
| columnCoords = numpy.unravel_index(index, self._columnDimensions)
columnCoords = numpy.array(columnCoords, dtype=realDType)
ratios = (columnCoords / self._columnDimensions)
inputCoords = (self._inputDimensions * ratios)
inputCoords += ((0.5 * self._inputDimensions) / self._columnDimensions)
inpu... |
'Maps a column to its input bits. This method encapsulates 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 cu... | def _mapPotential(self, index):
| centerInput = self._mapColumn(index)
columnInputs = self._getInputNeighborhood(centerInput).astype(uintType)
numPotential = int(((columnInputs.size * self._potentialPct) + 0.5))
selectedInputs = numpy.empty(numPotential, dtype=uintType)
self._random.sample(columnInputs, selectedInputs)
potential... |
'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... | @staticmethod
def _updateDutyCyclesHelper(dutyCycles, newInput, period):
| assert (period >= 1)
return (((dutyCycles * (period - 1.0)) + newInput) / period)
|
'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. The boosting function is a curve defined as:
boostFactors = exp[ - boostStrength * (du... | def _updateBoostFactors(self):
| if self._globalInhibition:
self._updateBoostFactorsGlobal()
else:
self._updateBoostFactorsLocal()
|
'Update boost factors when global inhibition is used'
| def _updateBoostFactorsGlobal(self):
| if (self._localAreaDensity > 0):
targetDensity = self._localAreaDensity
else:
inhibitionArea = (((2 * self._inhibitionRadius) + 1) ** self._columnDimensions.size)
inhibitionArea = min(self._numColumns, inhibitionArea)
targetDensity = (float(self._numActiveColumnsPerInhArea) / inh... |
'Update boost factors when local inhibition is used'
| def _updateBoostFactorsLocal(self):
| targetDensity = numpy.zeros(self._numColumns, dtype=realDType)
for i in xrange(self._numColumns):
maskNeighbors = self._getColumnNeighborhood(i)
targetDensity[i] = numpy.mean(self._activeDutyCycles[maskNeighbors])
self._boostFactors = numpy.exp(((targetDensity - self._activeDutyCycles) * sel... |
'Updates counter instance variables each round.
Parameters:
:param 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 separa... | def _updateBookeepingVars(self, learn):
| self._iterationNum += 1
if learn:
self._iterationLearnNum += 1
|
'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 (permanence value is greater than \'_synPermConnected\')
to input bits which are turned on. The implementation takes advantage of
the SparseBinaryMatrix cl... | def _calculateOverlap(self, inputVector):
| overlaps = numpy.zeros(self._numColumns, dtype=realDType)
self._connectedSynapses.rightVecSumAtNZ_fast(inputVector.astype(realDType), overlaps)
return overlaps
|
'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.
Parameters:
:param overlaps: an array containing the overlap score for each column.
The overlap score for a column is defined as the num... | def _inhibitColumns(self, overlaps):
| if (self._localAreaDensity > 0):
density = self._localAreaDensity
else:
inhibitionArea = (((2 * self._inhibitionRadius) + 1) ** self._columnDimensions.size)
inhibitionArea = min(self._numColumns, inhibitionArea)
density = (float(self._numActiveColumnsPerInhArea) / inhibitionArea)... |
'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. Columns with an overlap score below the \'stimulusThreshold\' are
always inhibited.
:p... | def _inhibitColumnsGlobal(self, overlaps, density):
| numActive = int((density * self._numColumns))
sortedWinnerIndices = numpy.argsort(overlaps, kind='mergesort')
start = (len(sortedWinnerIndices) - numActive)
while (start < len(sortedWinnerIndices)):
i = sortedWinnerIndices[start]
if (overlaps[i] >= self._stimulusThreshold):
b... |
'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. Columns ... | def _inhibitColumnsLocal(self, overlaps, density):
| activeArray = numpy.zeros(self._numColumns, dtype='bool')
for (column, overlap) in enumerate(overlaps):
if (overlap >= self._stimulusThreshold):
neighborhood = self._getColumnNeighborhood(column)
neighborhoodOverlaps = overlaps[neighborhood]
numBigger = numpy.count_no... |
'returns true if enough rounds have passed to warrant updates of
duty cycles'
| def _isUpdateRound(self):
| return ((self._iterationNum % self._updatePeriod) == 0)
|
'Gets a neighborhood of columns.
Simply calls topology.neighborhood or topology.wrappingNeighborhood
A subclass can insert different topology behavior by overriding this method.
:param centerColumn (int)
The center of the neighborhood.
@returns (1D numpy array of integers)
The columns in the neighborhood.'
| def _getColumnNeighborhood(self, centerColumn):
| if self._wrapAround:
return topology.wrappingNeighborhood(centerColumn, self._inhibitionRadius, self._columnDimensions)
else:
return topology.neighborhood(centerColumn, self._inhibitionRadius, self._columnDimensions)
|
'Gets a neighborhood of inputs.
Simply calls topology.wrappingNeighborhood or topology.neighborhood.
A subclass can insert different topology behavior by overriding this method.
:param centerInput (int)
The center of the neighborhood.
@returns (1D numpy array of integers)
The inputs in the neighborhood.'
| def _getInputNeighborhood(self, centerInput):
| if self._wrapAround:
return topology.wrappingNeighborhood(centerInput, self._potentialRadius, self._inputDimensions)
else:
return topology.neighborhood(centerInput, self._potentialRadius, self._inputDimensions)
|
'Initialize the random seed'
| def _seed(self, seed=(-1)):
| if (seed != (-1)):
self._random = NupicRandom(seed)
else:
self._random = NupicRandom()
|
'Initialize class properties from stored values.'
| def __setstate__(self, state):
| if (state['_version'] < 2):
state['_wrapAround'] = True
if (state['_version'] < 3):
state['_overlaps'] = numpy.zeros(self._numColumns, dtype=realDType)
state['_boostedOverlaps'] = numpy.zeros(self._numColumns, dtype=realDType)
state['_version'] = VERSION
self.__dict__.update(stat... |
'Useful for debugging.'
| def printParameters(self):
| print '------------PY SpatialPooler Parameters ------------------'
print 'numInputs = ', self.getNumInputs()
print 'numColumns = ', self.getNumColumns(... |
'NOTE: Anomaly likelihood scores are reported at a flat 0.5 for
learningPeriod + estimationSamples iterations.
claLearningPeriod and learningPeriod are specifying the same variable,
although claLearningPeriod is a deprecated name for it.
:param learningPeriod: (claLearningPeriod: deprecated) - (int) the number of
itera... | def __init__(self, claLearningPeriod=None, learningPeriod=288, estimationSamples=100, historicWindowSize=8640, reestimationPeriod=100):
| if (historicWindowSize < estimationSamples):
raise ValueError('estimationSamples exceeds historicWindowSize')
self._iteration = 0
self._historicalScores = collections.deque(maxlen=historicWindowSize)
self._distribution = None
if (claLearningPeriod != None):
print 'claLearningPe... |
'Compute a log scale representation of the likelihood value. Since the
likelihood computations return low probabilities that often go into four 9\'s
or five 9\'s, a log value is more useful for visualization, thresholding,
etc.'
| @staticmethod
def computeLogLikelihood(likelihood):
| return (math.log((1.0000000001 - likelihood)) / (-23.02585084720009))
|
'Return the value of skipRecords for passing to estimateAnomalyLikelihoods
If `windowSize` is very large (bigger than the amount of data) then this
could just return `learningPeriod`. But when some values have fallen out of
the historical sliding window of anomaly records, then we have to take those
into account as wel... | @staticmethod
def _calcSkipRecords(numIngested, windowSize, learningPeriod):
| numShiftedOut = max(0, (numIngested - windowSize))
return min(numIngested, max(0, (learningPeriod - numShiftedOut)))
|
'capnp deserialization method for the anomaly likelihood object
:param proto: (Object) capnp proto object specified in
nupic.regions.AnomalyLikelihoodRegion.capnp
:returns: (Object) the deserialized AnomalyLikelihood object'
| @classmethod
def read(cls, proto):
| anomalyLikelihood = object.__new__(cls)
anomalyLikelihood._iteration = proto.iteration
anomalyLikelihood._historicalScores = collections.deque(maxlen=proto.historicWindowSize)
for (i, score) in enumerate(proto.historicalScores):
anomalyLikelihood._historicalScores.append((i, score.value, score.a... |
'capnp serialization method for the anomaly likelihood object
:param proto: (Object) capnp proto object specified in
nupic.regions.AnomalyLikelihoodRegion.capnp'
| def write(self, proto):
| proto.iteration = self._iteration
pHistScores = proto.init('historicalScores', len(self._historicalScores))
for (i, score) in enumerate(list(self._historicalScores)):
(_, value, anomalyScore) = score
record = pHistScores[i]
record.value = float(value)
record.anomalyScore = fl... |
'Compute the probability that the current value plus anomaly score represents
an anomaly given the historical distribution of anomaly scores. The closer
the number is to 1, the higher the chance it is an anomaly.
:param value: the current metric ("raw") input value, eg. "orange", or
\'21.2\' (deg. Celsius), ...
:param ... | def anomalyProbability(self, value, anomalyScore, timestamp=None):
| if (timestamp is None):
timestamp = self._iteration
dataPoint = (timestamp, value, anomalyScore)
if (self._iteration < self._probationaryPeriod):
likelihood = 0.5
else:
if ((self._distribution is None) or ((self._iteration % self._reestimationPeriod) == 0)):
numSkipRe... |
'@param monitor (MonitorMixinBase) Monitor Mixin instance that generated
this trace
@param title (string) Title'
| def __init__(self, monitor, title):
| self.monitor = monitor
self.title = title
self.data = []
|
'@param datum (object) Datum from `self.data` to pretty-print
@return (string) Pretty-printed datum'
| @staticmethod
def prettyPrintDatum(datum):
| return (str(datum) if (datum is not None) else '')
|
'@return (CountsTrace) A new Trace made up of counts of this trace\'s indices.'
| def makeCountsTrace(self):
| trace = CountsTrace(self.monitor, '# {0}'.format(self.title))
trace.data = [len(indices) for indices in self.data]
return trace
|
'@return (CountsTrace) A new Trace made up of cumulative counts of this
trace\'s indices.'
| def makeCumCountsTrace(self):
| trace = CountsTrace(self.monitor, '# (cumulative) {0}'.format(self.title))
countsTrace = self.makeCountsTrace()
def accumulate(iterator):
total = 0
for item in iterator:
total += item
(yield total)
trace.data = list(accumulate(countsTrace.data))
return t... |
'@return (Trace) Trace of active columns'
| def mmGetTraceActiveColumns(self):
| return self._mmTraces['activeColumns']
|
'@return (Trace) Trace of predictive cells'
| def mmGetTracePredictiveCells(self):
| return self._mmTraces['predictiveCells']
|
'@return (Trace) Trace of # segments'
| def mmGetTraceNumSegments(self):
| return self._mmTraces['numSegments']
|
'@return (Trace) Trace of # synapses'
| def mmGetTraceNumSynapses(self):
| return self._mmTraces['numSynapses']
|
'@return (Trace) Trace of sequence labels'
| def mmGetTraceSequenceLabels(self):
| return self._mmTraces['sequenceLabels']
|
'@return (Trace) Trace of resets'
| def mmGetTraceResets(self):
| return self._mmTraces['resets']
|
'@return (Trace) Trace of predicted => active cells'
| def mmGetTracePredictedActiveCells(self):
| self._mmComputeTransitionTraces()
return self._mmTraces['predictedActiveCells']
|
'@return (Trace) Trace of predicted => inactive cells'
| def mmGetTracePredictedInactiveCells(self):
| self._mmComputeTransitionTraces()
return self._mmTraces['predictedInactiveCells']
|
'@return (Trace) Trace of predicted => active columns'
| def mmGetTracePredictedActiveColumns(self):
| self._mmComputeTransitionTraces()
return self._mmTraces['predictedActiveColumns']
|
'@return (Trace) Trace of predicted => inactive columns'
| def mmGetTracePredictedInactiveColumns(self):
| self._mmComputeTransitionTraces()
return self._mmTraces['predictedInactiveColumns']
|
'@return (Trace) Trace of unpredicted => active columns'
| def mmGetTraceUnpredictedActiveColumns(self):
| self._mmComputeTransitionTraces()
return self._mmTraces['unpredictedActiveColumns']
|
'Convenience method to compute a metric over an indices trace, excluding
resets.
@param (IndicesTrace) Trace of indices
@return (Metric) Metric over trace excluding resets'
| def mmGetMetricFromTrace(self, trace):
| return Metric.createFromTrace(trace.makeCountsTrace(), excludeResets=self.mmGetTraceResets())
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.