run.py file
-----------------------------------------------------------------
#!/usr/bin/env python
import csv
import datetime
from nupic.frameworks.opf.modelfactory import ModelFactory
from model_params import model_params
DATE_FORMAT = "%Y-%m-%d"
def createModel():
model = ModelFactory.create(model_params.MODEL_PARAMS)
model.enableInference({"predictedField": "Volume"})
return model
def runModel(model):
inputFilePath = "table.csv"
inputFile = open(inputFilePath, "rb")
csvReader = csv.reader(inputFile)
# skip header rows
csvReader.next()
csvReader.next()
csvReader.next()
counter = 0
for row in csvReader:
counter += 1
if (counter % 100 == 0):
print "Read %i lines..." % counter
date = datetime.datetime.strptime(row[0], DATE_FORMAT)
volume = float(row[1])
result = model.run({
"Date": date,
"Volume": volume
})
prediction = result.inferences["multiStepBestPredictions"][1]
print prediction
def runStockData():
model = createModel()
runModel(model)
if __name__ == "__main__":
runStockData()
---------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
model_params.py file
----------------------------------------------------------------------------------------------------------------------------
MODEL_PARAMS = \
{ 'aggregationInfo': { 'days': 0,
'fields': [],
'hours': 0,
'microseconds': 0,
'milliseconds': 0,
'minutes': 0,
'months': 0,
'seconds': 0,
'weeks': 0,
'years': 0},
'model': 'CLA',
'modelParams': { 'anomalyParams': { u'anomalyCacheRecords': None,
u'autoDetectThreshold': None,
u'autoDetectWaitRecords': None},
'clParams': { 'alpha': 0.025707736677855416,
'clVerbosity': 0,
'regionName': 'CLAClassifierRegion',
'steps': '1'},
'inferenceType': 'TemporalMultiStep',
'sensorParams': { 'encoders': { u'AdjClose': None,
u'Close': None,
u'Date_dayOfWeek': None,
u'Date_timeOfDay': None,
u'Date_weekend': None,
u'High': None,
u'Low': { 'clipInput':
True,
'fieldname':
'Low',
'maxval':
41.02,
'minval': 0.0,
'n': 139,
'name': 'Low',
'type':
'ScalarEncoder',
'w': 21},
u'Open': None,
u'Volume': None,
'_classifierInput': {
'classifierOnly': True,
'clipInput': True,
'fieldname': 'Volume',
'maxval': 66062700,
'minval': 0.0,
'n': 154,
'name': '_classifierInput',
'type': 'ScalarEncoder',
'w': 21}},
'sensorAutoReset': None,
'verbosity': 0},
'spEnable': True,
'spParams': { 'columnCount': 2048,
'globalInhibition': 1,
'inputWidth': 0,
'maxBoost': 2.0,
'numActiveColumnsPerInhArea': 40,
'potentialPct': 0.8,
'seed': 1956,
'spVerbosity': 0,
'spatialImp': 'cpp',
'synPermActiveInc': 0.05,
'synPermConnected': 0.1,
'synPermInactiveDec': 0.08283067560973391},
'tpEnable': True,
'tpParams': { 'activationThreshold': 13,
'cellsPerColumn': 32,
'columnCount': 2048,
'globalDecay': 0.0,
'initialPerm': 0.21,
'inputWidth': 2048,
'maxAge': 0,
'maxSegmentsPerCell': 128,
'maxSynapsesPerSegment': 32,
'minThreshold': 10,
'newSynapseCount': 20,
'outputType': 'normal',
'pamLength': 2,
'permanenceDec': 0.1,
'permanenceInc': 0.1,
'seed': 1960,
'temporalImp': 'cpp',
'verbosity': 0},
'trainSPNetOnlyIfRequested': False},
'predictAheadTime': None,
'version': 1}
On Mon, Jun 30, 2014 at 5:00 PM, Matthew Taylor <[email protected]> wrote:
> When you run the "run.py" file, you're not using the swarm description
> anymore. The swarm description is used to get the best model parameters.
> The run.py uses the model params returned by the swarm to create a new
> NuPIC model and pass data into it.
>
> Can you show me your model params python file as well as your new run.py
> file? Even better, can you push your code to Github or Bitbucket?
>
> ---------
> Matt Taylor
> OS Community Flag-Bearer
> Numenta
>
>
> On Mon, Jun 30, 2014 at 12:52 PM, joseph skippings <
> [email protected]> wrote:
>
>> I fixed the last error and ran into another (error message below) . Is
>> this occurring because the fields open, high, low, close and adjclose are
>> included in the description.py and, not included in the run.py??
>>
>> ------------------------------------------------------------------------------------------------------------------------
>>
>>
>> --------------------------------------------------------------------------------------------------------------------
>>
>>
>> Traceback (most recent call last):
>> File "run.py", line 50, in <module>
>> runStockData()
>> File "run.py", line 47, in runStockData
>> runModel(model)
>> File "run.py", line 38, in runModel
>> "Volume": volume
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/frameworks/opf/clamodel.py",
>> line 391, in run
>> self._sensorCompute(inputRecord)
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/frameworks/opf/clamodel.py",
>> line 461, in _sensorCompute
>> sensor.compute()
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/engine/__init__.py",
>> line 443, in compute
>> return self._region.compute()
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/bindings/engine_internal.py",
>> line 1235, in compute
>> return _engine_internal.Region_compute(*args, **kwargs)
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/regions/RecordSensor.py",
>> line 294, in compute
>> self.encoder.encodeIntoArray(data, outputs["dataOut"])
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/encoders/multi.py",
>> line 74, in encodeIntoArray
>> encoder.encodeIntoArray(self._getInputValue(obj, name),
>> output[offset:])
>> File
>> "/home/wolf_maroon/nupic/build/release/lib/python2.7/site-packages/nupic/encoders/base.py",
>> line 223, in _getInputValue
>> fieldName, knownFields, fieldName
>> ValueError: Unknown field name 'Low' in input record. Known fields are
>> 'Date, Volume'.
>> This could be because input headers are mislabeled, or because input data
>> rows do not contain a value for 'Low'
>> ------------------------------------------------------
>> SWARM_DESCRIPTION = {
>> "includedFields": [
>> {
>> "fieldName": "Date",
>> "fieldType": "datetime"
>> },
>> {
>> "fieldName": "Open",
>> "fieldType": "float",
>> "maxValue": 41.33,
>> "minValue": 0.0
>> },
>> {
>> "fieldName": "High",
>> "fieldType": "float",
>> "maxValue": 41.72,
>> "minValue": 0.0
>> },
>> {
>> "fieldName": "Low",
>> "fieldType": "float",
>> "maxValue": 41.02,
>> "minValue": 0.0
>> },
>> {
>> "fieldName": "Close",
>> "fieldType": "float",
>> "maxValue": 41.23,
>> "minValue": 0.0
>> },
>> {
>> "fieldName": "Volume",
>> "fieldType": "float",
>> "maxValue": 66062700,
>> "minValue": 0.0
>> },
>> {
>> "fieldName": "AdjClose",
>> "fieldType": "float",
>> "maxValue": 41.23,
>> "minValue": 0.0
>> }
>> ],
>> "streamDef": {
>> "info": "Volume",
>> "version": 1,
>> "streams": [
>> {
>> "info": "yahoo_data_test",
>> "source": "file://table.csv",
>> "columns": [
>> "*"
>> ]
>> }
>> ]
>> },
>>
>> "inferenceType": "TemporalMultiStep",
>> "inferenceArgs": {
>> "predictionSteps": [
>> 1
>> ],
>> "predictedField": "Volume"
>> },
>> "iterationCount": -1,
>> "swarmSize": "medium"
>> }
>> -----------------------------------------------------------
>>
>>
>>
>> On Mon, Jun 30, 2014 at 2:10 PM, Matthew Taylor <[email protected]> wrote:
>>
>>> Thanks for the extra details. Try renaming your "table_model_params.py"
>>> file to "model_params.py". Is the "table_model_params.py" in a
>>> directory called "model_params"? If so, you might need to create an empty
>>> file within that directory called "__init__.py". This tells python to treat
>>> that directory as an importable module. See the structure of the example at
>>> https://github.com/numenta/nupic/tree/master/examples/opf/clients/hotgym/prediction/one_gym/model_params
>>>
>>> ---------
>>> Matt Taylor
>>> OS Community Flag-Bearer
>>> Numenta
>>>
>>>
>>> On Mon, Jun 30, 2014 at 10:58 AM, joseph skippings <
>>> [email protected]> wrote:
>>>
>>>> Using the hot_gym tutorial on youtube as a guide, I am trying to get my
>>>> run.py file to complie. Command python swarm.py ran successfully creating
>>>> the model params folder and file but when running the command python
>>>> run.py I get the error below. Inside the model_params folder the file is
>>>> called table_model_params.py.
>>>>
>>>> --------------------------------------------------------------------------------------------
>>>> python run.py
>>>> Traceback (most recent call last):
>>>> File "run.py", line 8, in <module>
>>>> from model_params import model_params
>>>> ImportError: No module named model_params
>>>>
>>>>
>>>> -------------------------------------------------------------------------------------------------
>>>>
>>>> #!/usr/bin/env python
>>>>
>>>> import csv
>>>> import datetime
>>>>
>>>> from nupic.frameworks.opf.modelfactory import ModelFactory
>>>>
>>>> from model_params import model_params
>>>>
>>>>
>>>> DATE_FORMAT = "%y/%m/%d"
>>>>
>>>>
>>>> def createModel(modelParams):
>>>> model = ModelFactory.create(model_Params.MODEL_PARAMS)
>>>> model.enableInference({"predictedField": "Volume"})
>>>> return model
>>>>
>>>> def runModel(model):
>>>> inputFilePath = "table.csv"
>>>> inputFile = open(inputFilePath, "rb")
>>>> csvReader = csv.reader(inputFile)
>>>> # skip header rows
>>>> csvReader.next()
>>>> csvReader.next()
>>>> csvReader.next()
>>>>
>>>> counter = 0
>>>> for row in csvReader:
>>>> counter += 1
>>>> if (counter % 100 == 0):
>>>> print "Read %i lines..." % counter
>>>> date = datetime.datetime.strptime(row[0], DATE_FORMAT)
>>>> volume = float(row[1])
>>>> result = model.run({
>>>> "Date": date,
>>>> "Volume": volume
>>>> })
>>>>
>>>> prediction = result.inferences["multiStepBestPredictions"][1]
>>>> print prediction
>>>>
>>>>
>>>> def runStockData():
>>>> model = createModel()
>>>> runModel(model)
>>>>
>>>> if __name__ == "__main__":
>>>> runStockData()
>>>>
>>>> ------------------------------------------
>>>>
>>>>
>>>>
>>>> On Mon, Jun 30, 2014 at 1:25 PM, Matthew Taylor <[email protected]>
>>>> wrote:
>>>>
>>>>> Joseph,
>>>>>
>>>>> When reporting problems to the mailing list, it is essential that you
>>>>> include the following information so we can help you:
>>>>>
>>>>> - exact command you ran that received the error
>>>>> - any steps you took before that command
>>>>> - what you are trying to achieve with the command
>>>>> - complete output that contains the error (use pastebin.com if it is
>>>>> very long)
>>>>>
>>>>> From what I can tell about your report, you have model params in a
>>>>> file named "table_model_params.py", but you are importing "model_params".
>>>>> You should "import table_model_params" to get that file imported into
>>>>> another Python script.
>>>>>
>>>>> ---------
>>>>> Matt Taylor
>>>>> OS Community Flag-Bearer
>>>>> Numenta
>>>>>
>>>>>
>>>>> On Mon, Jun 30, 2014 at 9:48 AM, Joseph Skippings <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I get this error when I run file run.py "From model_params
>>>>>> import model_params. ImportError: no module named model_params." In my
>>>>>> model_params folder the file is called table_model_params.py, I'm not
>>>>>> sure
>>>>>> if that is causing the error.
>>>>>>
>>>>>> Thanks in advance.
>>>>>>
>>>>>> Sent from my iPhone
>>>>>> _______________________________________________
>>>>>> nupic mailing list
>>>>>> [email protected]
>>>>>> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> nupic mailing list
>>>>> [email protected]
>>>>> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> nupic mailing list
>>>> [email protected]
>>>> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>>>>
>>>>
>>>
>>> _______________________________________________
>>> nupic mailing list
>>> [email protected]
>>> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>>>
>>>
>>
>> _______________________________________________
>> nupic mailing list
>> [email protected]
>> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>>
>>
>
> _______________________________________________
> nupic mailing list
> [email protected]
> http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org
>
>
_______________________________________________
nupic mailing list
[email protected]
http://lists.numenta.org/mailman/listinfo/nupic_lists.numenta.org