Advertisement
Guest User

run file

a guest
Aug 14th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. def runIoThroughNupic(inputData, model, gymName, plot):
  2.   inputFile = open(inputData, "rb")
  3.   csvReader = csv.reader(inputFile)
  4.  
  5.   # skip header row
  6.   csvReader.next()
  7.  
  8.   shifter = InferenceShifter()
  9.   print 'Got shifter'
  10.   if plot:
  11.     output = nupic_anomaly_output.NuPICPlotOutput(gymName)
  12.   else:
  13.     output = nupic_anomaly_output.NuPICFileOutput(gymName)
  14.  
  15.  
  16.   counter = 0
  17.   for row in csvReader:
  18.     if counter%10 == 0:    
  19.       print counter
  20.     counter += 1
  21.     #timestamp = datetime.datetime.strptime(row[0], DATE_FORMAT)
  22.    
  23.     x_response = float(row[0])*100
  24.     y_response = float(row[1])*100 #row[1]
  25.        
  26.     '''
  27.    result = model.run({
  28.      #"timestamp": timestamp,
  29.      #"x_Err": x_err,
  30.      "x_Response": x_response,
  31.      #"y_Err": y_err,
  32.      "y_Response": y_response,
  33.    })
  34.    '''
  35.    
  36.     #xy = [int(x_response*1000),int(y_response*1000)]
  37.     this_point = [x_response,y_response]
  38.    
  39.     vector = np.array(this_point).astype(int)
  40.    
  41.     try:
  42.         last_point
  43.     except:
  44.         last_point = None
  45.  
  46.     radius = calculate_radius(last_point,this_point)    
  47.     #print 'Got radius: ',radius    
  48.    
  49.     last_point = copy.deepcopy(this_point)    
  50.    
  51.     modelInput = {
  52.     "vector": (vector,radius)
  53.     }
  54.    
  55.     result = model.run(modelInput)
  56.    
  57.     if counter % 100 == 0:
  58.       print ("Read %i lines..." % counter)
  59.      
  60.    
  61.     if plot:
  62.       result = shifter.shift(result)
  63.  
  64.     #prediction = result.inferences["multiStepBestPredictions"][1]
  65.     anomalyScore = result.inferences["anomalyScore"]
  66.     output.write('_____', y_response, '_____', anomalyScore) #[timestamp]
  67.  
  68.   inputFile.close()
  69.   output.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement