Example usage of Coordinate Encoder

Hi @rhyolight, so I made my ‘runThroughNupic’ function like yours from mine-hack, though my kernel is dying when I try to run it, right after it prints:

“Creating model from %s…” % file_name

I tried running another Nupic file I have so I know its not my computer, and when I ran it piece by piece I ran into an error here in the ‘createModel(modelParams)’ function:

model = ModelFactory.create(modelParams)

I able to successfully import the modelParams dict, though when I try to create ‘model’ with the ModelFactory.create function I get this error:

logger = ModelFactory.__getLogger()

AttributeError: ‘NoneType’ object has no attribute ‘ModelFactory.__getLogger’

I remember you saying that we can’t get predictions when using the CoordinateEncoder, which is fine since I only need anomaly scores, though I’m guessing my code is still expecting there to be predictions. Do you think this might be the problem?

Can you paste the entire stacktrace? This error does not make any sense to me:

AttributeError: ‘NoneType’ object has no attribute ‘ModelFactory.__getLogger’

Of course, here it is:

model = ModelFactory.create(modelParams)

Traceback (most recent call last):

File "<ipython-input-28-3479c5734fd2>", line 1, in <module>
model = ModelFactory.create(modelParams)

File "/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/modelfactory.py", line 65, in create
logger = ModelFactory.__getLogger()

AttributeError: 'NoneType' object has no attribute '_ModelFactory__getLogger'

What version of nupic are you running? That error is strange because it refers to modelfactory.py, which was changed to model_factory.py recently. So you may not have the most recent installation.

I am on an old version yes, 0.5.6 apparently. I will be upgrading to the new one soon definitely, though do you think I have to in order to get around this issue? I’m just really curious to see how the results come out with this change, and I suspect that its something to do with the CoordinateEncoder, cause I tried another nupic run file that uses scalars from the same data and it worked fine.

What version of nupic.bindings do you have installed?

I’m embarrassed to say that I’m not sure how to check that :sweat_smile: Could you offer any directions there?

See the link in my comment above.

I’m puzzled by this discussion
I’m using nupic 1.0 and it appears that method _neighbors(coordinate, radius) is not implemented appropriately as it only operates on one axis.
I am also modifying the file coordinate.py in order to sort out inconsistencies with data types apparently required (dict,tuple or numpy array)
Have I missed something?

The _neighbors() code seems to work on N-dimensions of the coordinate to me, so I’m not sure what you mean:

ranges = (xrange(n-radius, n+radius+1) for n in coordinate.tolist())
return numpy.array(list(itertools.product(*ranges)))

Are you talking about this?

@param inputData (tuple) Contains coordinate (numpy.array, N-dimensional
                         integer coordinate) and radius (int)

So you need to pass something like this:

coords = [1,2,3,4,5]
radius = 4
coordinateEncoder.encodeIntoArray((coords, radius,))

Is this what is causing you trouble?

Ok, so my nupic version is: 0.5.5
nupic bindings version: 0.4.5

Do you think this could be the source of the problem?

Thanks again :slight_smile:

That version looks like the correct one. I’m not sure why there is a problem. I do suggest you install NuPIC at the latest version, but you’ll need to update your code for the breaking changes. There shouldn’t be that much to do in order to update.

I assume that’s the most reliable way to solve this and I should do it anyway. Would you recommend uninstalling my current nupic and nupic bindings first? If you’ve already done a walk through of that would you direct me to it? Thanks again!


Thank you for your prompt and helpful reply. - However
This works:

  inputData = { 'coordinate':[17,37], 'radius':4 }
  base = encoder.encode( inputData )
  print( base )

But this does not work!

  coords = [1,2,3,4,5]
  radius = 4
  base2 = encoder.encodeIntoArray((coords, radius,))
  TypeError: encodeIntoArray() takes exactly 3 arguments (2 given)

I think the problem may lie with my limited understanding of the use of python classes

Also on the topic of the coordinate encoder - Can you point me to any literature on plusses and minuses of different algorithms for encoding neighbors. I am aiming to experiment with anomaly detection in a sequence of coordinates where the sequence may be chaotic. The input is of the form [phi,rho] where both coordinate are in the range 0-2*pi.
I have a working modified coordinate.py which handle the wraparound.

Ok so I ran the uninstall commands for nupic and nupic bindings and got that message for both:

‘cannot uninstall requirement, not installed’

However when I then ran the command you showed me to check the version of nupic and nupic bindings, they still showed up as

nupic 0.5.5
nupic.bindings 0.4.5

Given this should I still just go ahead and

pip install nupic

to upgrade to 1.0?

Hmm when I try to run another nupic run file with a scalar encoder it still runs, so it seems like I haven’t uninstalled nupic then?

No it doesn’t seem like you have. Do you have virtual environments? Or more than one version of python?

I do have more than 1 version of python, yes. I switched the default do both python 2 and python 3 and ran the uninstall files, getting the ‘cannot uninstall requirements, not installed’ messages for both. I can try your other method, of:

rming the nupic.bindings-* files from your site-packages directory.

though I seem to have many site-package directories. Is there a certain file that would be in the right one that would help me pinpoint the right site-packages? I’m really sorry for this laborious hand-holding I’m making you do here :roll_eyes:

Find your site-packages folder(s) and search for any nupic.bindings files or directories. You may need to manually delete them.