def feature_matrix2(trips, n=None): velocities = [compute_velocity(trip) for trip in trips] speeds = [compute_scalar(velocity) for velocity in velocities] maxlen = len(max(speeds, key=len)) if n is None else n print("maxlen:", maxlen) res = np.array([np.fft.fft(s, n=maxlen) for s in speeds]) print(res.shape) return res
def feature_vector(trip): velocity = compute_velocity(trip) velocity5 = n_step_diff(trip, n=5) acceleration = np.gradient(velocity) acceleration5 = np.gradient(velocity5) cos_dt = [cos_between(a, np.array([1, 0])) for a in acceleration5] angle_dt = [np.arccos(c) for c in cos_dt] speed = compute_scalar(velocity) corner_features = corners_features(velocity) acc_features = acceleration_features(velocity, angle_dt, cos_dt, speed) return np.hstack((corner_features, acc_features))
def main(): trips = read_trips(sys.argv[1]) velocities = [compute_velocity(trip) for trip in trips] speeds = [compute_scalar(v) for v in velocities] features = np.array([corners_features(v, s) for v, s in zip(velocities, speeds)]) #print(features) n = random.randint(0, 199) n = 29 print("Trip number is:", n) (corners, angles) = identify_corners(velocities[n]) trip = trips[n] import matplotlib.pyplot as plt plt.scatter(trips[n][:,0], trips[n][:,1])#, c=speeds[n]) for start, end in corners: t = trip[list(range(start, end+1))] plt.plot(t[:,0], t[:,1], 'r', linewidth=4.0) plt.axis('equal') plt.show()
def main(): trips = read_trips(sys.argv[1]) velocities = [compute_velocity(trip) for trip in trips] speeds = [compute_scalar(v) for v in velocities] features = np.array( [corners_features(v, s) for v, s in zip(velocities, speeds)]) #print(features) n = random.randint(0, 199) n = 29 print("Trip number is:", n) (corners, angles) = identify_corners(velocities[n]) trip = trips[n] import matplotlib.pyplot as plt plt.scatter(trips[n][:, 0], trips[n][:, 1]) #, c=speeds[n]) for start, end in corners: t = trip[list(range(start, end + 1))] plt.plot(t[:, 0], t[:, 1], 'r', linewidth=4.0) plt.axis('equal') plt.show()
def feature_vector(trip): velocity = compute_velocity(trip) speed = compute_scalar(velocity) corner_features = corners_features(velocity) acc_features = acceleration_features(speed) return np.hstack((corner_features, acc_features))