See numenta/nupic-legacy#2115 for context
Last active
August 29, 2015 14:21
-
-
Save oxtopus/23384ab43e063102227f to your computer and use it in GitHub Desktop.
issue #2115
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`cpp` implementation: | |
ModelResult( predictionNumber=999 | |
rawInput={'field1': 'Z68', 'classification': 'A68'} | |
sensorInput=SensorInput( dataRow=('Z68',) | |
dataDict={'field1': 'Z68', 'classification': 'A68'} | |
dataEncodings=[array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., | |
0., 0., 0., 0., 1., 1., 0., 1., 0., 1., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., | |
0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., | |
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., | |
1., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., | |
0., 0., 1., 0., 1., 0., 0., 1., 0., 0., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., | |
1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., | |
1., 0., 0., 0.], dtype=float32)] | |
sequenceReset=0.0 | |
category=0 | |
) | |
inferences={'multiStepPredictions': {0: {'A21': 0.017018328001970076, 'A86': 0.025500122950098816, 'A85': 0.027304582883691787, 'A52': 0.018374769721847952, 'A5': 0.017380698147416558, 'A54': 0.018555549923663036, 'A68': 0.078285036390751225, 'A43': 0.017195796532000717}}, 'multiStepBestPredictions': {0: 'A68'}, 'anomalyScore': None} | |
metrics=None | |
predictedFieldIdx=None | |
predictedFieldName=classification | |
) | |
ModelResult( predictionNumber=1000 | |
rawInput={'field1': 'Z75', 'classification': None} | |
sensorInput=SensorInput( dataRow=('Z75',) | |
dataDict={'field1': 'Z75', 'classification': None} | |
dataEncodings=[array([ 0., 0., 0., 0., 1., 0., 0., 1., 0., 0., 0., 0., 1., | |
0., 0., 0., 0., 0., 1., 0., 0., 1., 1., 0., 0., 0., | |
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., | |
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., | |
0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 1., 0., | |
0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., | |
0., 0., 1., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., | |
0., 0., 0., 0.], dtype=float32)] | |
sequenceReset=0.0 | |
category=0 | |
) | |
inferences={'multiStepPredictions': {0: {10.0: 0.021096635866935359, 12.0: 0.029523950153757712, 14.0: 0.022389804874187708, 20.0: 0.024284386197955064, 23.0: 0.024051517002240334, 57.0: 0.055984890054280374, None: 0.026655194509031799, 26.0: 0.020005072580303047}}, 'multiStepBestPredictions': {0: 57.0}, 'anomalyScore': None} | |
metrics=None | |
predictedFieldIdx=None | |
predictedFieldName=classification | |
) | |
Switching to `py` implementation | |
ModelResult( predictionNumber=999 | |
rawInput={'field1': 'Z91', 'classification': 'A91'} | |
sensorInput=SensorInput( dataRow=('Z91',) | |
dataDict={'field1': 'Z91', 'classification': 'A91'} | |
dataEncodings=[array([ 0., 0., 1., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., | |
0., 1., 1., 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., | |
1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., | |
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., | |
0., 0., 1., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., | |
1., 1., 0., 0.], dtype=float32)] | |
sequenceReset=0.0 | |
category=0 | |
) | |
inferences={'multiStepPredictions': {0: {'A12': 0.0262765278784447, 'A67': 0.02172648726270179, 'A60': 0.018943902499596148, 'A3': 0.023220922439247494, 'A52': 0.02190171999606073, 'A7': 0.018732111263751877, 'A91': 0.019514134499977211, 'A90': 0.04268380033354497}}, 'multiStepBestPredictions': {0: 'A90'}, 'anomalyScore': None} | |
metrics=None | |
predictedFieldIdx=None | |
predictedFieldName=classification | |
) | |
ModelResult( predictionNumber=1000 | |
rawInput={'field1': 'Z60', 'classification': None} | |
sensorInput=SensorInput( dataRow=('Z60',) | |
dataDict={'field1': 'Z60', 'classification': None} | |
dataEncodings=[array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., | |
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., | |
0., 0., 0., 0., 0., 0., 0., 1., 0., 1., 1., 0., 1., | |
1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., | |
0., 1., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 1., | |
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., | |
1., 0., 0., 1., 0., 0., 1., 0., 1., 0., 1., 0., 0., | |
1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., | |
0., 0., 1., 0.], dtype=float32)] | |
sequenceReset=0.0 | |
category=0 | |
) | |
inferences={'multiStepPredictions': {0: {'A83': 0.017049521814562985, 'A10': 0.015987908661051004, 'A26': 0.023570763373443306, 'A60': 0.066631353873196478, 'A18': 0.017054244101916777, 'A61': 0.016429903265782565, 'A3': 0.018157330471954239, 'A90': 0.016815080302038671}}, 'multiStepBestPredictions': {0: 'A60'}, 'anomalyScore': None} | |
metrics=None | |
predictedFieldIdx=None | |
predictedFieldName=classification | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
from nupic.frameworks.opf.modelfactory import ModelFactory | |
PARAMS = { | |
'aggregationInfo': {'days': 0, | |
'fields': [], | |
'hours': 0, | |
'microseconds': 0, | |
'milliseconds': 0, | |
'minutes': 0, | |
'months': 0, | |
'seconds': 0, | |
'weeks': 0, | |
'years': 0}, | |
'dataSource': 'file://' + os.path.join(os.environ["NUPIC"], "examples/opf/experiments/spatial_classification/datasets/category_0.csv"), | |
'errorMetric': 'avg_err', | |
'model': 'CLA', | |
'modelParams': {'anomalyParams': {u'anomalyCacheRecords': None, | |
u'autoDetectThreshold': None, | |
u'autoDetectWaitRecords': None}, | |
'clParams': {'alpha': 0.001, | |
'clVerbosity': 0, | |
'implementation': 'cpp', | |
'regionName': 'CLAClassifierRegion', | |
'steps': '0'}, | |
'inferenceType': 'NontemporalClassification', | |
'sensorParams': {'encoders': {u'classification': {'classifierOnly': True, | |
'fieldname': u'classification', | |
'n': 121, | |
'name': u'classification', | |
'type': 'SDRCategoryEncoder', | |
'w': 21}, | |
u'field1': {'fieldname': u'field1', | |
'n': 121, | |
'name': u'field1', | |
'type': 'SDRCategoryEncoder', | |
'w': 21}}, | |
'sensorAutoReset': None, | |
'verbosity': 0}, | |
'spEnable': False, | |
'spParams': {'columnCount': 2048, | |
'globalInhibition': 1, | |
'inputWidth': 0, | |
'numActiveColumnsPerInhArea': 40, | |
'potentialPct': 0.5, | |
'seed': 1956, | |
'spVerbosity': 0, | |
'spatialImp': 'py', | |
'synPermActiveInc': 0.1, | |
'synPermConnected': 0.1, | |
'synPermInactiveDec': 0.01}, | |
'tpEnable': False, | |
'tpParams': {'activationThreshold': 16, | |
'cellsPerColumn': 32, | |
'columnCount': 2048, | |
'globalDecay': 0.0, | |
'initialPerm': 0.21, | |
'inputWidth': 2048, | |
'maxAge': 0, | |
'maxSegmentsPerCell': 128, | |
'maxSynapsesPerSegment': 32, | |
'minThreshold': 12, | |
'newSynapseCount': 20, | |
'outputType': 'normal', | |
'pamLength': 1, | |
'permanenceDec': 0.1, | |
'permanenceInc': 0.1, | |
'seed': 1960, | |
'temporalImp': 'cpp', | |
'verbosity': 0}, | |
'trainSPNetOnlyIfRequested': False}, | |
'predictAheadTime': None, | |
'version': 1 | |
} | |
model = ModelFactory.create(PARAMS) | |
model.enableInference({"predictedField": "classification"}) | |
print "`cpp` implementation: " | |
for r in range(1000): | |
ip = str(random.randint(0, 99)) | |
res = model.run({"classification": "A" + ip, "field1": "Z" + ip}) | |
print res | |
for r in range(1000): | |
ip = str(random.randint(0, 99)) | |
res = model.run({"classification": None, "field1": "Z" + ip}) | |
if res.inferences["multiStepBestPredictions"][0]: | |
break | |
print res | |
print "Switching to `py` implementation" | |
PARAMS["modelParams"]["clParams"]["implementation"] = "py" | |
model = ModelFactory.create(PARAMS) | |
model.enableInference({"predictedField": "classification"}) | |
for r in range(1000): | |
ip = str(random.randint(0, 99)) | |
res = model.run({"classification": "A" + ip, "field1": "Z" + ip}) | |
print res | |
for r in range(1000): | |
ip = str(random.randint(0, 99)) | |
res = model.run({"classification": None, "field1": "Z" + ip}) | |
if res.inferences["multiStepBestPredictions"][0]: | |
break | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment