def __init__(self, tp, agent_finish):
        self.tp_level_one = tp
        tp_level_one_settings = tp.temporal_settings
        tp_level_one_settings.dendrite_permanence_dec_delta = tp_level_one_settings.dendrite_permanence_inc_delta = 0.0
        tp_level_one_settings.passive_time_to_active_threshold = 10000000000000000000

        dendrite_id_cnt = 0
        self.id_to_dendrite_map = {}
        self.id_to_Cell = {}
        self.dendrites = []

        for i, I in enumerate(self.tp_level_one.columns):
            for j, J in enumerate(I):
                for cell, Cell in enumerate(self.tp_level_one.columns[i][j].cells):
                    self.id_to_Cell[Cell.id] = Cell
                    Cell.position_x_y = [i, j]
                    for dendrite, Dendrite in enumerate(Cell.dendrites):
                        self.dendrites.append(Dendrite)
                        Dendrite.id = dendrite_id_cnt
                        Dendrite.id_to = Cell.id
                        dendrite_id_cnt += 1
                        Dendrite.position_x_y = [i, j]
                        self.id_to_dendrite_map[Dendrite.id] = Dendrite

        self.used = {}

        self.graph_edges = []
        index = 0
        os.system('rm -rf pic/')
        if not os.path.exists('pic/'):
            os.makedirs('pic/')
        for current in self.dendrites:
            self.edges = []
            self.edges2 = []
            # print("id" + str(current.id) + ":" + str(current.position_x_y))
            active_cells = set()
            for i in current.synapses:
                if i.permanence > tp_level_one_settings.synapse_threshold:
                    active_cells.add(i.id_to)
            if len(active_cells) < tp_level_one_settings.dendrite_activate_threshold:
                continue
            # print("acells:" + str(active_cells))
            ans = []
            for den in self.dendrites:
                q = 0
                for j in den.synapses:
                    if j.id_to in active_cells and j.permanence > tp_level_one_settings.synapse_threshold:
                        q += 1
                if q >= tp_level_one_settings.dendrite_activate_threshold:
                    ans.append(den)
            # print("---" * 5)
            # for t in ans:
            # print(t.position_x_y)
            self.dfs(ans)
            # if sys.platform == "linux":

            size = self.tp_level_one.temporal_settings.region_size
            p = [[0 for _ in range(size)] for _ in range(size)]
            for i in range(len(self.edges2)):
                for x in range(len(self.edges2[i])):
                    for y in range(len(self.edges2[i][x])):
                        if self.edges2[i][x][y]:
                            p[x][y] = 1
            # if p[7][4]:
            if len(self.edges) > 0:
                p[agent_finish[0]][agent_finish[1]] = 2

                # p[agent_finish[0]][agent_finish[1]] = 3
                draw_image("pic/image" + str(index), p)

            # draw_graph("pic/refactoring" + str(index), [(self.make_string_(p), "1")])
            index += 1
Beispiel #2
0
            inc_delta,
        )

        temporal_pooler_region.step_forward(a)
        # if current_episode * 2 > episode_count:
        #     temporal_pooler_region.out_prediction()
        inc_delta, temporal_pooler_region.temporal_settings.dendrite_permanence_inc_delta = (
            temporal_pooler_region.temporal_settings.dendrite_permanence_inc_delta,
            inc_delta,
        )
        dec_delta, temporal_pooler_region.temporal_settings.dendrite_permanence_dec_delta = (
            temporal_pooler_region.temporal_settings.dendrite_permanence_dec_delta,
            dec_delta,
        )

        if done == 100:
            print(done)
            print("finish:", x, y)
            a = np.zeros(shape=(10, 10))
            temporal_pooler_region.step_forward(a)
            break

    print("iter: ", current_episode, "reward: ", cur_reward)
    if current_episode > episode_count - 50:
        P[7][4] = 2
        draw_image("pic2/last_path_on_grid" + str(current_episode), P)

    if current_episode == episode_count - 1:
        Foo(temporal_pooler_region, finish)
        break