本文整理汇总了Python中nupic.encoders.MultiEncoder类的典型用法代码示例。如果您正苦于以下问题:Python MultiEncoder类的具体用法?Python MultiEncoder怎么用?Python MultiEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultiEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createNetwork
def _createNetwork():
"""Create network with one RecordSensor region."""
network = Network()
network.addRegion('sensor', 'py.RecordSensor', '{}')
sensorRegion = network.regions['sensor'].getSelf()
# Add an encoder.
encoderParams = {'consumption': {'fieldname': 'consumption',
'resolution': 0.88,
'seed': 1,
'name': 'consumption',
'type': 'RandomDistributedScalarEncoder'}}
encoder = MultiEncoder()
encoder.addMultipleEncoders(encoderParams)
sensorRegion.encoder = encoder
# Add a data source.
testDir = os.path.dirname(os.path.abspath(__file__))
inputFile = os.path.join(testDir, 'fixtures', 'gymdata-test.csv')
dataSource = FileRecordStream(streamID=inputFile)
sensorRegion.dataSource = dataSource
# Get and set what field index we want to predict.
network.regions['sensor'].setParameter('predictedField', 'consumption')
return network
示例2: _addRegion
def _addRegion(self, src_name, dest_name, params):
sensor = src_name
sp_name = "sp_" + dest_name
tp_name = "tp_" + dest_name
class_name = "class_" + dest_name
try:
self.network.regions[sp_name]
self.network.regions[tp_name]
self.network.regions[class_name]
self.network.link(sensor, sp_name, "UniformLink", "")
except Exception as e:
# sp
self.network.addRegion(sp_name, "py.SPRegion", json.dumps(params['SP_PARAMS']))
self.network.link(sensor, sp_name, "UniformLink", "")
# tp
self.network.addRegion(tp_name, "py.TPRegion", json.dumps(params['TP_PARAMS']))
self.network.link(sp_name, tp_name, "UniformLink", "")
# class
self.network.addRegion( class_name, "py.CLAClassifierRegion", json.dumps(params['CLASSIFIER_PARAMS']))
self.network.link(tp_name, class_name, "UniformLink", "")
encoder = MultiEncoder()
encoder.addMultipleEncoders(params['CLASSIFIER_ENCODE_PARAMS'])
self.classifier_encoder_list[class_name] = encoder
self.classifier_input_list[class_name] = tp_name
示例3: _createNetwork
def _createNetwork():
"""Create a network with a RecordSensor region and a SDRClassifier region"""
network = Network()
network.addRegion('sensor', 'py.RecordSensor', '{}')
network.addRegion('classifier', 'py.SDRClassifierRegion', '{}')
_createSensorToClassifierLinks(network, 'sensor', 'classifier')
# Add encoder to sensor region.
sensorRegion = network.regions['sensor'].getSelf()
encoderParams = {'consumption': {'fieldname': 'consumption',
'resolution': 0.88,
'seed': 1,
'name': 'consumption',
'type': 'RandomDistributedScalarEncoder'}}
encoder = MultiEncoder()
encoder.addMultipleEncoders(encoderParams)
sensorRegion.encoder = encoder
# Add data source.
testDir = os.path.dirname(os.path.abspath(__file__))
inputFile = os.path.join(testDir, 'fixtures', 'gymdata-test.csv')
dataSource = FileRecordStream(streamID=inputFile)
sensorRegion.dataSource = dataSource
# Get and set what field index we want to predict.
predictedIdx = dataSource.getFieldNames().index('consumption')
network.regions['sensor'].setParameter('predictedFieldIdx', predictedIdx)
return network
示例4: createEncoder
def createEncoder(newEncoders):
"""
Creates and returns a MultiEncoder.
@param newEncoders (dict) Keys are the encoders' names, values are
dicts of the params; an example is shown below.
@return encoder (MultiEncoder) See nupic.encoders.multi.py.
Example input:
{"energy": {"fieldname": u"energy",
"type": "ScalarEncoder",
"name": u"consumption",
"minval": 0.0,
"maxval": 100.0,
"w": 21,
"n": 500},
"timestamp": {"fieldname": u"timestamp",
"type": "DateEncoder",
"name": u"timestamp_timeOfDay",
"timeOfDay": (21, 9.5)},
}
"""
encoder = MultiEncoder()
encoder.addMultipleEncoders(newEncoders)
return encoder
示例5: _createEncoder
def _createEncoder(encoders):
"""
Creates and returns a MultiEncoder.
@param encoders: (dict) Keys are the encoders' names, values are dicts of
the params; an example is shown below.
@return encoder: (MultiEncoder) See nupic.encoders.multi.py. Example input:
{"energy": {"fieldname": u"energy",
"type": "ScalarEncoder",
"name": u"consumption",
"minval": 0.0,
"maxval": 100.0,
"w": 21,
"n": 500},
"timestamp": {"fieldname": u"timestamp",
"type": "DateEncoder",
"name": u"timestamp_timeOfDay",
"timeOfDay": (21, 9.5)},
}
"""
if not isinstance(encoders, dict):
raise TypeError("Encoders specified in incorrect format.")
encoder = MultiEncoder()
encoder.addMultipleEncoders(encoders)
return encoder
示例6: createEncoder
def createEncoder():
"""Create the encoder instance for our test and return it."""
consumption_encoder = ScalarEncoder(21, 0.0, 100.0, n=50, name="consumption", clipInput=True)
time_encoder = DateEncoder(timeOfDay=(21, 9.5), name="timestamp_timeOfDay")
encoder = MultiEncoder()
encoder.addEncoder("consumption", consumption_encoder)
encoder.addEncoder("timestamp", time_encoder)
return encoder
示例7: createSensors
def createSensors(network, sensors):
for sensor in sensors:
dataSource = FileRecordStream(streamID=sensor["source"])
dataSource.setAutoRewind(True)
encoder = MultiEncoder()
encoder.addMultipleEncoders(fieldEncodings=sensor["encodings"])
s = createRegion(network, sensor)
s = s.getSelf()
s.dataSource = dataSource
s.encoder = encoder
return network
示例8: createCategoryEncoder
def createCategoryEncoder():
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"gym": {
"type": "CategoryEncoder",
"fieldname": u"gym",
"name": u"gym",
"categoryList": ['Hornsby', 'Melbourne', 'Epping', 'Chadstone', 'North', 'Bondi', 'Pitt', 'Park', 'Canberra', 'Darlinghurst'],
"w": 21,
},
})
return encoder
示例9: createClassifierEncoder
def createClassifierEncoder():
"""Create the encoder instance for our test and return it."""
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"y": {
"type": "CategoryEncoder",
"categoryList": ['label_1', 'label_2'],
"fieldname": u"y",
"name": u"y",
"w": 21,
},
})
return encoder
示例10: _createEncoder
def _createEncoder():
"""Create the encoder instance for our test and return it."""
encoder = MultiEncoder()
encoder.addMultipleEncoders({
'timestamp': dict(fieldname='timestamp', type='DateEncoder',
timeOfDay=(5,5), forced=True),
'attendeeCount': dict(fieldname='attendeeCount', type='ScalarEncoder',
name='attendeeCount', minval=0, maxval=270,
clipInput=True, w=5, resolution=10, forced=True),
'consumption': dict(fieldname='consumption',type='ScalarEncoder',
name='consumption', minval=0,maxval=115,
clipInput=True, w=5, resolution=5, forced=True),
})
return encoder
示例11: initialize
def initialize(self):
"""
Initialize this node.
"""
Node.initialize(self)
# Initialize input bits
self.bits = []
for x in range(self.width):
for y in range(self.height):
bit = Bit()
bit.x = x
bit.y = y
self.bits.append(bit)
if self.dataSourceType == DataSourceType.file:
"""
Initialize this node opening the file and place cursor on the first record.
"""
# If file name provided is a relative path, use project file path
if self.fileName != '' and os.path.dirname(self.fileName) == '':
fullFileName = os.path.dirname(Global.project.fileName) + '/' + self.fileName
else:
fullFileName = self.fileName
# Check if file really exists
if not os.path.isfile(fullFileName):
QtGui.QMessageBox.warning(None, "Warning", "Input stream file '" + fullFileName + "' was not found or specified.", QtGui.QMessageBox.Ok)
return
# Create a data source for read the file
self.dataSource = FileRecordStream(fullFileName)
elif self.dataSourceType == DataSourceType.database:
pass
self.encoder = MultiEncoder()
for encoding in self.encodings:
encoding.initialize()
# Create an instance class for an encoder given its module, class and constructor params
encoding.encoder = getInstantiatedClass(encoding.encoderModule, encoding.encoderClass, encoding.encoderParams)
# Take the first part of encoder field name as encoder name
# Ex: timestamp_weekend.weekend => timestamp_weekend
encoding.encoder.name = encoding.encoderFieldName.split('.')[0]
# Add sub-encoder to multi-encoder list
self.encoder.addEncoder(encoding.dataSourceFieldName, encoding.encoder)
# If encoder size is not the same to sensor size then throws exception
encoderSize = self.encoder.getWidth()
sensorSize = self.width * self.height
if encoderSize > sensorSize:
QtGui.QMessageBox.warning(None, "Warning", "'" + self.name + "': Encoder size (" + str(encoderSize) + ") is different from sensor size (" + str(self.width) + " x " + str(self.height) + " = " + str(sensorSize) + ").", QtGui.QMessageBox.Ok)
return
return True
示例12: createScalarEncoder
def createScalarEncoder():
scalarEncoder = ScalarEncoder(SCALAR_ENCODER_PARAMS['w'],
SCALAR_ENCODER_PARAMS['minval'],
SCALAR_ENCODER_PARAMS['maxval'],
n=SCALAR_ENCODER_PARAMS['n'],
name=SCALAR_ENCODER_PARAMS['name'])
# NOTE: we don't want to encode the category along with the scalar input.
# The category will be fed separately to the classifier later, during the training phase.
#categoryEncoder = CategoryEncoder(CATEGORY_ENCODER_PARAMS['w'],
# CATEGORY_ENCODER_PARAMS['categoryList'],
# name=CATEGORY_ENCODER_PARAMS['name'])
encoder = MultiEncoder()
encoder.addEncoder(SCALAR_ENCODER_PARAMS['name'], scalarEncoder)
return encoder
示例13: createSensorEncoder
def createSensorEncoder():
"""Create the encoder instance for our test and return it."""
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"x": {
"type": "ScalarEncoder",
"fieldname": u"x",
"name": u"x",
"maxval": 100.0,
"minval": 0.0,
"n": 100,
"w": 21,
"clipInput": True,
},
})
return encoder
示例14: _makeRegion
def _makeRegion(self, name, params):
sp_name = "sp_" + name
if self.tp_enable:
tp_name = "tp_" + name
class_name = "class_" + name
# addRegion
self.network.addRegion(sp_name, "py.SPRegion", json.dumps(params['SP_PARAMS']))
if self.tp_enable:
self.network.addRegion(tp_name, "py.TPRegion", json.dumps(params['TP_PARAMS']))
self.network.addRegion( class_name, "py.CLAClassifierRegion", json.dumps(params['CLASSIFIER_PARAMS']))
encoder = MultiEncoder()
encoder.addMultipleEncoders(self.class_encoder_params)
self.classifier_encoder_list[class_name] = encoder
if self.tp_enable:
self.classifier_input_list[class_name] = tp_name
else:
self.classifier_input_list[class_name] = sp_name
示例15: createEncoder
def createEncoder():
# TODO: vector
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"consumption": {
"clipInput": True,
"type": "ScalarEncoder",
"fieldname": u"consumption",
"name": u"consumption",
"maxval": 100.0,
"minval": 0.0,
"n": 50,
"w": 21,
},
"timestamp_timeOfDay": {
"fieldname": u"timestamp",
"name": u"timestamp_timeOfDay",
"timeOfDay": (21, 9.5),
"type": "DateEncoder",
},
})
return encoder