class nupic.regions.pluggable_encoder_sensor.PluggableEncoderSensor(**kwargs)

Bases: nupic.bindings.regions.PyRegion.PyRegion

Holds a value and encodes it into network output.

It requires you to reach in and insert an encoder:

timestampSensor = network.addRegion("timestampSensor",
                                  'py.PluggableEncoderSensor', "")
timestampSensor.getSelf().encoder = DateEncoder(timeOfDay=(21, 9.5),
Returns:sensed value
Parameters:value – will be encoded when this region does a compute.


class nupic.regions.record_sensor.RecordSensor(verbosity=0, numCategories=1)

Bases: nupic.bindings.regions.PyRegion.PyRegion

A Record Sensor (RS) retrieves an information “record” and encodes it to be suitable as input to an HTM.

An information record is analogous database record – it is just a collection of typed values: date, amount, category, location, etc.

The RS may obtain information from one of two sources:
. a file (e.g. csv or tsv) . a data generator (for artificial data)

The RS encodes a record using an encoding scheme that can be specified programmatically.

An RS is essentially a shell containing two objects:

  1. dataSource object gets one record at a time. This record is returned either as a dictionary or a user-defined object. The fields within a record correspond to entries in the dictionary or attributes of the object. For example, a dataSource might return:

    dict(date="02-01-2010 23:12:23", amount=4.95, country="US",
         _reset=0, _sequenceId=0)

    or an object with attributes date, amount and country.

    A data source is typically a or an artificial data generator.

  2. An encoder object encodes one record into a fixed-sparsity distributed representation. Usually nupic.encoders.multi.MultiEncoder.

    Example usage in NuPIC:

    from import Network
    from nupic.encoders import MultiEncoder
    from import FileRecordStream
    n = Network()
    s = n.addRegion("sensor", "py.RecordSensor", "")
    mysource = FileRecordStream("mydata.txt")
    myencoder = MultiEncoder()
    ... set up myencoder ...
    s.getSelf().dataSource = mysource
    s.getSelf().encoder = myencoder
    l1 = n.addRegion("l1", "py.TestRegion", "[create params]")
  • verbosity – (int) verbosity, default 0
  • numCategories – (int) number of categories, default 1

Apply pre-encoding filters. These filters may modify or add data. If a filter needs another record (e.g. a delta filter) it will request another record by returning False and the current record will be skipped (but will still be given to all filters).

We have to be very careful about resets. A filter may add a reset, but other filters should not see the added reset, each filter sees the original reset value, and we keep track of whether any filter adds a reset.

Parameters:data – (dict) The data that will be processed by the filter.
Returns:(tuple) with the data processed by the filter and a boolean to know whether or not the filter needs mode data.
compute(inputs, outputs)

Get a record from the dataSource and encode it.

Overrides nupic.bindings.regions.PyRegion.PyRegion.compute().


Get the next record to encode. Includes getting a record from the dataSource and applying filters. If the filters request more data from the dataSource continue to get data from the dataSource until all filters are satisfied. This method is separate from RecordSensor.compute() so that we can use a standalone RecordSensor to get filtered data.


Computes the width of dataOut.

Overrides nupic.bindings.regions.PyRegion.PyRegion.getOutputElementCount().



These are normal Python lists, rather than numpy arrays. This is to support lists with mixed scalars and strings, as in the case of records with categorical variables.

Returns:(dict) output values.
static getSchema()

Overrides nupic.bindings.regions.PyRegion.PyRegion.getSchema().

populateCategoriesOut(categories, output)

Populate the output array with the category indices.


Non-categories are represented with -1.

  • categories – (list) of category strings
  • output – (list) category output, will be overwritten
classmethod readFromProto(proto)

Overrides nupic.bindings.regions.PyRegion.PyRegion.readFromProto().


Reset the sensor to beginning of data.

setParameter(parameterName, index, parameterValue)

Set the value of a Spec parameter. Most parameters are handled automatically by PyRegion’s parameter set mechanism. The ones that need special treatment are explicitly handled here.


Overrides nupic.bindings.regions.PyRegion.PyRegion.writeToProto().