Skip to content

Instantly share code, notes, and snippets.

@rhyolight
Forked from jclevesque/run_charpred.py
Created June 19, 2017 20:32
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 rhyolight/618784b79764977cf7cf96455d34cd5f to your computer and use it in GitHub Desktop.
Save rhyolight/618784b79764977cf7cf96455d34cd5f to your computer and use it in GitHub Desktop.
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
from nupic.data.inference_shifter import InferenceShifter
from nupic.frameworks.opf.model_factory import ModelFactory
# Create and run the model:
MODEL_PARAMS = {
"model": "HTMPrediction",
"version": 1,
"predictAheadTime": None,
"modelParams": {
"inferenceType": "TemporalMultiStep",
"sensorParams": {
"verbosity" : 0,
"encoders": {
"char": {
"fieldname": u"char",
"name": u"char",
"type": "CategoryEncoder",
"categoryList": list(set(map(str.strip, open("input_test.txt").readlines()))),
"w": 21
}
},
"sensorAutoReset" : None,
},
"spEnable": True,
"spParams": {
"spVerbosity" : 0,
"globalInhibition": 1,
"columnCount": 2048,
"inputWidth": 0,
"numActiveColumnsPerInhArea": 40,
"seed": 1956,
"columnDimensions": 0.5,
"synPermConnected": 0.1,
"synPermActiveInc": 0.1,
"synPermInactiveDec": 0.01,
},
"tmEnable" : True,
"tmParams": {
"verbosity": 0,
"columnCount": 2048,
"cellsPerColumn": 32,
"inputWidth": 2048,
"seed": 1960,
"temporalImp": "cpp",
"newSynapseCount": 20,
"maxSynapsesPerSegment": 32,
"maxSegmentsPerCell": 128,
"initialPerm": 0.21,
"permanenceInc": 0.1,
"permanenceDec" : 0.1,
"globalDecay": 0.0,
"maxAge": 0,
"minThreshold": 12,
"activationThreshold": 16,
"outputType": "normal",
"pamLength": 1,
},
"clParams": {
"implementation": "py",
"regionName" : "SDRClassifierRegion",
"verbosity" : 0,
"alpha": 0.0001,
"steps": "1,2,3",
},
"trainSPNetOnlyIfRequested": False,
},
}
model = ModelFactory.create(MODEL_PARAMS)
model.enableInference({"predictedField": "char"})
shifter = InferenceShifter()
out = open("results.txt", "wt")
my_str = ''.join(['abcd '] * 10)
for c in my_str:
modelInput = {"char": c}
#result = shifter.shift(model.run(modelInput))
result = model.run(modelInput)
out.write("%s\n" %
([c] + [result.inferences["multiStepBestPredictions"]]))
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment