@@ -176,6 +176,16 @@ void TMRegion::initialize() {
176176 args_.sequencePos = 0 ;
177177}
178178
179+
180+ bool TMRegion::isConnected_ (string name) const {
181+ const auto in = getInput (name);
182+ const auto out = getOutput (name);
183+ const bool hasOutput = (out != nullptr ) and out->hasOutgoingLinks ();
184+ const bool hasInput = (in != nullptr ) and in->hasIncomingLinks ();
185+ return hasInput or hasOutput;
186+ }
187+
188+
179189void TMRegion::compute () {
180190
181191 NTA_ASSERT (tm_) << " TM not initialized" ;
@@ -230,9 +240,11 @@ void TMRegion::compute() {
230240 //
231241 std::shared_ptr<Output> out;
232242 out = getOutput (" bottomUpOut" );
233- // set NTA_LOG_LEVEL = htm::LogLevel::LogLevel_Verbose
243+ // set
244+ NTA_LOG_LEVEL = htm::LogLevel::LogLevel_Verbose;
245+ NTA_CHECK (NTA_LOG_LEVEL == LogLevel::LogLevel_Verbose) << " setting Verbose failed, man" ;
234246 // to output the NTA_DEBUG statements below
235- if (out && out-> hasOutgoingLinks ( ) ) {
247+ if (isConnected_ ( " bottomUpOut " ) ) {
236248 SDR& sdr = out->getData ().getSDR ();
237249 tm_->getActiveCells (sdr); // active cells
238250 if (args_.orColumnOutputs ) { // output as columns
@@ -241,24 +253,24 @@ void TMRegion::compute() {
241253 NTA_DEBUG << " bottomUpOut " << *out << std::endl;
242254 }
243255 out = getOutput (" activeCells" );
244- if (out && out-> hasOutgoingLinks () ) {
256+ if (isConnected_ ( " activeCells " ) ) {
245257 tm_->getActiveCells (out->getData ().getSDR ());
246258 NTA_DEBUG << " active " << *out << std::endl;
247259 }
248260 out = getOutput (" predictedActiveCells" );
249- if (out && out-> hasOutgoingLinks ( ) ) {
261+ if (isConnected_ ( " predictedActiveCells " ) ) {
250262 tm_->activateDendrites ();
251263 tm_->getWinnerCells (out->getData ().getSDR ());
252264 NTA_DEBUG << " winners " << *out << std::endl;
253265 }
254266 out = getOutput (" anomaly" );
255- if (out && out-> hasOutgoingLinks ( ) ) {
267+ if (isConnected_ ( " anomaly " ) ) {
256268 Real32* buffer = reinterpret_cast <Real32*>(out->getData ().getBuffer ());
257- buffer[0 ] = tm_->anomaly ;
269+ buffer[0 ] = tm_->anomaly ; // only the first field is valid
258270 NTA_DEBUG << " anomaly " << *out << std::endl;
259271 }
260272 out = getOutput (" predictiveCells" );
261- if (out && out-> hasOutgoingLinks ( ) ) {
273+ if (isConnected_ ( " predictiveCells " ) ) {
262274 out->getData ().getSDR () = tm_->getPredictiveCells ();
263275 NTA_DEBUG << " predictive " << *out << std::endl;
264276 }
0 commit comments