def closest_by_code(klass, search_string, n=100):
        d = []

        for obj in klass.objects.all():

            args = [str(obj.code), search_string]
            alt_args = [str(obj.code) + str(obj.satellite_number), search_string]

            args_dists = utils.calc_dists(*args)
            alt_dists = utils.calc_dists(*alt_args)

            # use the shortest of these distances
            d.append((search_string, obj,\
                min([args_dists[0], alt_dists[0]]),\
                min([args_dists[1], alt_dists[1]]),\
                max([args_dists[2], alt_dists[2]])))

        return utils.closest_matches(d, n)
    def closest_by_spelling(klass, search_string, n=100):
        d = []

        for obj in klass.objects.all():
            args = [str(obj.name).upper(), search_string.upper()]
            # also calculate distance between search_string and 
            # the best guess of a surname (longest word in name)
            name_list = str(obj.name).upper().replace('.', ' ').split()
            surname_guess = max(name_list, key=len) 

            alt_args = [surname_guess, search_string.upper()]

            args_dists = utils.calc_dists(*args)
            alt_dists = utils.calc_dists(*alt_args)

            # use the shortest of these distances
            d.append((search_string, obj,\
                min([args_dists[0], alt_dists[0]]),\
                min([args_dists[1], alt_dists[1]]),\
                max([args_dists[2], alt_dists[2]])))

        return utils.closest_matches(d, n)
    def closest_by_spelling(klass, search_string, n=100):
        d = []

        for obj in klass.objects.all():
            args = [str(obj.name).upper(), search_string.upper()]

            args_dists = utils.calc_dists(*args)

            # use the shortest of these distances
            d.append((search_string, obj,\
                args_dists[0], args_dists[1],\
                args_dists[2]))

        return utils.closest_matches(d, n)
                                           sigma=None,
                                           preproc=combo)
        else:
            # TODO: The route object can not be passed intothe test_nav function here only the starting coordinates
            # are needed by the test_nav function
            traj, nav = agent.test_nav(route, nav, t=t, r=r, preproc=combo)

        toc = time.perf_counter()
        time_compl = toc - tic
        # Get the errors and the minimum distant index of the route memory
        errors, min_dist_index = route.calc_errors(traj)
        # Difference between matched index and minimum distance index and distance between points
        matched_index = nav.get_index_log()
        abs_index_diffs = np.absolute(
            np.subtract(nav.get_index_log(), min_dist_index))
        dist_diff = calc_dists(route.get_xycoords(), min_dist_index,
                               matched_index)
        mean_route_error = np.mean(errors)
        log['route_id'].extend([route.get_route_id()])
        log['blur'].extend([combo.get('blur')])
        log['edge'].extend([combo.get('edge_range')])
        log['res'].append(combo.get('shape'))
        log['window'].extend([window])
        log['matcher'].extend([matcher])
        log['mean_error'].append(mean_route_error)
        log['seconds'].append(time_compl)
        log['window_log'].append(window_log)
        log['tx'].append(traj['x'].tolist())
        log['ty'].append(traj['y'].tolist())
        log['th'].append(traj['heading'].tolist())
        log['matched_index'].append(matched_index)
        log['abs_index_diff'].append(abs_index_diffs.tolist())
Example #5
0
def bench(params, routes_path, route_ids):
    log = {'route_id': [], 'blur': [], 'edge': [], 'res': [], 'window': [],
           'matcher': [], 'mean_error': [], 'seconds': [], 'errors': [],
           'dist_diff': [], 'abs_index_diff': [], 'window_log': [],
           'tx': [], 'ty': [], 'th': []}
    agent = aw.Agent()

    grid = get_grid_dict(params)
    total_jobs = len(grid) * len(route_ids)
    jobs = 0
    #  Go though all combinations in the chunk
    for combo in grid:

        matcher = combo['matcher']
        window = combo['window']
        t = combo['t']
        r = combo['r']
        segment_length = combo.get('segment_l')
        window_log = None
        for route_id in route_ids:  # for every route
            route_path = routes_path + '/route' + str(route_id) + '/'
            route = Route(route_path, route_id)

            tic = time.perf_counter()
            # Preprocess images
            route_imgs = pre_process(route.get_imgs(), combo)
            # Run navigation algorithm
            if window:
                nav = spm.SequentialPerfectMemory(route_imgs, matcher, deg_range=(-180, 180), window=window)
            else:
                nav = pm.PerfectMemory(route_imgs, matcher, deg_range=(-180, 180))

            if segment_length:
                traj, nav = agent.segment_test(route, nav, segment_length=segment_length, t=t, r=r, sigma=None, preproc=combo)
            else:
                start = route.get_starting_coords()
                traj, nav = agent.test_nav(start, nav, t=t, r=r, preproc=combo)

            # agent.run_agent(route, nav, t=t, r=r, preproc=combo)

            toc = time.perf_counter()
            time_compl = toc - tic
            # Get the errors and the minimum distant index of the route memory
            errors, min_dist_index = route.calc_errors(traj)
            # Difference between matched index and minimum distance index and distance between points
            matched_index = nav.get_index_log()
            abs_index_diffs = np.absolute(np.subtract(nav.get_index_log(), min_dist_index))
            dist_diff = calc_dists(route.get_xycoords(), min_dist_index, matched_index)
            mean_route_error = np.mean(errors)
            log['route_id'].extend([route_id])
            log['blur'].extend([combo.get('blur')])
            log['edge'].extend([combo.get('edge_range')])
            log['res'].append(combo.get('shape'))
            log['window'].extend([window])
            log['matcher'].extend([matcher])
            log['mean_error'].append(mean_route_error)
            log['seconds'].append(time_compl)
            log['window_log'].append(window_log)
            log['tx'].append(traj['x'].tolist())
            log['ty'].append(traj['y'].tolist())
            log['th'].append(traj['heading'].tolist())
            log['abs_index_diff'].append(abs_index_diffs.tolist())
            log['dist_diff'].append(dist_diff.tolist())
            log['errors'].append(errors)

            # Increment the complete jobs shared variable
            jobs += 1
            print('jobs completed: {}/{}'.format(jobs, total_jobs))
    return log