ydir = 0 if util.includeVelocity == True: features.append(yvel) if util.includeAcceleration == True: features.append(yacc) if util.includeHeading == True: features.append(heading) if util.includeYDirection == True: features.append(ydir) tdX = np.array(util.removeColFromRow(features, 0)) tdY = np.array(util.removeColFromRow(features, 1)) predY = neighY.predict(tdY) actual = test1Data[i + offset][1] prediction = predY[0] actuals.append(actual) predictions.append(prediction) # errors.append(util.error([actual], [prediction])) if onlyTrainingAndCV == False: # util.plotLines(actuals, predictions, 'Actual position', 'Predicted position') # util.plotGraph(actuals, predictions, 'Actual position', 'Predicted position') util.plotLine(actuals, 'Actual position') util.plotLine(predictions, 'Predicted position') # util.plotLine(errors, 'Error graph') print len(actuals), len(predictions) # print np.sum(errors) else: util.plotLine(cvScoresY, 'CV label y')
#parse the input txt,eg:text01.txt givenData = parseTxt(filename) #use the last 60 frames of gieven input, eg test01.txt as actual actual = givenData[len(givenData) - 60:] # feed the program input data with last 60 frames chopped off allData = consolidateAllData() output = particleFilterPrediction(givenData[:len(givenData) - 60], allData) #####need to write output to txt######### #use utility to test our error and make plots errors = [] for i in range(0, len(output)): #errors.append(util.error([actual[i]],[output[i]])) ok = ((output[i][0] - actual[i][0])**2) + ( (output[i][1] - actual[i][1])**2) errors.append(ok) util.plotGraph(actual, output, 'Actual position', 'Predicted position') util.plotLine(errors, 'Error graph') print len(actual), len(output) print "L2 error is >>>>>>>>" print math.sqrt(np.sum(errors)) else: sys.exit(1)
test1 = open('inputs/test01.txt') test1Data = np.loadtxt(test1, delimiter=',') test1Data = util.normalizeData(test1Data) errors = [] NUM_INPUTS = len(test1Data) - offset for i in range(1750, NUM_INPUTS): current = test1Data[i] features = util.createFeatureRow(test1Data, i, offset, current) td = np.array(features) predX = neigh.predict(td) predY = neighY.predict(td) actual = test1Data[i + offset] prediction = [predX[0], predY[0]] actuals.append(actual) predictions.append(prediction) errors.append(util.error([actual], [prediction])) if onlyTrainingAndCV == False: # util.plotLines(actuals, predictions, 'Actual position', 'Predicted position') # util.plotGraph(actuals, predictions, 'Actual position', 'Predicted position') util.plotData(actuals, 'Actual position') util.plotData(predictions, 'Predicted position') util.plotLine(errors, 'Error graph') print len(actuals), len(predictions) print np.sum(errors) else: util.plotLine(cvScoresX, 'CV label x') util.plotLine(cvScoresY, 'CV label y') # util.plotLines(cvScoresX, cvScoresY, 'CV label X', 'CV label y')