Created
June 11, 2013 14:07
-
-
Save kennytm/5757126 to your computer and use it in GitHub Desktop.
Test NuPIC.
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 nupic.frameworks.opf.modelfactory as mf | |
import nupic.frameworks.opf.opfutils as ou | |
import nupic.frameworks.opf.predictionmetricsmanager as pm | |
import nupic.frameworks.opf.metrics as mt | |
import random | |
import math | |
STEPS = 5 | |
FIELD = 'latitude' | |
model_config = { | |
'model': 'CLA', | |
'version': 1, | |
'modelParams': { | |
'inferenceType': 'TemporalMultiStep', | |
'sensorParams': { | |
'verbosity': 0, | |
'encoders': { | |
FIELD: { | |
'type': 'ScalarEncoder', | |
'fieldname': FIELD, | |
'name': FIELD, | |
'minval': -1, | |
'maxval': 1, | |
'periodic': False, | |
'resolution': 0.02, | |
'w': 7, | |
}, | |
}, | |
'sensorAutoReset': None, | |
}, | |
'spParams': { | |
'spVerbosity': 0, | |
'columnCount': 2048, | |
}, | |
'tpParams': { | |
'verbosity': 0, | |
'columnCount': 2048, | |
'inputWidth': 2048, | |
'cellsPerColumn': 32, | |
}, | |
'clParams': { | |
'regionName' : 'CLAClassifierRegion', | |
'steps': STEPS, | |
}, | |
'predictedField': 'latitude', | |
}, | |
} | |
model = mf.ModelFactory.create(model_config) | |
metrics_manager = pm.MetricsManager( | |
[ | |
mt.MetricSpec( | |
field='latitude', | |
metric='multiStep', | |
inferenceElement='multiStepBestPredictions', | |
params={'errorMetric': 'altMAPE', 'window': 200, 'steps': STEPS} | |
) | |
], | |
model.getFieldInfo(), | |
model.getInferenceType() | |
) | |
model.enableInference({ | |
'predictedField': FIELD, | |
'predictionSteps': STEPS, | |
}) | |
for i in range(700): | |
dictionary = {'index': i, 'latitude': math.sin(i * 0.1)} | |
res = model.run(dictionary) | |
#res.metrics = metrics_manager.update(res) | |
print i, dictionary[FIELD], res.inferences['multiStepBestPredictions'][STEPS] | |
model.finishLearning() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment