Пример #1
0
def align(pc_source, pc_target, config_params):
    all_iterations_results = []
    pc_source_aligned_rigid = copy.deepcopy(pc_source)
    mean_error_prev = 0

    for i in range(config_params['max_iterations']):
        print(f'rigid icp iteration: {i}')
        distances, indices = utls.get_knn(pc_source_aligned_rigid, pc_target)
        target_closest = utls.get_closest(pc_target, indices)
        transform = best_fit_transform(pc_source_aligned_rigid, target_closest)
        pc_source_aligned_rigid = transform_points(pc_source_aligned_rigid,
                                                   transform)

        if config_params['debug_mode']:
            all_iterations_results.append(pc_source_aligned_rigid)
        else:
            all_iterations_results = [pc_source_aligned_rigid]

        mean_error = np.mean(distances)
        print('mean error: {}'.format(mean_error))
        if np.abs(mean_error - mean_error_prev) < config_params['tolerance']:
            print('error less than tolerance')
            break
        mean_error_prev = mean_error

    return all_iterations_results
Пример #2
0
def get_odds_energy(deposited, reconstructed):
    """
    Takes an energy deposited and energy reconstructed.
    Loads the datafile and reads off the uncertainty from the second column. 
    The data is in %E_depo, so we scale this to be a ratio and then by that deposted energy
    """
    if not isinstance(deposited, (float, int)):
        raise Exception()
    if not isinstance(reconstructed, (float, int)):
        raise Exception()
    if use_scan:
        x_id = get_loc(deposited, _data_depo, True)
        y_id = get_loc(reconstructed, _data_reco, True)

        return (_data_prob[x_id][y_id])
    else:
        sigma = get_closest(deposited, data[0], data[1]) * deposited * 0.01

        s2 = np.log(1 + (sigma / deposited)**2)
        mu = np.log((deposited**2) / np.sqrt(deposited**2 + sigma**2))
        # now, we assume that the uncertainty follows a log normal distribution, and calculate the PDF here

        #prob = rtwo*(1./sigma)*exp(-0.5*((reconstructed - deposited)/sigma)**2)
        prob = rtwo * (1. / np.sqrt(s2)) * exp(-0.5 * (
            (np.log(reconstructed) - mu)**2) / s2) / reconstructed

    return (prob)
Пример #3
0
def match(command):
    is_proper_command = ('brew' in command.script
                         and 'Unknown command' in command.stderr)

    if is_proper_command:
        broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
                                command.stderr)[0]
        return bool(get_closest(broken_cmd, _brew_commands()))
    return False
def match(command):
    is_proper_command = ('brew' in command.script and
                         'Unknown command' in command.stderr)

    if is_proper_command:
        broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
                                command.stderr)[0]
        return bool(get_closest(broken_cmd, _brew_commands()))
    return False
Пример #5
0
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
Пример #6
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file, get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
Пример #7
0
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git.", command.stderr)[0]
    closest_branch = utils.get_closest(missing_file,
                                       get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    else:
        return shell.and_('git branch {}',
                          '{}').format(missing_file, command.script)
Пример #8
0
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd,
                              stash_commands,
                              fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
Пример #9
0
def get_new_command(command):
    old_command = command.script_parts[0]

    # One from history:
    already_used = get_closest(
        old_command, _get_used_executables(command),
        fallback_to_first=False)
    if already_used:
        new_cmds = [already_used]
    else:
        new_cmds = []

    # Other from all executables:
    new_cmds += [cmd for cmd in get_close_matches(old_command,
                                                  get_all_executables())
                 if cmd not in new_cmds]

    return [' '.join([new_command] + command.script_parts[1:])
            for new_command in new_cmds]
Пример #10
0
def align(pc_source, pc_target, orig_config_params):
    all_iterations_results = []
    pc_source_aligned = copy.deepcopy(pc_source)
    pc_source_vec = tf.reshape(pc_source, [-1])
    source_laplacian_mat = calc_laplacian_mat(pc_source, orig_config_params['laplacian_k'])
    for i in range(orig_config_params['max_iterations']):
        print(f'Non rigid icp iteration #{i}')
        config_params = update_config_params(orig_config_params, i)
        distances, indices = utls.get_knn(pc_source_aligned, pc_target)

        # fit term:
        target_closest = utls.get_closest(pc_target, indices)
        target_closest_in = utls.mask_outliers(config_params['diff_thresh'], pc_source_aligned, target_closest)
        target_closest_vec = tf.reshape(target_closest_in, [-1])
        point_to_point_term = calc_p_to_point_mat(target_closest_vec)
        weighted_fit_mat = (tf.cast(config_params['p_to_point_w'], dtype=tf.float64) * point_to_point_term)

        # stiffness term:
        pc_source_aligned_vec = tf.reshape(pc_source_aligned, [-1])
        stiffness_term = calc_stiff_mat(source_laplacian_mat)
        weighted_stiffness_mat = (tf.cast(config_params['stiff_w'], dtype=tf.float64) * stiffness_term)

        a_mat = tf.sparse.add(weighted_fit_mat, weighted_stiffness_mat)

        # fiducial points term:
        if config_params['fid_indices'] is not None:
            fid_vals_vec = calc_fid_vals_vec(pc_target, pc_source, config_params['fid_indices'])  # TODO
            fid_points_term = calc_fid_points_mat(fid_vals_vec)
            weighted_fid_points_mat = (tf.cast(config_params['fid_points_w'], dtype=tf.float64) * fid_points_term)
            a_mat = tf.sparse.add(a_mat, weighted_fid_points_mat)
        else:
            fid_vals_vec = None
            weighted_fid_points_mat = None

        b = get_b(a_mat, weighted_fit_mat, weighted_stiffness_mat, weighted_fid_points_mat,
                  target_closest_vec, pc_source_vec, fid_vals_vec, pc_source_vec_current=pc_source_aligned_vec)
        # ------------- solve optimization problem: Ax = b -------------
        per_point_transform = solve_optimization(a_mat, b)
        pc_source_aligned = transform_points(pc_source_aligned, per_point_transform)
        all_iterations_results.append(pc_source_aligned)

    return all_iterations_results
Пример #11
0
def get_new_command(command):
    old_command = command.script_parts[0]

    # One from history:
    already_used = get_closest(old_command,
                               _get_used_executables(command),
                               fallback_to_first=False)
    if already_used:
        new_cmds = [already_used]
    else:
        new_cmds = []

    # Other from all executables:
    new_cmds += [
        cmd for cmd in get_close_matches(old_command, get_all_executables())
        if cmd not in new_cmds
    ]

    return [
        ' '.join([new_command] + command.script_parts[1:])
        for new_command in new_cmds
    ]
Пример #12
0
					if event.type == pygame.MOUSEBUTTONDOWN:
						bcol.red(event.pos)
			if player:
				if event.type == pygame.KEYDOWN:
					if   event.key == K_UP:    up    = True
					elif event.key == K_DOWN:  down  = True
					elif event.key == K_LEFT:  left  = True
					elif event.key == K_RIGHT: right = True
				if event.type == pygame.KEYUP:
					if   event.key == K_UP:    up    = False
					elif event.key == K_DOWN:  down  = False
					elif event.key == K_LEFT:  left  = False
					elif event.key == K_RIGHT: right = False
			if leveleditor:
				if event.type == pygame.MOUSEBUTTONDOWN:
					elem = utils.get_closest(drawables,Pos(event.pos))
					if event.button == 1:
						move = elem
					if event.button == 2:
						bpos = Pos(event.pos)
						drawables.append(Blockade(bpos,0))
					elif event.button == 3:
						drawables.remove(elem)
					elif event.button == 4:
						elem.rot += utils.rad(15)
					elif event.button == 5:
						elem.rot -= utils.rad(15)
				if event.type == pygame.MOUSEBUTTONUP:
					if event.button == 1:
						move = 0
				if move != 0:
Пример #13
0
def get_new_command(command):
    return get_closest(command.script,
                       get_valid_history_without_current(command))
Пример #14
0
def get_new_command(command):
    script = command.script_parts[:]
    possibilities = extract_possibilities(command)
    script[1] = get_closest(script[1], possibilities)
    return ' '.join(script)
Пример #15
0
def get_new_command(command):
    return get_closest(command.script,
                       get_valid_history_without_current(command))
Пример #16
0
def _get_similar_formula(formula_name):
    return get_closest(formula_name, _get_formulas(), 1, 0.85)
Пример #17
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
Пример #18
0
def get_new_command(command):
    npm_commands = _get_available_commands(command.stdout)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
Пример #19
0
def _get_similar_formula(formula_name):
    return get_closest(formula_name, _get_formulas(), 1, 0.85)