Skip to content

Commit 84e04b0

Browse files
committed
Fixed incorrect performance optimization, that was losing valid data.
1 parent b1088e6 commit 84e04b0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

py/htm/advanced/algorithms/location_modules.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def movementCompute(self, displacement, noiseFactor = 0):
139139

140140
self._computeActiveCells()
141141
self.phaseDisplacement = phaseDisplacement
142+
self.sensoryAssociatedCells = np.empty(0, dtype="int") # This set by sensoryCompute.
142143

143144
@abstractmethod
144145
def _sensoryComputeInferenceMode(self, anchorInput):
@@ -166,18 +167,18 @@ def _sensoryComputeLearningMode(self, anchorInput):
166167

167168
# Cells with a active segment: reinforce the segment
168169
cellsForActiveSegments = self.connections.mapSegmentsToCells(activeSegments)
169-
learningActiveSegments = activeSegments[np.in1d(cellsForActiveSegments, self.getLearnableCells(), assume_unique=True)]
170-
remainingCells = np.setdiff1d(self.getLearnableCells(), cellsForActiveSegments, assume_unique=True)
170+
learningActiveSegments = activeSegments[np.in1d(cellsForActiveSegments, self.getLearnableCells())]
171+
remainingCells = np.setdiff1d(self.getLearnableCells(), cellsForActiveSegments)
171172

172173
# Remaining cells with a matching segment: reinforce the best
173174
# matching segment.
174175
candidateSegments = self.connections.filterSegmentsByCell(matchingSegments, remainingCells)
175176
cellsForCandidateSegments = (self.connections.mapSegmentsToCells(candidateSegments))
176-
candidateSegments = candidateSegments[np.in1d(cellsForCandidateSegments, remainingCells, assume_unique=True)]
177+
candidateSegments = candidateSegments[np.in1d(cellsForCandidateSegments, remainingCells)]
177178
onePerCellFilter = np2.argmaxMulti(potentialOverlaps[candidateSegments], cellsForCandidateSegments)
178179
learningMatchingSegments = candidateSegments[onePerCellFilter]
179180

180-
newSegmentCells = np.setdiff1d(remainingCells, cellsForCandidateSegments, assume_unique=True)
181+
newSegmentCells = np.setdiff1d(remainingCells, cellsForCandidateSegments)
181182

182183
for learningSegments in (learningActiveSegments, learningMatchingSegments):
183184
self._learn(learningSegments, anchorInput, potentialOverlaps)
@@ -242,7 +243,7 @@ def _learnOnNewSegments(self, newSegmentCells, growthCandidates):
242243
if self.maxSynapsesPerSegment != -1:
243244
numNewSynapses = min(numNewSynapses, self.maxSynapsesPerSegment)
244245

245-
for cell in newSegmentCells:
246+
for cell in newSegmentCells:
246247
newSegment = self.connections.createSegment(cell, self.maxSegmentsPerCell)
247248
self.connections.growSynapses(newSegment, growthCandidates.sparse, self.initialPermanence, self.rng, numNewSynapses)
248249

@@ -722,8 +723,7 @@ def activateRandomLocation(self):
722723
self.bumpPhases = np.array([np.random.random(2)])
723724
if self.anchoringMethod == "discrete":
724725
# Need to place the phase in the middle of a cell
725-
self.bumpPhases = np.floor(
726-
self.bumpPhases * self.cellDimensions)/self.cellDimensions
726+
self.bumpPhases = np.floor(self.bumpPhases * self.cellDimensions)/self.cellDimensions
727727
self._computeActiveCells()
728728

729729
def _movementComputeDelta(self, displacement):
@@ -755,12 +755,12 @@ def _sensoryComputeInferenceMode(self, anchorInput):
755755

756756
sensorySupportedCells = np.unique(self.connections.mapSegmentsToCells(activeSegments))
757757

758-
inactivated = np.setdiff1d(self.activeCells, sensorySupportedCells, assume_unique=True)
759-
inactivatedIndices = np.in1d(self.cellsForActivePhases, inactivated, assume_unique=True).nonzero()[0]
758+
inactivated = np.setdiff1d(self.activeCells, sensorySupportedCells)
759+
inactivatedIndices = np.in1d(self.cellsForActivePhases, inactivated).nonzero()[0]
760760
if inactivatedIndices.size > 0:
761761
self.bumpPhases = np.delete(self.bumpPhases, inactivatedIndices, axis=0)
762762

763-
activated = np.setdiff1d(sensorySupportedCells, self.activeCells, assume_unique=True)
763+
activated = np.setdiff1d(sensorySupportedCells, self.activeCells)
764764

765765
# Find centers of point clouds
766766
if "corners" in self.anchoringMethod:

0 commit comments

Comments
 (0)