@@ -522,6 +522,7 @@ void TemporalMemory::activateCells(const SDR &activeColumns, const bool learn) {
522522 segmentsValid_ = false ;
523523}
524524
525+
525526void TemporalMemory::activateDendrites (const bool learn,
526527 const SDR &extraActive,
527528 const SDR &extraWinners)
@@ -536,48 +537,24 @@ void TemporalMemory::activateDendrites(const bool learn,
536537 both.intersection (extraActive, extraWinners);
537538 NTA_ASSERT (both == extraWinners) << " ExtraWinners must be a subset of ExtraActive" ;
538539#endif
539- activateDendrites ( learn, extraActive.getSparse (),
540- extraWinners.getSparse ());
541540 }
542541 else
543542 {
544543 NTA_CHECK ( extraActive.getSum () == 0u && extraWinners.getSum () == 0u )
545544 << " External predictive inputs must be declared to TM constructor!" ;
546- activateDendrites (learn);
547545 }
548- }
549546
550- void TemporalMemory::activateDendrites (const bool learn,
551- const vector<UInt> &extraActive,
552- const vector<UInt> &extraWinners)
553- {
547+
554548 if ( segmentsValid_ )
555549 return ;
556550
557- // Handle external predictive inputs. extraActive & extraWinners default
558- // values are `vector({ SENTINEL })`
559- const auto SENTINEL = std::numeric_limits<UInt>::max ();
560- if ( extra_ )
561- {
562- NTA_CHECK ( extraActive.size () != 1 || extraActive[0 ] != SENTINEL )
563- << " TM.ActivateDendrites() missing argument extraActive!" ;
564- NTA_CHECK ( extraWinners.size () != 1 || extraWinners[0 ] != SENTINEL )
565- << " TM.ActivateDendrites() missing argument extraWinners!" ;
566-
567- for (const auto &active : extraActive) {
551+ for (const auto &active : extraActive.getSparse ()) {
568552 NTA_ASSERT ( active < extra_ );
569553 activeCells_.push_back ( static_cast <CellIdx>(active + numberOfCells ()) );
570- }
571- for (const auto &winner : extraWinners) {
554+ }
555+ for (const auto &winner : extraWinners. getSparse () ) {
572556 NTA_ASSERT ( winner < extra_ );
573557 winnerCells_.push_back ( static_cast <CellIdx>(winner + numberOfCells ()) );
574- }
575- }
576- else {
577- NTA_CHECK ( extraActive.size () == 1 && extraActive[0 ] == SENTINEL )
578- << " External predictive inputs must be declared to TM constructor!" ;
579- NTA_CHECK ( extraWinners.size () == 1 && extraWinners[0 ] == SENTINEL )
580- << " External predictive inputs must be declared to TM constructor!" ;
581558 }
582559
583560 const size_t length = connections.segmentFlatListLength ();
@@ -590,16 +567,13 @@ void TemporalMemory::activateDendrites(const bool learn,
590567
591568 // Active segments, connected synapses.
592569 activeSegments_.clear ();
593- for (Segment segment = 0 ;
594- segment < numActiveConnectedSynapsesForSegment_.size (); segment++) {
595- if (numActiveConnectedSynapsesForSegment_[segment] >=
596- activationThreshold_) {
570+ for (Segment segment = 0 ; segment < numActiveConnectedSynapsesForSegment_.size (); segment++) {
571+ if (numActiveConnectedSynapsesForSegment_[segment] >= activationThreshold_) {
597572 activeSegments_.push_back (segment);
598573 }
599574 }
600- std::sort (
601- activeSegments_.begin (), activeSegments_.end (),
602- [&](Segment a, Segment b) { return connections.compareSegments (a, b); });
575+ const auto compareSegments = [&](const Segment a, const Segment b) { return connections.compareSegments (a, b); };
576+ std::sort ( activeSegments_.begin (), activeSegments_.end (), compareSegments);
603577 // Update segment bookkeeping.
604578 if (learn) {
605579 for (const auto &segment : activeSegments_) {
@@ -610,19 +584,17 @@ void TemporalMemory::activateDendrites(const bool learn,
610584
611585 // Matching segments, potential synapses.
612586 matchingSegments_.clear ();
613- for (Segment segment = 0 ;
614- segment < numActivePotentialSynapsesForSegment_.size (); segment++) {
587+ for (Segment segment = 0 ; segment < numActivePotentialSynapsesForSegment_.size (); segment++) {
615588 if (numActivePotentialSynapsesForSegment_[segment] >= minThreshold_) {
616589 matchingSegments_.push_back (segment);
617590 }
618591 }
619- std::sort (
620- matchingSegments_.begin (), matchingSegments_.end (),
621- [&](Segment a, Segment b) { return connections.compareSegments (a, b); });
592+ std::sort ( matchingSegments_.begin (), matchingSegments_.end (), compareSegments);
622593
623594 segmentsValid_ = true ;
624595}
625596
597+
626598void TemporalMemory::compute (const SDR &activeColumns,
627599 const bool learn,
628600 const SDR &extraActive,
0 commit comments