Python 3 Migration: SP Overlay Test

This test is using a SpatialPooler to generate some data. Here is the call into nupic.core:

      onCells = numpy.zeros(columnDimensions)
      spImpl.compute(spInput, True, onCells)
      activeCoincIndices = set(onCells.nonzero()[0])

The onCells array is filled mostly with β€œ0.0” and if all values are zero the activeCoincIndices array would be empty. On python 3 that is the case whereas on python 2.7 there are some non zero values. The things is that all the non zero values are very small, I mean small as β€œ2.1219957909652723e-314”. I have checked:

      if(len([x for x in onCells if abs(x) > 0.00000000001]) > 0):
        print 'good values'

and onCells never seem to have anything useful in it. Is that a correct observation?

In any event, when there are only 0.0 in onCells the code will fault because of division by zero.

factor = max(summ)*len(summ)/sum(summ)

Is it correct to fix the test like this:

    if(len([x for x in summ if x!=0]) > 0):
      zeros = len([x for x in summ if x==0])
      factor = max(summ)*len(summ)/sum(summ)


Are you saying that in python 3 numpy.zeros() is returning arrays with non zero values?

No, the line

spImpl.compute(spInput, True, onCells)

is filling in the onCells array.

The issue here is that the non zero values are very very small. Like β€œ2.1219957909652723e-314”

Would you be able to debug that? I just like to know if you have reasonable values.

If you give me a link to the specific test I can try debugging in python2 and let you know if I see the same thing.

This is where the test starts:

After the first call of

spImpl.compute(spInput, True, onCells)

do you have any non zero values that are different to these β€œ2.1219957909652723e-314”?

I will help you with this and Python 3 Migration: Backtracking tests within the next week. I have some other things to do right away.

Please, take your time. I got plenty of other things to work on…

Thanks for your offer!

OK, I just saw there was a nupic bug fix from 2018/1/16 which is related to this issue. At least now the values make sense that are returned from the SpatialPooler compute().

This issue is closed. Using the correct numpy datatype solved the issue.

1 Like