Go to the documentation of this file.00001
00002
00003 import rospy
00004 import numpy as np
00005 import csv
00006 import sys
00007 import matplotlib.pyplot as plt
00008 from sklearn import linear_model, datasets
00009
00010 if __name__ == "__main__":
00011 csv_files = sys.argv[1:]
00012 xs = []
00013 ys = []
00014 es = []
00015 for csv_file in csv_files:
00016 with open(csv_file) as f:
00017 reader = csv.reader(f)
00018 (true_depths, observed_depths) = zip(*[(float(row[0]), float(row[1])) for row in reader])
00019 errs = [a - b for (a, b) in zip(true_depths, observed_depths)]
00020 true_mean = np.mean(true_depths)
00021 observed_mean = np.mean(observed_depths)
00022 err_mean = np.mean(errs, axis=0)
00023 err_stddev = np.std(errs, axis=0)
00024 xs.append(true_mean)
00025 ys.append(observed_mean)
00026
00027 es.append(err_stddev)
00028
00029 plt.scatter(xs, es)
00030 model_ransac = linear_model.RANSACRegressor(linear_model.LinearRegression(), min_samples=2,
00031 residual_threshold=0.1)
00032 X = np.array(xs).reshape((len(xs), 1))
00033 Y = np.array(es)
00034 model_ransac.fit(X, Y)
00035 line_y_ransac = model_ransac.predict(X)
00036 plt.plot(X, line_y_ransac, "r--",
00037 label="{0} x + {1}".format(model_ransac.estimator_.coef_[0][0],
00038 model_ransac.estimator_.intercept_[0]))
00039 print "{0} x + {1}".format(model_ransac.estimator_.coef_[0][0],
00040 model_ransac.estimator_.intercept_[0])
00041 plt.grid()
00042 plt.xlabel("Distance [m]")
00043 plt.ylabel("Standard Deviation [m]")
00044
00045 plt.show()