Skip to content
Snippets Groups Projects
Commit 04dd969b authored by chsieh16's avatar chsieh16
Browse files

Refactor for readability and consistency

parent 68c86728
No related branches found
No related tags found
No related merge requests found
import pickle
import numpy as np
from numpy.lib.function_base import diff
import matplotlib.pyplot as plt
# Constants for Stanley controller for GEM
......@@ -26,7 +25,7 @@ def f(x, y, theta, steer):
def v(x, y, theta) -> float:
return y**2 + theta**2
return np.linalg.norm([y, theta], ord=2)
def in_circle(x, y, theta, d, phi) -> bool:
......@@ -36,8 +35,8 @@ def in_circle(x, y, theta, d, phi) -> bool:
state_vec = np.array([x, y, theta])
perc_vec = np.array([d, phi])
diff_vec = perc_vec - (np.dot(state_vec, a_mat.T) + b_vec)
return np.dot(diff_vec, diff_vec) <= 0.03
diff_vec = perc_vec - (a_mat @ state_vec + b_vec)
return np.linalg.norm(diff_vec, ord=2) <= np.sqrt(0.03)
def pred(sample) -> bool:
......@@ -61,7 +60,7 @@ for truth, samples in truth_samples_seq:
filtered_samples = [s for s in samples if pred(s)]
if abs(len(samples) - len(filtered_samples)) < 200 and \
abs(cte - 0.967823751) <= 0.001 and abs(phi - -0.211146388) <= 0.001:
print("#Original:", len(samples), "#Filtered:", len(filtered_samples))
print("#Original:", len(samples), "#Filtered:", len(filtered_samples))
filtered_truth_samples.append((truth, filtered_samples))
else:
# print("Skip partition. #Original:", len(samples), "#Filtered:", len(filtered_samples))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment