0

Using the commits from breznak for the encoders (I wasn't able to figure out "git checkout ..." with GitHub, so I just carefully copied over the three files - base.py, multi.py, and multi_test.py).

I ran multi_test.py without any problems.

Then I adjusted my model parameters (MODEL_PARAMS), so that the encoders portion of 'sensorParams' looks like this:

'encoders': {
    'frequency': {
         'fieldname': u'frequency',
         'type': 'SimpleVector',
         'length': 5,                    
         'minVal': 0,
         'maxVal': 210
     }
 },

I also adjusted the modelInput portion of my code, so it looked like this:

model = ModelFactory.create(model_params.MODEL_PARAMS)
model.enableInference({'predictedField': 'frequency'})
y = [1,2,3,4,5]
modelInput = {"frequency": y}
result = model.run(modelInput)

But I get the final error, regardless if I instantiate 'y' as a list or a numpy.ndarray

File "nta/eng/lib/python2.7/site-packages/nupic/encoders/base.py", line 183, in _getInputValue
    return getattr(obj, fieldname)
AttributeError: 'list' object has no attribute 'idx0'

I also tried initializing a SimpleVector encoder inline with my modelInput, directly encoding my array, then passing it through modelInput. That violated the input parameters of my SimpleVector, because I was now double encoding. So I removed the encoders portion of my model parameters dictionary. That caused a spit up, because some part of my model was looking for that portion of the dictionary.

Any suggestions on what I should do next?

Edit: Here're the files I'm using with the OPF.

sendAnArray.py

import numpy
from nupic.frameworks.opf.modelfactory import ModelFactory    
import model_params

class sendAnArray():

def __init__(self):
    self.model = ModelFactory.create(model_params.MODEL_PARAMS)
    self.model.enableInference({'predictedField': 'frequency'})
    for i in range(100):
        self.run()

def run(self):
    y = [1,2,3,4,5]
    modelInput = {"frequency": y}
    result = self.model.run(modelInput)
    anomalyScore = result.inferences['anomalyScore']
    print y, anomalyScore

sAA = sendAnArray()

model_params.py

MODEL_PARAMS = {
    'model': "CLA",
    'version': 1,
    'predictAheadTime': None,
    'modelParams': {
        'inferenceType': 'TemporalAnomaly',
        'sensorParams': {
            'verbosity' : 0,
            'encoders': {
                'frequency': {
                    'fieldname': u'frequency',
                    'type': 'SimpleVector',
                    'length': 5,                    
                    'minVal': 0,
                    'maxVal': 210
                }
            },
            'sensorAutoReset' : None,
        },
        'spEnable': True,
        'spParams': {
            'spVerbosity' : 0,
            'globalInhibition': 1,
            'columnCount': 2048,
            'inputWidth': 5,
            'numActivePerInhArea': 60,
            'seed': 1956,
            'coincInputPoolPct': 0.5,
            'synPermConnected': 0.1,
            'synPermActiveInc': 0.1,
            'synPermInactiveDec': 0.01,
        },
        'tpEnable' : True,
        'tpParams': {
            'verbosity': 0,
            'columnCount': 2048,
            'cellsPerColumn': 32,
            'inputWidth': 2048,
            'seed': 1960,
            'temporalImp': 'cpp',
            'newSynapseCount': 20,
            'maxSynapsesPerSegment': 32,
            'maxSegmentsPerCell': 128,
            'initialPerm': 0.21,
            'permanenceInc': 0.1,
            'permanenceDec' : 0.1,
            'globalDecay': 0.0,
            'maxAge': 0,
            'minThreshold': 12,
            'activationThreshold': 16,
            'outputType': 'normal',
            'pamLength': 1,
        },
        'clParams': {
            'regionName' : 'CLAClassifierRegion',
            'clVerbosity' : 0,
            'alpha': 0.0001,
            'steps': '5',
        },
        'anomalyParams': {  
            u'anomalyCacheRecords': None,
            u'autoDetectThreshold': None,
            u'autoDetectWaitRecords': 2184
        },
        'trainSPNetOnlyIfRequested': False,
    },
}
tmacrina
  • 1
  • 3

2 Answers2

0

The problem seems to be that the SimpleVector class is accepting an array instead of a dict as its input, and then reconstructs that internally as {'list': {'idx0': 1, 'idx1': 2, ...}} (ie as if this dict had been the input). This is fine if it is done consistently, but your error shows that it's broken down somewhere. Have a word with @breznak about this.

Fergal Byrne
  • 135
  • 4
0

Working through the OPF was difficult. I wanted to input an array of indices into the temporal pooler, so I opted to interface directly with the algorithms (I relied heavy on hello_tp.py). I ignored SimpleVector all together, and instead worked through the BitmapArray encoder.

Subutai has a useful email on the nupic-discuss listserve, where he breaks down the three main areas of the NuPIC API: algorithms, networks/regions, & the OPF. That helped me understand my options better.

tmacrina
  • 1
  • 3