Skip to content

Instantly share code, notes, and snippets.

@kennytm
Created June 11, 2013 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennytm/5757126 to your computer and use it in GitHub Desktop.
Save kennytm/5757126 to your computer and use it in GitHub Desktop.
Test NuPIC.
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