Hi all, so I’m receiving this Assertion error when trying to save models in NuPIC using the TemporalAnomaly model type, and wondered if anyone had any ideas:
Traceback (most recent call last):
File “run.py”, line 190, in
runModel(only_csv_files, plot=plot) #runModel(GYM_NAME, plot=plot)
File “run.py”, line 166, in runModel
model.save(path)
File “/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/model.py”, line 289, in save
self.__makeDirectoryFromAbsolutePath(saveModelDir)
File “/home/sheiser1/.local/lib/python2.7/site-packages/nupic/frameworks/opf/model.py”, line 385, in __makeDirectoryFromAbsolutePath
assert os.path.isabs(absDirPath)
AssertionError
Here are the modifications I made to the runModel function. First I set the new data directory, and create the list of csv files (‘only_csv_files’) that I’ll pass into the modified runModel function.
mypath = ‘/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData’
only_csv_files = [f for f in listdir(mypath) if isfile(join(mypath,f)) and os.path.splitext(f)[1] == ‘.csv’]
for file in only_csv_files:
print 'File: ',file
GYM_NAME = “rec-center-hourly”
DATA_DIR = “/home/sheiser1/Desktop/zaychik_proj1-master/Dr_Zaychik_Data/selectedData” #“.”
MODEL_PARAMS_DIR = “./model_params”
Here I change runModel to take in a list of data files instead of just one, replacing ‘gymName’ with ‘only_csv_files’. I added an outer loop to the function, because the goal is to learn 20 separate models (1 for each of 20 separate data sets). The idea is to save each model, then run it on each data set (with learning turned off) to see which model best accounts for each given data set. To choose the model that best fits the given data set, I intend to take the model with lowest overall anomalyLikelihood as Matt suggested (if I understood right).
def runModel(file_list, plot=False): #def runModel(gymName, plot=False):
“”"
Assumes the gynName corresponds to both a like-named model_params file in the
model_params directory, and that the data exists in a like-named CSV file in
the current directory.
:param gymName: Important for finding model params and input CSV file
:param plot: Plot in matplotlib? Don’t use this unless matplotlib is
installed.
“”"
for file1 in file_list:
save = False
file_name = os.path.splitext(file1)[0]
path = ‘~/nupic/examples/opf/clients/hotgym/anomaly/one_gym$’ + file_name
model = None
if os.path.exists(path):
model = Model.load(path)
else:
model = createModel(getModelParamsFromName(GYM_NAME))
save = True
print “Creating model from %s…” % file_name
inputData = “%s/%s.csv” % (DATA_DIR, file_name.replace(" ", ““))
runIoThroughNupic(inputData, model, file_name, plot)
if save:
model.save(path)
for file2 in file_list:
file2_name = os.path.splitext(file2)[0]
model.disableLearning()
print “Running model” + file_name + ‘on’ + file2_name
inputData = “%s/%s.csv” % (DATA_DIR, file2_name.replace(” ", "”))
runIoThroughNupic(inputData, model, file2_name, plot)
os.rename(file2_name + ‘out.csv’, file_name + '’ + file2_name + ‘_out.csv’)
#print “Creating model from %s…” % gymName
#model = createModel(getModelParamsFromName(gymName))
#inputData = “%s/%s.csv” % (DATA_DIR, gymName.replace(" ", “_”))
#runIoThroughNupic(inputData, model, gymName, plot)
if name == “main”:
print DESCRIPTION
plot = False
new_model = False
args = sys.argv[1:]
if “–plot” in args:
plot = True
runModel(only_csv_files, plot=plot) #runModel(GYM_NAME, plot=plot)
Thanks again!!