def f1(route_id): matcher = 'rmse' pre_proc = {'blur': True, 'shape': (180, 50)} window = 14 dist = 100 w, x_inlimit, y_inlimit, world_grid_imgs, x_route, y_route, \ route_heading, route_images = load_route(route_id=route_id, grid_pos_limit=dist) pre_world_grid_imgs = pre_process(world_grid_imgs, pre_proc) pre_route_images = pre_process(route_images, pre_proc) nav = spm.SequentialPerfectMemory(pre_route_images, matcher, window=window) recovered_heading, window_log = nav.navigate(pre_world_grid_imgs) print(mean_degree_error(x_inlimit, y_inlimit, x_route, y_route, route_heading, recovered_heading))
def mean_residual_image(ref_img, current_img, d): current_img = rotate(d, current_img) current_img = current_img.flatten() ref_img = ref_img.flatten() current_mean = np.mean(current_img) ref_mean = np.mean(ref_img) res_img = ((ref_img - ref_mean) * (current_img - current_mean)) / len(ref_img) res_img = np.reshape(res_img, (75, 360)) fig = plt.figure(figsize=(15, 5)) ax = sns.heatmap(res_img) # ax.figure.savefig('idf_v_correlation_figures/mean residual image ' + str(d) + '.png') # save_image('idf_v_correlation_figures/mean residual image ' + str(d) + '.png', res_img) route_img = pre_process([route_img], pre_proc)[0] grid_img = pre_process([grid_img], pre_proc)[0] logs = ridf(route_img, grid_img, 360, 1) print(logs.index(min(logs))) fig = plt.figure() plt.plot(range(len(logs)), logs) fig.suptitle('RIDF') plt.xlabel('Degrees') plt.ylabel('IDF') plt.show() # Save residual images residual_image(route_img, grid_img, 134) residual_image(route_img, grid_img, 190) logs = r_cor_coef(route_img, grid_img, 360, 1)
window = 15 dist = 100 figures_path = 'Figures/' check_for_dir_and_create(figures_path) w, x_inlimit, y_inlimit, world_grid_imgs, x_route, y_route, \ route_heading, route_images = load_loop_route(directory, route_id=route_id, grid_pos_limit=dist) zoom = [np.mean(x_route), np.mean(y_route)] plot_map(w, [x_route, y_route], [x_inlimit, y_inlimit], size=(15, 15), route_headings=route_heading, scale=40, zoom=zoom) pre_world_grid_imgs = pre_process(world_grid_imgs, pre_proc) pre_route_images = pre_process(route_images, pre_proc) nav = spm.SequentialPerfectMemory(pre_route_images, matcher, window=window) recovered_heading, window_log = nav.navigate(pre_world_grid_imgs) print( mean_degree_error(x_inlimit, y_inlimit, x_route, y_route, route_heading, recovered_heading)) plot_map(w, [x_route, y_route], [x_inlimit, y_inlimit], size=(15, 15), route_headings=route_heading, grid_headings=recovered_heading, scale=40, zoom=(3000, 5000), save=True)
check_for_dir_and_create(figures_path) # w, x_inlimit, y_inlimit, grid_imgs, x_route, y_route, \ # route_heading, route_images = load_route(route_id=route, grid_pos_limit=dist) w, x_inlimit, y_inlimit, grid_imgs, x_route, y_route, \ route_heading, route_images = load_loop_route(directory, route_id=route, grid_pos_limit=dist) img_path = figures_path + 'Route.png' plot_map(w, [x_route, y_route], [x_inlimit, y_inlimit], size=(6, 6), path=img_path, route_headings=route_heading, scale=40, route_zoom=False, save=True) pre_grid_imgs = pre_process(grid_imgs, pre_proc) pre_route_images = pre_process(route_images, pre_proc) nav = spm.SequentialPerfectMemory(pre_route_images, matcher, window=window) recovered_heading, window_log = nav.navigate(pre_grid_imgs) # nav = pm.PerfectMemory(pre_route_images, matcher) # recovered_heading = nav.navigate(pre_grid_imgs) print( mean_degree_error(x_inlimit, y_inlimit, x_route, y_route, route_heading, recovered_heading)) zoom = [np.mean(x_route), np.mean(y_route)] img_path = figures_path + 'errorRoute.png' plot_map(w, [x_route, y_route], [x_inlimit, y_inlimit], size=(6, 6), path=img_path,
route_id = 3 path = '../new-antworld/exp1/route' + str(route_id) + '/' # path = '../test_data/route'+ str(route_id) + '/' route = load_route_naw(path, route_id=route_id, imgs=True, query=True, max_dist=0.2) plot_route(route) window = 20 matcher = 'mae' sets = {'shape': (180, 50)} #, 'edge_range': (180, 200)} route_imgs = pre_process(route['imgs'], sets) test_imgs = pre_process(route['qimgs'], sets) nav = seqnav.SequentialPerfectMemory(route_imgs, matcher, window=window) recovered_heading, window_log = nav.navigate(test_imgs) traj = {'x': route['qx'], 'y': route['qy'], 'heading': recovered_heading} traj['heading'] = np.array(traj['heading']) plot_route(route, traj) errors, min_dist_index = angular_error(route, traj) print(np.mean(errors)) xs = route['x'][min_dist_index] ys = route['y'][min_dist_index]
# matplotlib.use( 'tkagg' ) # _, x_inlimit, y_inlimit, world_grid_imgs, x_route, y_route, \ # route_heading, route_images = load_route(1) # original_img = route_images[img_indx] route_id = 3 path = '../new-antworld/exp1/route' + str(route_id) + '/' route = load_route_naw(path, route_id=route_id, imgs=True) img_indx = 98 original_img = route['imgs'][img_indx] display_image(original_img) pre_proc = {'edge_range': (220, 240)} edges_img = pre_process(original_img, pre_proc) display_image(edges_img) fig = plt.figure() logs = rmf(original_img, original_img, matcher=cor_dist, d_range=(-180, 180), d_step=1) plt.plot(range(len(logs)), logs, label='original') low_bounds = list(range(150, 240, 20)) for bound in low_bounds: pre_proc = {'edge_range': (bound, bound + 20)} edges_img = pre_process(original_img, pre_proc)
from source2 import load_route_naw, pre_process, animated_window from source2 import seqnav from source2 import antworld2 as aw agent = aw.Agent() route_id = 1 preprocessing = {'shape': (180, 50)} path = '../new-antworld/exp1/route' + str(route_id) + '/' # path = '../test_data/route' + str(route_id) + '/' route = load_route_naw(path, route_id=route_id, imgs=True) # plot_route(route) nav = seqnav.SequentialPerfectMemory # nav = perfect_memory.PerfectMemory # set up the navigator route['imgs'] = pre_process(route['imgs'], preprocessing) nav = nav(route['imgs'], 'mae', window=10, deg_range=(-180, 180)) traj, nav = agent.segment_test(route, nav, segment_length=2, t=20, r=0.1, preproc=preprocessing) window_log = nav.get_window_log() path = 'window-plots/' animated_window(route, window_log, traj=traj, path=path)