Python 3 Migration: encoder attribute

I’m working myself through the examples and I’m stuck in core_encoders_demo.py.
In the function createNetwork() we are creating two regions:

  # C++
  consumptionSensor = network.addRegion('consumptionSensor', 'ScalarSensor',
                                        json.dumps({'n': 120,
                                                    'w': 21,
                                                    'minValue': 0.0,
                                                    'maxValue': 100.0,
                                                    'clipInput': True}))

  # Python
  timestampSensor = network.addRegion("timestampSensor",
                                      'py.PluggableEncoderSensor', "")
  timestampSensor.getSelf().encoder = DateEncoder(timeOfDay=(21, 9.5),
                                                  name="timestamp_timeOfDay")

In timestampSensor.getSelf().encoder I’m referencing the “encoder”. Where is that defined?

I looked into /nupic/regions/pluggable_encoder_sensor.py and nupic/bindings/regions/PyRegion.py but I cannot find it.

The network.addRegion method returns a C++ region. The getSelf method returns the actual region class. In this case, it will be the PluggableEncoderSensor class which allows you to specify an arbitrary Python encoder.

Let me know if you have any other questions!

1 Like

@scott Thanks for your answer! This is my understanding as well. It now works on my side.

1 Like