Esempio n. 1
0
def get_XY(problems, max_nb_inputs, max_nb_tokens):
    y = []
    rows_type = []
    rows_val = []
    # print(problems)
    for problem in problems:
        examples = [util.decode_example(x) for x in problem['examples']]
        # print(examples[0])
        row_type, row_val = get_row(examples, max_nb_inputs, L)
        # print(row)
        f_list = util.get_program_vec(problem['program'])
        y.append(encode_program(f_list, max_nb_tokens))
        rows_type.append(row_type)
        rows_val.append(row_val)

    y = np.array(y)
    rows_type = np.array(rows_type)
    rows_val = np.array(rows_val)

    # preprocess
    rows_val += np.ones_like(rows_val) * constants.INTMAX

    # print(1111, X)
    # print(rows_val)
    # print(y)
    return rows_type, rows_val, y
Esempio n. 2
0
def get_XY(problems, max_nb_inputs):
    y = []
    rows = []
    for problem in problems:
        examples = [util.decode_example(x) for x in problem['examples']]
        row = encoding.get_row(examples, max_nb_inputs, L)
        y.append(problem['attribute'])
        rows.append(row)

    # convert
    X = collections.defaultdict(list)
    for row in rows:
        for k, v in row.items():
            X[k].append(v)

    for k, v in X.items():
        X[k] = np.array(v)

    # preprocess
    for k, v in X.items():
        if not k.endswith('type'):
            # keras embedding requires nonnegative ints so we inc
            # by INTMAX.  This is less than NULL which is 513
            v[v < constants.NULL] += constants.INTMAX

    return X, np.array(y)
def solve_problem(problem, T, mode='dfs', gas=np.inf):
    examples = [util.decode_example(x) for x in problem['examples']]
    predictions = problem.get('prediction')  # (L2, len(f)+8)
    start = time.time()

    search_func = search.beam_search

    solution, steps_used = search_func(examples, T, predictions, gas)
    end = time.time()
    if solution:
        solution = solution.prefix
    return solution, end - start, steps_used
Esempio n. 4
0
def solve_problem(problem, T, mode='dfs', gas=np.inf):
    examples = [util.decode_example(x) for x in problem['examples']]
    predictions = problem.get('prediction', np.zeros(len(impl.FUNCTIONS)))
    scores = dict(zip(impl.FUNCTIONS, predictions))
    ctx = context.Context(scores)
    start = time.time()
    if mode == 'dfs':
        search_func = search.dfs
    elif mode == 'sort-and-add':
        search_func = search.sort_and_add
    else:
        raise ValueError('invalid search mode {}'.format(mode))
    solution, steps_used = search_func(examples, T, ctx, gas)
    end = time.time()
    if solution:
        solution = solution.prefix
    return solution, end - start, steps_used
Esempio n. 5
0
def solve_problem(problem, T, mode='dfs', gas=np.inf):
    examples = [util.decode_example(x) for x in problem['examples']]
    predictions = problem.get('prediction', np.zeros(len(impl.FUNCTIONS)))
    if mode != 'beam':
        scores = dict(zip(impl.FUNCTIONS, predictions))
        ctx = context.Context(scores)
    start = time.time()
    if mode == 'dfs':
        search_func = search.dfs
        solution, steps_used = search_func(examples, T, ctx, gas)
    elif mode == 'sort-and-add':
        search_func = search.sort_and_add
        solution, steps_used = search_func(examples, T, ctx, gas)
    else:
        search_func = search.beam_search
        solution, steps_used = search_func(examples, T, predictions, gas)
    end = time.time()
    if solution:
        solution = solution.prefix
    return solution, end - start, steps_used
Esempio n. 6
0
def get_XY(problems, max_nb_inputs):
    y = []
    rows_type = []
    rows_val = []
    # print(problems)
    for problem in problems:
        examples = [util.decode_example(x) for x in problem['examples']]
        # print(examples[0])
        row_type, row_val = get_row(examples, max_nb_inputs, L)
        # print(row)
        y.append(problem['attribute'])
        rows_type.append(row_type)
        rows_val.append(row_val)

    y = np.array(y)
    rows_type = np.array(rows_type)
    rows_val = np.array(rows_val)

    # preprocess
    rows_val += np.ones_like(rows_val) * constants.INTMAX

    # print(1111, X)
    return rows_type, rows_val, y
Esempio n. 7
0
def get_XY(problems, max_nb_inputs, max_nb_tokens):
    y = [[], []]
    rows_type = []
    rows_val = []
    # print(problems)
    for problem in problems:
        examples = [util.decode_example(x) for x in problem['examples']]
        # print(examples[0])
        row_type, row_val = get_row(examples, max_nb_inputs, L)
        # print(row)
        next_y = encode_program(problem['program'])
        y[0].append(next_y[0])
        y[1].append(next_y[1])
        rows_type.append(row_type)
        rows_val.append(row_val)

    rows_type = np.array(rows_type)
    rows_val = np.array(rows_val)

    # preprocess
    rows_val += np.ones_like(rows_val) * constants.INTMAX

    # print(1111, X)
    return rows_type, rows_val, y  #sketchy = [index]  argy = [11100]