本文整理汇总了Python中nupic.encoders.MultiEncoder.addMultipleEncoders方法的典型用法代码示例。如果您正苦于以下问题:Python MultiEncoder.addMultipleEncoders方法的具体用法?Python MultiEncoder.addMultipleEncoders怎么用?Python MultiEncoder.addMultipleEncoders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.MultiEncoder
的用法示例。
在下文中一共展示了MultiEncoder.addMultipleEncoders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _addRegion
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例2: _createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例3: _createNetwork
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例4: _createNetwork
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例5: createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例6: createSensors
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例7: createCategoryEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例8: createClassifierEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例9: _createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例10: createSensorEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例11: _makeRegion
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例12: createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
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
示例13: createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
def createEncoder():
"""Create the encoder instance for our test and return it."""
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"consumption": {
"clipInput": True,
"fieldname": u"consumption",
"maxval": 100.0,
"minval": 0.0,
"n": 50,
"name": u"consumption",
"type": "ScalarEncoder",
"w": 21,
},
"timestamp_timeOfDay": {
"fieldname": u"timestamp",
"name": u"timestamp_timeOfDay",
"timeOfDay": (21, 9.5),
"type": "DateEncoder",
},
})
return encoder
示例14: createEncoder
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
def createEncoder():
"""
Creates and returns a #MultiEncoder including a ScalarEncoder for
energy consumption and a DateEncoder for the time of the day.
@see nupic/encoders/__init__.py for type to file-name mapping
@see nupic/encoders for encoder source files
"""
encoder = MultiEncoder()
encoder.addMultipleEncoders({
"consumption": {"fieldname": u"consumption",
"type": "ScalarEncoder",
"name": u"consumption",
"minval": 0.0,
"maxval": 100.0,
"clipInput": True,
"w": 21,
"n": 500},
"timestamp_timeOfDay": {"fieldname": u"timestamp",
"type": "DateEncoder",
"name": u"timestamp_timeOfDay",
"timeOfDay": (21, 9.5)}
})
return encoder
示例15: _createNetwork
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import addMultipleEncoders [as 别名]
def _createNetwork(self):
def deepupdate(original, update):
"""
Recursively update a dict.
Subdict's won't be overwritten but also updated.
"""
if update is None:
return None
for key, value in original.iteritems():
if not key in update:
update[key] = value
elif isinstance(value, dict):
deepupdate(value, update[key])
return update
self.network = Network()
# check
# if self.selectivity not in self.dest_region_params.keys():
# raise Exception, "There is no selected region : " + self.selectivity
if not len(self.net_structure.keys()) == len(set(self.net_structure.keys())):
raise Exception, "There is deplicated net_structure keys : " + self.net_structure.keys()
# sensor
for sensor_name, params in self.sensor_params.items():
self.network.addRegion(sensor_name, "py.RecordSensor", json.dumps({"verbosity": 0}))
sensor = self.network.regions[sensor_name].getSelf()
# set encoder
#params = deepupdate(cn.SENSOR_PARAMS, params)
encoder = MultiEncoder()
encoder.addMultipleEncoders( params )
sensor.encoder = encoder
sensor.dataSource = DataBuffer()
# network
print 'create element ...'
for name in self.dest_region_params.keys():
change_params = self.dest_region_params[name]
params = deepupdate(self.default_params, change_params)
# input width
input_width = 0
for source in [s for s,d in self.net_structure.items() if name in d]:
if source in self.sensor_params.keys():
sensor = self.network.regions[source].getSelf()
input_width += sensor.encoder.getWidth()
else:
input_width += params['TP_PARAMS']['cellsPerColumn'] * params['TP_PARAMS']['columnCount']
params['SP_PARAMS']['inputWidth'] = input_width
self._makeRegion(name, params)
# link
print 'link network ...'
for source, dest_list in self.net_structure.items():
for dest in dest_list:
if source in self.sensor_params.keys():
self._linkRegion(source, dest)
else:
if self.tp_enable:
self._linkRegion("tp_" + source, dest)
else:
self._linkRegion("sp_" + source, dest)
# initialize
print 'initializing network ...'
self.network.initialize()
for name in self.dest_region_params.keys():
self._initRegion(name)
return