Sensors¶
PluggableEncoderSensor¶
-
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), name="timestamp_timeOfDay")
-
getSensedValue
()¶ Returns: sensed value
-
setSensedValue
(value)¶ Parameters: value – will be encoded when this region does a compute.
-
RecordSensor¶
-
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:
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
nupic.data.file_record_stream.FileRecordStream
: or an artificial data generator.An encoder object encodes one record into a fixed-sparsity distributed representation. Usually
nupic.encoders.multi.MultiEncoder
.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.TestRegion", "[create params]") n.initialize() n.run(100)
Parameters: - verbosity – (int) verbosity, default 0
- numCategories – (int) number of categories, default 1
-
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.
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()
.
-
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
RecordSensor.compute()
so that we can use a standaloneRecordSensor
to get filtered data.
-
getOutputElementCount
(name)¶ Computes the width of dataOut.
Overrides
nupic.bindings.regions.PyRegion.PyRegion.getOutputElementCount()
.
-
getOutputValues
(outputName)¶ Note
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
getProtoType
()¶ Overrides
nupic.bindings.regions.PyRegion.PyRegion.getProtoType()
.
-
populateCategoriesOut
(categories, output)¶ Populate the output array with the category indices.
Note
Non-categories are represented with
-1
.Parameters: - categories – (list) of category strings
- output – (list) category output, will be overwritten
-
classmethod
readFromProto
(proto)¶ Overrides
nupic.bindings.regions.PyRegion.PyRegion.readFromProto()
.
-
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)¶ Overrides
nupic.bindings.regions.PyRegion.PyRegion.writeToProto()
.