Sensors

PluggableEncoderSensor

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

Bases: nupic.bindings.regions.PyRegion.PyRegion

A PluggableEncoderSensor holds a value and encodes it into network output.

It requires you to reach in and insert an encoder.

setSensedValue(value)

Sets the value that will be encoded when this region does a compute.

RecordSensor

class nupic.regions.RecordSensor.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 three sources:
. a file (e.g. csv or tsv) . a sql database (not yet implemented) . 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. A 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”.

The _reset and _sequenceId attributes must always exist, and are provided by the DataSource if not directly present in the data.

DataSource methods are: – getNext() – return the next record, which is a dict – TBD: something like getIterationCount()?

2. A MultiEncoder object encodes one record into a fixed-sparsity distributed representation. MultiEncoder is defined in nupic.encoders

The DataSource and MultiEncoder are supplied after the node is created, not in the node itself.

Example usage in NuPIC:

from nupic.net import Network from nupic.encoders import MultiEncoder from nupic.data.file.file_record_stream 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.FDRCNode”, “[create params]”) n.initialize()

n.run(100)

TBD: the data source could also include the type of data, and we could more closely tie the DataSource output to the encoder input, ensuring that data types match and that allfields the encoder expects to see are in fact present.

applyFilters(data)

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.

@param data: The data that will be processed by the filter. @type data: dict @return: a 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.

getNextRecord()

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 compute() so that we can use a standalone RecordSensor to get filtered data

getOutputElementCount(name)

Computes the width of dataOut

getOutputValues(outputName)

Return the dictionary of output values. Note that 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

static getProtoType()

Return the pycapnp proto type that the class uses for serialization.

populateCategoriesOut(categories, output)

Populate the output array with the category indices. Note: non-categories are represented with -1.

classmethod readFromProto(proto)

Read state from proto object.

proto: RecordSensorProto capnproto object

rewind()

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.

writeToProto(proto)

Write state to proto object.

proto: RecordSensorProto capnproto object