Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def runIoThroughNupic(inputData, model, gymName, plot):
- inputFile = open(inputData, "rb")
- csvReader = csv.reader(inputFile)
- # skip header row
- csvReader.next()
- shifter = InferenceShifter()
- print 'Got shifter'
- if plot:
- output = nupic_anomaly_output.NuPICPlotOutput(gymName)
- else:
- output = nupic_anomaly_output.NuPICFileOutput(gymName)
- counter = 0
- for row in csvReader:
- if counter%10 == 0:
- print counter
- counter += 1
- #timestamp = datetime.datetime.strptime(row[0], DATE_FORMAT)
- x_response = float(row[0])*100
- y_response = float(row[1])*100 #row[1]
- '''
- result = model.run({
- #"timestamp": timestamp,
- #"x_Err": x_err,
- "x_Response": x_response,
- #"y_Err": y_err,
- "y_Response": y_response,
- })
- '''
- #xy = [int(x_response*1000),int(y_response*1000)]
- this_point = [x_response,y_response]
- vector = np.array(this_point).astype(int)
- try:
- last_point
- except:
- last_point = None
- radius = calculate_radius(last_point,this_point)
- #print 'Got radius: ',radius
- last_point = copy.deepcopy(this_point)
- modelInput = {
- "vector": (vector,radius)
- }
- result = model.run(modelInput)
- if counter % 100 == 0:
- print ("Read %i lines..." % counter)
- if plot:
- result = shifter.shift(result)
- #prediction = result.inferences["multiStepBestPredictions"][1]
- anomalyScore = result.inferences["anomalyScore"]
- output.write('_____', y_response, '_____', anomalyScore) #[timestamp]
- inputFile.close()
- output.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement