def _chooseBestSegmentPerCell(self, connections, cells, allMatchingSegments, potentialOverlaps): """ For each specified cell, choose its matching segment with largest number of active potential synapses. When there's a tie, the first segment wins. @param connections (SparseMatrixConnections) @param cells (numpy array) @param allMatchingSegments (numpy array) @param potentialOverlaps (numpy array) @return (numpy array) One segment per cell """ candidateSegments = connections.filterSegmentsByCell(allMatchingSegments, cells) # Narrow it down to one pair per cell. onePerCellFilter = np2.argmaxMulti(potentialOverlaps[candidateSegments], connections.mapSegmentsToCells(candidateSegments)) learningSegments = candidateSegments[onePerCellFilter] return learningSegments
def _sensoryComputeLearningMode(self, anchorInput): """ Associate this location with a sensory input. Subsequently, anchorInput will activate the current location during anchor(). @param anchorInput SDR A sensory input. This will often come from a feature-location pair layer. """ overlaps,potentialOverlaps = self.connections.computeActivityFull(anchorInput, False) activeSegments = np.flatnonzero(overlaps >= self.activationThreshold) matchingSegments = np.flatnonzero(potentialOverlaps >= self.learningThreshold) # Cells with a active segment: reinforce the segment cellsForActiveSegments = self.connections.mapSegmentsToCells(activeSegments) learningActiveSegments = activeSegments[np.in1d(cellsForActiveSegments, self.getLearnableCells(), assume_unique=True)] remainingCells = np.setdiff1d(self.getLearnableCells(), cellsForActiveSegments, assume_unique=True) # Remaining cells with a matching segment: reinforce the best # matching segment. candidateSegments = self.connections.filterSegmentsByCell(matchingSegments, remainingCells) cellsForCandidateSegments = (self.connections.mapSegmentsToCells(candidateSegments)) candidateSegments = candidateSegments[np.in1d(cellsForCandidateSegments, remainingCells, assume_unique=True)] onePerCellFilter = np2.argmaxMulti(potentialOverlaps[candidateSegments], cellsForCandidateSegments) learningMatchingSegments = candidateSegments[onePerCellFilter] newSegmentCells = np.setdiff1d(remainingCells, cellsForCandidateSegments, assume_unique=True) for learningSegments in (learningActiveSegments, learningMatchingSegments): self._learn(learningSegments, anchorInput, potentialOverlaps) # Remaining cells without a matching segment: grow one. self._learnOnNewSegments(newSegmentCells, anchorInput) self.activeSegments = activeSegments self.sensoryAssociatedCells = self.getLearnableCells()
def _chooseBestSegmentPerColumn(self, connections, matchingCells, allMatchingSegments, potentialOverlaps): """ For all the columns covered by 'matchingCells', choose the column's matching segment with largest number of active potential synapses. When there's a tie, the first segment wins. @param connections (SparseMatrixConnections) @param matchingCells (numpy array) @param allMatchingSegments (numpy array) @param potentialOverlaps (numpy array) """ candidateSegments = connections.filterSegmentsByCell( allMatchingSegments, matchingCells) # Narrow it down to one segment per column. cellScores = potentialOverlaps[candidateSegments] columnsForCandidates = ( connections.mapSegmentsToCells(candidateSegments) // self.cellsPerColumn) onePerColumnFilter = np2.argmaxMulti(cellScores, columnsForCandidates) learningSegments = candidateSegments[onePerColumnFilter] return learningSegments