Skip to content

Commit 2149e83

Browse files
committed
WIP trying to fix linked regions in TMRegion
but not successful yet
1 parent 4560ce7 commit 2149e83

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

bindings/py/tests/regions/network_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ def testBuiltInRegions(self):
302302

303303
tm_output = tm.getOutputArray("predictedActiveCells")
304304
sdr = tm_output.getSDR()
305+
print(sdr.sparse)
306+
print(EXPECTED_RESULT3)
305307
self.assertTrue(np.array_equal(sdr.sparse, EXPECTED_RESULT3))
306308

307309
def testExecuteCommand1(self):

src/htm/regions/TMRegion.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
179189
void 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
}

src/htm/regions/TMRegion.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TMRegion : public RegionImpl, Serializable {
182182
Size iter;
183183
} args_;
184184

185-
185+
bool isConnected_(std::string name) const;
186186

187187
computeCallbackFunc computeCallback_;
188188
std::unique_ptr<TemporalMemory> tm_;

0 commit comments

Comments
 (0)