Ejemplo n.º 1
0
import utils


def dp_change(money, coins):
    best_num_coins = [0] * money
    for m in range(0, money):
        if m + 1 in coins:
            best_num_coins[m] = 1
            continue
        best_num_coins[m] = float('inf')
        for coin in coins:
            if m + 1 >= coin:
                a = best_num_coins[m - coin] + 1
                best_num_coins[m] = min(best_num_coins[m], a)

    return best_num_coins[money - 1]


if __name__ == '__main__':
    money, coins = utils.read_input_data()
    result = dp_change(money, coins)
    utils.write_output_data(result)
    parser.add_argument('-oq', '--oq', required=True, help='output query file')
    args = vars(parser.parse_args())

    # if dataset file exists, otherwise exit
    dataset = args['dataset']
    # dataset = 'train-images-idx3-ubyte'
    if (os.path.isfile(dataset) == False):
        die("\n[+] Error: This dataset file does not exist\n\nExiting...", -1)

    queryset = args['queryset']
    if (os.path.isfile(queryset) == False):
        die("\n[+] Error: This queryset file does not exist\n\nExiting...", -1)

    # read the first 16 bytes (magic_number, number_of_images, rows, columns)
    dataset, _, rows, cols = dataset_reader(dataset)
    queryset, _, rows, cols = dataset_reader(queryset)
    testSize = 0.2

    trainSet, testSet = process_data(dataset, rows, cols, testSize)

    model = cnn_train_simulation(trainSet, testSet)

    half_model = keras.Model(inputs=model.layers[0].input,
                             outputs=model.get_layer("bottleneck").output)

    bottleneck_dataset_outputs = half_model.predict(dataset)
    bottleneck_query_outputs = half_model.predict(queryset)

    write_output_data(args['od'], bottleneck_dataset_outputs)
    write_output_data(args['oq'], bottleneck_query_outputs)
Ejemplo n.º 3
0
        elif from_to[node]["from"] > from_to[node]["to"]:
            odd_to = node
    if odd_from not in graph:
        graph[odd_from] = []
    graph[odd_from].append(odd_to)
    return odd_from, odd_to


def euler_path(strings):
    graph = {}
    for string in strings:
        frm = string.split(' -> ')[0]
        to = string.split(' -> ')[1].split(',')
        graph[frm] = to
    frm, to = add_extra_edge_to_graph(graph)
    cycle = []
    while not empty(graph):
        start = frm if len(cycle) == 0 \
            else max(cycle, key=lambda k: len(graph[k]))
        new_cycle = find_cycle(graph, start)
        cycle = new_cycle if len(cycle) == 0 else append_cycle(
            cycle, new_cycle)
    cycle.pop(0)
    return cycle


if __name__ == '__main__':
    strings = utils.read_input_data()
    result = euler_path(strings)
    utils.write_output_data('->'.join(result))
Ejemplo n.º 4
0
    words = {"v": '', "w": ''}
    restore_words(words, b, v, w, n - 1, m - 1)
    words["v"] = words["v"][::-1]
    words["w"] = words["w"][::-1]
    score = s[n - 1][m - 1]
    return score, words

def restore_words(words, b, v, w, i, j):
    if i == 0 and j == 0:
        return
    if b[i][j] == "↖":
        words["v"] += v[i - 1]
        words["w"] += w[j - 1]
        restore_words(words, b, v, w, i - 1, j - 1)
    elif b[i][j] == "←" or i == 0:
        words["v"] += '-'
        words["w"] += w[j - 1]
        restore_words(words, b, v, w, i, j - 1)
    else:
        words["v"] += v[i - 1]
        words["w"] += '-'
        restore_words(words, b, v, w, i - 1, j)


if __name__ == '__main__':
    v, w = utils.read_input_data()
    score_matrix = utils.read_scoring_matrix()
    score, words = global_alignment(v, w, score_matrix)
    utils.write_output_data(score, words)