@@ -190,9 +190,9 @@ void TemporalMemory::activatePredictedColumn_(
190190
191191
192192void TemporalMemory::burstColumn_ (
193- const UInt column,
194- vector<Segment>::const_iterator columnMatchingSegmentsBegin,
195- vector<Segment>::const_iterator columnMatchingSegmentsEnd,
193+ const UInt column,
194+ const vector<Segment>::const_iterator columnMatchingSegmentsBegin,
195+ const vector<Segment>::const_iterator columnMatchingSegmentsEnd,
196196 const SDR &prevActiveCells,
197197 const vector<CellIdx> &prevWinnerCells,
198198 const bool learn) {
@@ -208,19 +208,28 @@ void TemporalMemory::burstColumn_(
208208 numActivePotentialSynapsesForSegment_[b]);
209209 });
210210
211- const CellIdx winnerCell =
212- (bestMatchingSegment != columnMatchingSegmentsEnd)
213- ? connections.cellForSegment (*bestMatchingSegment)
214- : getLeastUsedCell_ (column); // TODO replace (with random?) this is extremely costly, removing makes TM 6x faster!
215-
211+ CellIdx winnerCell;
212+ if (bestMatchingSegment != columnMatchingSegmentsEnd) {
213+ winnerCell = connections.cellForSegment (*bestMatchingSegment);
214+ }
215+ else {
216+ // Check for previous winner cells in this minicolumn.
217+ const auto prevWinnerPtr = std::lower_bound (prevWinnerCells.begin (), prevWinnerCells.end (), column,
218+ [&](const CellIdx cell, const UInt col) { return columnForCell (cell) < col; });
219+ if (prevWinnerPtr != prevWinnerCells.end () && columnForCell (*prevWinnerPtr) == column) {
220+ winnerCell = *prevWinnerPtr;
221+ }
222+ else {
223+ winnerCell = getLeastUsedCell_ (column);
224+ }
225+ }
216226 winnerCells_.push_back (winnerCell);
217227
218- // Learn.
219228 if (learn) {
220229 if (bestMatchingSegment != columnMatchingSegmentsEnd) {
221230 // Learn on the best matching segment.
222231 connections_.adaptSegment (*bestMatchingSegment, prevActiveCells,
223- permanenceIncrement_, permanenceDecrement_, true , minThreshold_); // TODO consolidate SP.stimulusThreshold_ & TM.minThreshold_ into Conn.stimulusThreshold ? (replacing segmentThreshold arg used in some methods in Conn)
232+ permanenceIncrement_, permanenceDecrement_, true , minThreshold_);
224233
225234 const Int32 nGrowDesired = maxNewSynapseCount_ - numActivePotentialSynapsesForSegment_[*bestMatchingSegment];
226235 if (nGrowDesired > 0 ) {
0 commit comments