def main(): # Parse command-line arguments. args = parse_args() Hfile = os.path.join(args.datadir, "H.txt") obsfile = os.path.join(args.datadir, "obsmat.txt") # Parse homography matrix. H = np.loadtxt(Hfile) Hinv = np.linalg.inv(H) # Parse pedestrian annotations. frames, timeframes, timesteps, agents = ewap.parse_annotations( Hinv, obsfile) # Agents 319-338 timeline = range(11205, 11554) print 'Running experiment...' util.reset_timer() num_samples = 100 variances = np.array([0.1, 0.3, 1, 3, 10, 30, 100]) entropies = np.zeros_like(variances) for i, sigma2 in enumerate(variances): M = np.zeros((2, 2)) total_samples = 0 for frame in timeline: t = frames[frame] if t == -1: continue T = len(timeline) print '{:.1%} complete'.format( (T * i + frame - timeline[0]) / (T * len(variances))) for _ in range(num_samples): # predictions = util.make_predictions(t, timesteps, agents) predictions = util.fake_predictions(t, timesteps, agents, sigma2) for a, plan in enumerate(predictions.plan): if plan.shape[0] > 1: error = predictions.true_paths[a][1, 0:2] - plan[1, 0:2] M += np.outer(error, error) total_samples += 1 M /= total_samples entropies[i] = 0.5 * np.log((2 * np.pi * np.e)**2 * np.linalg.det(M)) # print 'entropy is', entropy # print 'variance:' # print M print 'EXPERIMENT COMPLETE.' util.report_time() results = np.column_stack((variances, entropies)) print results np.savetxt('experiments/entropy_vs_variance.txt', results)
def run_experiment(cap, disp, timeframes, timesteps, agents): # We're going to compare ourselves to the agents with the following IDs. print 'Running experiment...' util.reset_timer() agents_to_test = range(319, 331) # agents_to_test = [48, 49] true_paths = [] planned_paths = [] one_step_paths = [] # IGP_scores = np.zeros((len(agents_to_test), 2)) # ped_scores = np.zeros((len(agents_to_test), 2)) display.plot_prediction_metrics([], [], []) for i, agent in enumerate(agents_to_test): print 'Agent ', agent ped_path = agents[agent] path_length = ped_path.shape[0] start = 3 # Initializes path with start+1 points. final_path = np.zeros((path_length, 3)) final_path[0:start+1, :] = ped_path[0:start+1,1:4] one_step_final_path = final_path.copy() # Run IGP through the path sequence. for t in range(start, path_length-1): frame_num = timeframes[int(ped_path[t,0])] print 'doing frame', frame_num disp.set_frame(frame_num) final_path[t+1], one_step_final_path[t+1] = disp.do_frame(agent, final_path[:t+1], False, True) if cv2.waitKey(1) != -1: print 'Canceled!' return # Compute the final score for both IGP and pedestrian ground truth. print 'Agent', agent, 'done.' # start_time = int(ped_path[0,0]) # other_peds = [agents[a] for a in timesteps[start_time] if a != agent] # other_paths = [util.get_path_at_time(start_time, fullpath)[1][:,1:4] for fullpath in other_peds] # IGP_scores[i] = util.length_and_safety(final_path, other_paths) # ped_scores[i] = util.length_and_safety(ped_path[:,1:4], other_paths) true_paths.append(ped_path[:,1:4]) planned_paths.append(final_path) one_step_paths.append(one_step_final_path) pred_errs = util.calc_pred_scores(true_paths, planned_paths, util.prediction_errors) path_errs = util.calc_pred_scores(true_paths, planned_paths, util.path_errors) display.plot_prediction_metrics(pred_errs, path_errs, agents_to_test[0:i+1]) one_step_errors = util.calc_pred_scores(true_paths, one_step_paths, util.prediction_errors) pl.figure(2) pl.clf() display.plot_prediction_error('One-Step Prediction Errors', one_step_errors, agents_to_test[0:i+1]) pl.draw() # results = np.column_stack((agents_to_test, ped_scores, IGP_scores)) pred_results = np.column_stack((agents_to_test, pred_errs.T)) path_results = np.column_stack((agents_to_test, path_errs.T)) # np.savetxt('experiment.txt', results) np.savetxt('prediction_errors.txt', pred_results) np.savetxt('path_errors.txt', path_results) print 'EXPERIMENT COMPLETE.' util.report_time()
def main(): # Parse command-line arguments. args = parse_args() Hfile = os.path.join(args.datadir, "H.txt") obsfile = os.path.join(args.datadir, "obsmat.txt") # Parse homography matrix. H = np.loadtxt(Hfile) Hinv = np.linalg.inv(H) # Parse pedestrian annotations. frames, timeframes, timesteps, agents = ewap.parse_annotations(Hinv, obsfile) # Agents 319-338 timeline = range(11205, 11554) print 'Running experiment...' util.reset_timer() num_samples = 100 variances = np.array([0.1, 0.3, 1, 3, 10, 30, 100]) entropies = np.zeros_like(variances) for i, sigma2 in enumerate(variances): M = np.zeros((2,2)) total_samples = 0 for frame in timeline: t = frames[frame] if t == -1: continue T = len(timeline) print '{:.1%} complete'.format((T*i+frame-timeline[0])/(T*len(variances))) for _ in range(num_samples): # predictions = util.make_predictions(t, timesteps, agents) predictions = util.fake_predictions(t, timesteps, agents, sigma2) for a,plan in enumerate(predictions.plan): if plan.shape[0] > 1: error = predictions.true_paths[a][1,0:2] - plan[1,0:2] M += np.outer(error, error) total_samples += 1 M /= total_samples entropies[i] = 0.5*np.log((2*np.pi*np.e)**2 * np.linalg.det(M)) # print 'entropy is', entropy # print 'variance:' # print M print 'EXPERIMENT COMPLETE.' util.report_time() results = np.column_stack((variances, entropies)) print results np.savetxt('experiments/entropy_vs_variance.txt', results)
def run_experiment(cap, disp, timeframes, timesteps, agents): # We're going to compare ourselves to the agents with the following IDs. print 'Running experiment...' util.reset_timer() agents_to_test = range(319, 331) # agents_to_test = [48, 49] true_paths = [] planned_paths = [] one_step_paths = [] # IGP_scores = np.zeros((len(agents_to_test), 2)) # ped_scores = np.zeros((len(agents_to_test), 2)) display.plot_prediction_metrics([], [], []) for i, agent in enumerate(agents_to_test): print 'Agent ', agent ped_path = agents[agent] path_length = ped_path.shape[0] start = 3 # Initializes path with start+1 points. final_path = np.zeros((path_length, 3)) final_path[0:start + 1, :] = ped_path[0:start + 1, 1:4] one_step_final_path = final_path.copy() # Run IGP through the path sequence. for t in range(start, path_length - 1): frame_num = timeframes[int(ped_path[t, 0])] print 'doing frame', frame_num disp.set_frame(frame_num) final_path[t + 1], one_step_final_path[t + 1] = disp.do_frame( agent, final_path[:t + 1], False, True) if cv2.waitKey(1) != -1: print 'Canceled!' return # Compute the final score for both IGP and pedestrian ground truth. print 'Agent', agent, 'done.' # start_time = int(ped_path[0,0]) # other_peds = [agents[a] for a in timesteps[start_time] if a != agent] # other_paths = [util.get_path_at_time(start_time, fullpath)[1][:,1:4] for fullpath in other_peds] # IGP_scores[i] = util.length_and_safety(final_path, other_paths) # ped_scores[i] = util.length_and_safety(ped_path[:,1:4], other_paths) true_paths.append(ped_path[:, 1:4]) planned_paths.append(final_path) one_step_paths.append(one_step_final_path) pred_errs = util.calc_pred_scores(true_paths, planned_paths, util.prediction_errors) path_errs = util.calc_pred_scores(true_paths, planned_paths, util.path_errors) display.plot_prediction_metrics(pred_errs, path_errs, agents_to_test[0:i + 1]) one_step_errors = util.calc_pred_scores(true_paths, one_step_paths, util.prediction_errors) pl.figure(2) pl.clf() display.plot_prediction_error('One-Step Prediction Errors', one_step_errors, agents_to_test[0:i + 1]) pl.draw() # results = np.column_stack((agents_to_test, ped_scores, IGP_scores)) pred_results = np.column_stack((agents_to_test, pred_errs.T)) path_results = np.column_stack((agents_to_test, path_errs.T)) # np.savetxt('experiment.txt', results) np.savetxt('prediction_errors.txt', pred_results) np.savetxt('path_errors.txt', path_results) print 'EXPERIMENT COMPLETE.' util.report_time()
def main(): # Parse command-line arguments. args = parse_args() Hfile = os.path.join(args.datadir, "H.txt") obsfile = os.path.join(args.datadir, "obsmat.txt") # Parse homography matrix. H = np.loadtxt(Hfile) Hinv = np.linalg.inv(H) # Parse pedestrian annotations. frames, timeframes, timesteps, agents = ewap.parse_annotations(Hinv, obsfile) test_sequences = np.array([ range(2112, 2395), range(3648, 3769), range(4163, 4374), range(6797, 7164), range(7301, 7608), range(8373, 8620), range(8859, 9544), range(9603, 10096), range(10101, 10528), range(11205, 11500), range(11835, 12172), range(12201, 12382), ]) total_t = 0 for s in test_sequences: total_t += len(s) model = models.model16 print 'Running experiment...' util.reset_timer() num_samples = 5 iters = 0 total_samples = 0 entropies = np.zeros(test_sequences.shape[0]) for i,timeline in enumerate(test_sequences): M = np.zeros((2,2)) for frame in timeline: iters += 1 t = frames[frame] if t == -1: continue for _ in range(num_samples): predictions = util.make_predictions(t, timesteps, agents, model) for a,plan in enumerate(predictions.plan): if plan.shape[0] > 1: error = predictions.true_paths[a][1,0:2] - plan[1,0:2] M += np.outer(error, error) total_samples += 1 print 'frame {}: {:.1%} complete'.format(frame, iters/total_t) M /= total_samples entropies[i] = 0.5*np.log((2*np.pi*np.e)**2 * np.linalg.det(M)) # print 'entropy is', entropy # print 'variance:' # print M print 'EXPERIMENT COMPLETE.' util.report_time() np.savetxt('experiments/hyperparam-test-194-202-joint-2.txt', entropies)