Created
October 6, 2016 02:31
-
-
Save gotham29/b17efc8ad1a26166fa5eec55abab1b0f to your computer and use it in GitHub Desktop.
My modifications to run.py to create and save numerous models, and run them each on all data sets.
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
#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 <module> | |
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. | |
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 | |
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') | |
# And here's the main function: | |
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment