The good news is that the following tests succeed:
The missing test “backtracking_tm_cpp2_test.py” doesn’t work right now and I have a hard time figuring out why that is. As far as I understand from comments in the source code python’s classes
BacktrackingTM should generate the same results at all times. But a simple test doesn’t work for me.
# Create cpp tm
tm = BacktrackingTMCPP(numberOfCols=10, cellsPerColumn=1, verbosity=VERBOSITY)
# Create Python tm from same characteristics
tmPy = BacktrackingTM(numberOfCols=tm.numberOfCols,
# Check if both tm's are equal
self.assertTrue(fdrutils.tmDiff2(tm, tmPy, VERBOSITY, False))
# Build up sequences
sequence = fdrutils.generateCoincMatrix(nCoinc=numPatterns, length=tm.numberOfCols, activity=activity)
sequence_row = sequence.getRow(0)
y1 = tm.learn(sequence_row)
y2 = tmPy.learn(sequence_row)
num_segments_cpp = tm.getNumSegments()
num_segments_py = tmPy.getNumSegments()
# fails since num_segments_cpp = 0 and num_segments_py = 1
self.assertTrue(num_segments_cpp = num_segments_py)
The complete source code is here
Can someone spot what is going wrong?
I think this would be the pure cpp version:
using namespace nupic;
using namespace nupic::algorithms::Cells4;
using namespace std;
UInt nColumns = 10;
UInt nCellsPerCol = 1;
UInt activationThreshold = 12;
UInt minThreshold = 8;
UInt newSynapseCount = 15;
UInt segUpdateValidDuration = 1;
Real permInitial = 0.11;
Real permConnected = 0.5;
Real permMax = 1.0;
Real permDec = 0.1;
Real permInc = 0.1;
Real globalDecay = 0.1;
bool doPooling = false;
UInt seed = 42;
bool initFromCpp = true;
bool checkSynapseConsistency = false;
vector<nupic::Real> input(10, 0.0);
input = 1.0;
vector<nupic::Real> output(10, 0.0);
c.compute(input.data(), output.data(), false, true);
auto num_segments = c.nSegments();
Again, the cpp version has 0 segments. Is that the correct answer? If so, would that mean that the python 3 code above is incorrect?
Sorry for the delay, I have been out sick.
When you say missing, what do you mean? Is the test excluded or commented out? Or is this a new test you are writing?
There are four backtracking tests in nupic.
Three of them run through and the fourth one “backtracking_tm_cpp2_test.py” is giving me some headache.
Is there a test in the current suite that compares the results from these two implementations? I do believe we have those. Am I correct in assuming that this is working in python2 but not python3?
Yes this test file is exactly doing that. It compares the states of BacktrackingTMCPP and BacktrackingTM after various computations. Since this test is part of the nupic unit test suite I assume it’s working for python 2.7 and it’s nupic.core implementation.
My problem is that I have a hard figuring out who is at fault here. Is it python 3 or is it my nupic.core which I have modified to use pybind11.
I have boiled down a test to a very small code sample, as displayed in my initial message.
How can I help? I can run the test in python 2 and tell you how many segments I get.
Matt, thanks for your offer!
I recently learned that I run and debug python code in different environments (2.7 or 3.6) in Visual Studio. It’s just a flip of switch, really. Very cool! So, I don’t really want to waste any time of yours and rather keep digging on my side.
If you don’t mind, would you be able to have look at this issue, instead?