def main():
    numbers = read_numbers()
    three = numbers[3][0]

    place = [[0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 0, 0]]
    for i in three:
        print(i)
    print()

    BUBBLE_SIZE = 7

    q = hello(three, place)
    print("SIZE: ", len(q), len(q[0]))
    for i in q:
        print(i)
    bubbled_place = make_bubble(place, BUBBLE_SIZE)
    out_matrix(bubbled_place)
    out_matrix(zip_bubbled_data(bubbled_place, BUBBLE_SIZE))

    # важно чтобы id клеток разных регионов не пересекались!!!
    r = Region(len(merge_input([make_bubble(place, BUBBLE_SIZE), hello(three, place)])), 5, 0)

    for step in range(200):
        s = 0
        x = -1
        y = -1
        for i, I in enumerate(place):
            for j, J in enumerate(I):
                if place[i][j] == 1:
                    x, y = i, j
                    break

        print("-----" * 10)
        for i in place:
            print(i)
        print("-----" * 10)
        for i, I in enumerate(place):
            for j, J in enumerate(I):
                place[i][j] = 0

        if (x == -1 and y == -1) or step < 10:
            while 1:
                x = randrange(len(place))
                y = randrange(len(place))
                place[x][y] = 1
                if get_sum(hello(three, place)):
                    break
                place[x][y] = 0
        else:
            place[x][y] = 1
        r.step_forward(merge_input([make_bubble(place, BUBBLE_SIZE), hello(three, place)]))

        r.out_prediction()
        new_place = zip_bubbled_data(do_cut(r.get_binary_prediction(), len(make_bubble(place, BUBBLE_SIZE))),
                                     BUBBLE_SIZE)
        place = new_place
Exemple #2
0
    cur_reward = 0
    x, y = env.cur_position_discrete
    finish = env.cur_task.finish
    # print("start:", x, y)
    # if current_episode * 2 > episode_count:
    # print("BEGIN" * 5)
    P = [[0 for ___ in range(size)] for _____ in range(size)]

    a = np.zeros(shape=(10, 10))
    tx, ty = env.cur_position_discrete
    a[tx, ty] = 1
    temporal_pooler_region.step_forward(a)

    for current_step in range(max_steps):

        p = temporal_pooler_region.get_binary_prediction()
        p_actions = []
        x, y = env.cur_position_discrete
        P[x][y] = 1
        for i in BY_PIXEL_ACTION_DIFFS:
            dx, dy = BY_PIXEL_ACTION_DIFFS[i]
            try:
                if p[x + dx][y + dy]:
                    p_actions.append(i)
            except IndexError:
                pass

        if not len(p_actions) or (
            current_episode < 0.7 * episode_count and numpy.random.randint(max_steps) / 4 < current_step
        ):
            action = numpy.random.randint(agent.number_of_actions)