I have an error when I am trying to learn with SpatialPooler

Hello everybody.
I have the following error when I want to learn with SpatialPooler:

encoding = numpy.concatenate([catBits, geoBits])
activeColumns = numpy.zeros(spParams["columnCount"])
sp.compute(inputVector=encoding,learn=True, activeArray=activeColumns)
  spParams:
    columnCount: 2048
    spVerbosity: 0
    spatialImp: cpp
    globalInhibition: 1
    localAreaDensity: -1.0
    numActiveColumnsPerInhArea: 40
    seed: 1960
    potentialPct: 0.85
    synPermConnected: 0.1
    synPermActiveInc: 0.04
    synPermInactiveDec: 0.005
    boostStrength: 3.0
C:\Users\Mohammad Tahamtan\Miniconda2\python.exe" F:/nupic-master/nupic-master/examples/tahamtan/ex05/script.py
Traceback (most recent call last):
  File "F:/nupic-master/nupic-master/examples/tahamtan/ex05/script.py", line 125, in <module>
    sp.compute(inputVector=encoding,learn=True, activeArray=activeColumns)
  File "C:\Users\Mohammad Tahamtan\AppData\Roaming\Python\Python27\site-packages\nupic\algorithms\spatial_pooler.py", line 925, in compute
    self._adaptSynapses(inputVector, activeColumns)
  File "C:\Users\Mohammad Tahamtan\AppData\Roaming\Python\Python27\site-packages\nupic\algorithms\spatial_pooler.py", line 1171, in _adaptSynapses
    perm = self._permanences[columnIndex]
  File "C:\Users\Mohammad Tahamtan\AppData\Roaming\Python\Python27\site-packages\nupic\algorithms\spatial_pooler.py", line 64, in __getitem__
    return super(_SparseMatrixCorticalColumnAdapter, self).getRow(columnIndex)
  File "C:\Users\Mohammad Tahamtan\Miniconda2\lib\site-packages\nupic\bindings\math.py", line 4265, in getRow
    return _math._SparseMatrix32_getRow(self, *args, **kwargs)
TypeError: in method '_SparseMatrix32_getRow', argument 2 of type 'nupic::UInt32'

The first thing I would check is that the inputVector is in fact an array of 0s and 1s, and that it is the same dimensions as expected by the spatial pooler. A type error like this usually means something is wrong with the input.

1 Like

The input vector and the active array are ok. I double-checked these parametres.
When I change the learn bit to False, the spatial pooler works correctly!!!

Hello, dear Matt Taylor @rhyolight

Please check my code:

import numpy
from nupic.algorithms.spatial_pooler import SpatialPooler
from nupic.encoders.coordinate import CoordinateEncoder

CE = CoordinateEncoder(w=21, n=1024, name=None, verbosity=0)
encodingW = CE.getWidth()
SP = SpatialPooler(inputDimensions=(encodingW,),
                   columnDimensions=2048)

xy = [int(75),int(35)]

vector = numpy.array(xy)

x = CE.encode(inputData=(vector,5))

activeColumns = numpy.zeros(2048)

SP.compute(inputVector=x, learn=True, activeArray=activeColumns)

print activeColumns

I have the same error on this code

I think this is because I run this code on the windows.
I will install the nupic on Linux.

Problem solved, thank you
This problem just happened on windows.

1 Like