def binary_option(): from nupic.frameworks.opf.model import Model # inputFilePath = "./datasets/usdjpy_2001_01_ohlc.csv" # inputFilePath = "./datasets/usdjpy_2001_ohlc.csv" # inputFilePath = "./datasets/usdjpy_2001_2005_ohlc.csv" inputFilePath = "./datasets/usdjpy_2006_2007.csv" # predict_mode: disableLearning and dont save the model predict_mode = True if os.path.exists("./learned_model_direct"): print "read learned_model" low_model = Model.load("./learned_model_direct/low/") if predict_mode: low_model.disableLearning() else: low_model.enableLearning() else: print "create model ..." low_model = createModel("high_low") print "run Model ..." low_model = runModel(inputFilePath, low_model) if not predict_mode: print "pickle dump ..." low_model.save(os.path.abspath("./learned_model_direct/low/"))
def runModel(file_list, plot=False): for file1 in file_list: save = False file_name = os.path.splitext(file1)[0] path = '/home/sheiser1/nupic-master/examples/opf/clients/hotgym/prediction/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')
def binary_option(): from nupic.frameworks.opf.model import Model #inputFilePath = "./datasets/usdjpy_2001_01_ohlc.csv" #inputFilePath = "./datasets/usdjpy_2001_ohlc.csv" #inputFilePath = "./datasets/usdjpy_2001_2005_ohlc.csv" inputFilePath = "./datasets/usdjpy_2006_2007.csv" # TODO: 学習したモデルの保存ができてない. if os.path.exists('./learned_model'): print 'loading model ...' #high_model = Model.load('./learned_model/high/') low_model = Model.load('./learned_model/low/') else: print 'create model ...' #high_model = createModel("high") low_model = createModel("low") high_model = createModel("high") print 'run Model ...' runModel(inputFilePath, high_model, low_model, True)
__author__ = 'sergeyalexashenko' #This file loads a model and generates a jingle based on a list of notes to begin it with from music21 import * from nupic.frameworks.opf.model import Model ABSOLUTE_PATH_TO_MODEL='/Users/sergeyalexashenko/pycharm/bachify/savedmodel3/' model=Model.load(ABSOLUTE_PATH_TO_MODEL) model.resetSequenceStates() s = stream.Stream() list_of_notes=['e4','c5','a4','a4'] for everynote in list_of_notes: modelInput = {"note": everynote} result = model.run(modelInput) localnote=note.Note(everynote) localnote.duration.type = 'quarter' s.append(localnote) inference = result.inferences['multiStepBestPredictions'] i=1 #If you want more than 50 note predictions - change model_params.py to add more steps while i<51: prediction=inference[i] print prediction localnote=note.Note(prediction) localnote.duration.type = 'quarter' s.append(localnote) i=i+1 s.show()