Output crash / problem with PassthroughEncoders

Hey,

I am trying to set up a minimalistic bitmap prediction (roughly similar to ep10 of htm school).
My input is an array like so:

[
  	0, 1, 1, 1,
  	0, 1, 1, 0,
  	0, 1, 0, 0,
  	0, 1, 0, 1, 
  ]

However, I am getting the following error:

    RecordSensor got data: {'_sequenceId': 0, '_category': [None], 'data': [0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1], '_reset': 0}
    Traceback (most recent call last):
      File "run.py", line 162, in <module>
        runModel(plot=plot)
      File "run.py", line 152, in runModel
        runIoThroughNupic(inputData, model, PARAMS_NAME, plot)
      File "run.py", line 97, in runIoThroughNupic
        "data": data,
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/frameworks/opf/htm_prediction_model.py", line 429, in run
        self._sensorCompute(inputRecord)
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/frameworks/opf/htm_prediction_model.py", line 514, in _sensorCompute
        sensor.compute()
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/engine/__init__.py", line 433, in compute
        return self._region.compute()
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/bindings/engine_internal.py", line 1499, in compute
        return _engine_internal.Region_compute(self)
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/bindings/regions/PyRegion.py", line 184, in guardedCompute
        return self.compute(inputs, DictReadOnlyWrapper(outputs))
      File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/regions/record_sensor.py", line 405, in compute
        outputs["actValueOut"][:] = actualValue
    ValueError: cannot copy sequence with size 16 to array axis with dimension 1

I have the these model params:

    MODEL_PARAMS = \
    { 'aggregationInfo': { 'days': 0,
                           'fields': [],
                           'hours': 0,
                           'microseconds': 0,
                           'milliseconds': 0,
                           'minutes': 0,
                           'months': 0,
                           'seconds': 0,
                           'weeks': 0,
                           'years': 0},
      'model': 'HTMPrediction',
      'modelParams': { 'anomalyParams': { u'anomalyCacheRecords': None,
                                          u'autoDetectThreshold': None,
                                          u'autoDetectWaitRecords': None},
                       'clParams': { 'alpha': 0.0853123559090781,
                                     'regionName': 'SDRClassifierRegion',
                                     'steps': '1',
                                     'verbosity': 0},
                       'inferenceType': 'TemporalMultiStep',
                       'sensorParams': { 'encoders': { '_classifierInput': { 
                                                                            'classifierOnly': True,
                                                                            'fieldname': 'data',
                                                                            'n': 16,
                                                                            'name': '_classifierInput',
                                                                            'type': 'PassThroughEncoder',
                                                                            'w': 8,
                                                                            'forced': True,
                                                       },
                                                       u'data': {  
                                                                   'fieldname': 'data',
                                                                   'n': 16,
                                                                   'name': 'data',
                                                                   'type': 'PassThroughEncoder',
                                                                   'w': 8,
                                                                   'forced': True,
                                                       },
                                                    },
                                         'sensorAutoReset': None,
                                         'verbosity': 100},
                       'spEnable': True,
                       'spParams': { 'boostStrength': 0.0,
                                     'columnCount': 2048,
                                     'globalInhibition': 1,
                                     'inputWidth': 0,
                                     'numActiveColumnsPerInhArea': 40,
                                     'potentialPct': 0.8,
                                     'seed': 1956,
                                     'spVerbosity': 0,
                                     'spatialImp': 'cpp',
                                     'synPermActiveInc': 0.05,
                                     'synPermConnected': 0.1,
                                     'synPermInactiveDec': 0.01650662494024628},
                       'tmEnable': True,
                       'tmParams': { 'activationThreshold': 16,
                                     'cellsPerColumn': 32,
                                     'columnCount': 2048,
                                     'globalDecay': 0.0,
                                     'initialPerm': 0.21,
                                     'inputWidth': 2048,
                                     'maxAge': 0,
                                     'maxSegmentsPerCell': 128,
                                     'maxSynapsesPerSegment': 32,
                                     'minThreshold': 11,
                                     'newSynapseCount': 20,
                                     'outputType': 'normal',
                                     'pamLength': 1,
                                     'permanenceDec': 0.1,
                                     'permanenceInc': 0.1,
                                     'seed': 1960,
                                     'temporalImp': 'cpp',
                                     'verbosity': 0},
                       'trainSPNetOnlyIfRequested': False},
      'predictAheadTime': None,
      'version': 1}

It seems to me something is wrong with the sensorParams, but I cannot figure out what it is. I managed to get my code to run with a different encoder (e.g. SDRCategoryEncoder with a string input). Any pointers would be appreciated :slight_smile:

Edit: Looking at the source code, apparently my predicted field needs to be named ‘vector’. That’s a little odd, but it seems to do the job.
However, I am now getting a

        File "/Users/lukas/Library/Python/2.7/lib/python/site-packages/nupic/bindings/algorithms.py", line 3151, in convertedCompute
          return _algorithms.SDRClassifier_convertedCompute(self, *args, **kwargs)
      TypeError: in method 'SDRClassifier_convertedCompute', argument 4 of type 'std::vector< nupic::UInt > const &'

Edit 2: Okay, this one is solved by wrapping my array in a numpy.array. I think that’s it.

1 Like

I think you need this:

model.enableInference({"predictedField": "your_name"})

See the OPF Quick Start for more details.