"\t\tMean(time_step): " + str(interval_mean) + \
                  "\t\tStandard Deviation(time_step): " + str(interval_stddev_to_hundredths)
            print(msg)
            anay_data.msg_list.append(msg)



            # save file and update plot section
            is_save_file_and_update_plot = (episode_idx + 1) % save_file_and_plot_update_interval == 0
            if is_save_file_and_update_plot:
                if is_save_raw_data:
                    CommonUtil.save_json_to_file(game_raw_data.__dict__, save_dir_path + "/" + start_interval_str + "_raw_data.txt")


                plt = PlotUtil.plot(plot_id=1, plot_title = "Time Step in each Episode",
                                    x_label = "Episodes", y_label = "Time Step",
                                    data_list=game_raw_data.episode_total_step_list)

                if is_save_chart_data:
                    plt.savefig(save_dir_path + "/" + start_interval_str + "_episode_data_plot")


                plt = PlotUtil.plot_multi_list(plot_id=2, plot_title="Mean and Standard Deviation of Evaluation Interval",
                                               x_label="Evaluation Interval (each interval contains " + str(data_analysis_interval) + " episode(s))",
                                               y_label="Time Step",
                                               label_data_list_dict = anay_data.name_datalist_dict)
                if is_save_chart_data:
                    plt.savefig(save_dir_path + "/" + start_interval_str + "_analytical_data_plot")


                if is_save_analytica_data:
        exploration_rate = BinaryOutputTabularAgent.derive_explore_rate(episode_idx, initial_epsilon, epsilon_decay, episodes_per_drop)
        game_data.general_data_list.append(exploration_rate)



        # data analysis section
        if (episode_idx+1) % update_interval == 0:
            print(f"Explore rate: {exploration_rate}")
            start_interval: int = episode_idx - update_interval + 2
            start_interval_str: str = CommonUtil.format_int_to_str_length(start_interval, len(str(num_of_iterations)))
            end_interval_str: str = CommonUtil.format_int_to_str_length(episode_idx + 1, len(str(num_of_iterations)))

            plt = PlotUtil.plot(plot_id=1,
                                  plot_title = "Exploration Rate Change",
                                  x_label = "Episodes",
                                  y_label = "Exploration Rate",
                                  data_list=game_data.general_data_list)

            if is_save_chart_data:
                plt.savefig(save_dir_path + "/" + start_interval_str + "_episode_data_plot")


            if user_input_next_operation != "fly":
                user_input_next_operation = input("Enter 'N' to stop. 'fly' to run max episode. Or enter anything run next interval: ")
                if user_input_next_operation == "N":
                    break

                print("\ncontinue...", end='')

Esempio n. 3
0
                host_ts_rating_list_dict[tmp_guest_player_2.algorithm_name +
                                         "(std_dev)"].append(stddev)

            # print("Host Player: ", host_player.algorithm_name,
            #        ".\tBoard size: ", board_size,
            #        ".\tTotal move made: ", len(host_audit_timer.delta_list),
            #       ". \tAvg time per action", host_audit_timer.avg_time())

            if (game_idx + 1) >= data_analysis_interval and (
                    game_idx + 1) % data_analysis_interval == 0:
                print()

                plot_title = host_player.algorithm_name + " vs all"
                plt = PlotUtil.plot_multi_list(
                    plot_id=1,
                    plot_title=plot_title,
                    x_label="Games",
                    y_label="ELO ratings",
                    label_data_list_dict=host_ts_rating_list_dict)
                plt.pause(0.1)

                if is_save_data:
                    plt.savefig(save_dir_path + "/" + start_interval_str +
                                "_plot")
                    CommonUtil.write_txt_file(
                        anay_data_msg_list, save_dir_path + "/" +
                        start_interval_str + "_analytical_data.txt")

            if starting_color == HexBoard.BLUE: starting_color = HexBoard.RED
            elif starting_color == HexBoard.RED: starting_color = HexBoard.BLUE
            else: raise Exception(starting_color)
                  "\t\tqtable_nonzero_revisit_rate: " + str(game_raw_data.qtable_nonzero_revisit_rate_list[-1])
            print(msg)
            anay_data.msg_list.append(msg)

            # save file and update plot section
            is_save_file_and_update_plot = (
                episode_idx + 1) % save_file_and_plot_update_interval == 0
            if is_save_file_and_update_plot:
                if is_save_raw_data:
                    CommonUtil.save_json_to_file(
                        game_raw_data.__dict__, save_dir_path + "/" +
                        start_interval_str + "_raw_data.txt")

                plt = PlotUtil.plot(
                    plot_id=1,
                    plot_title="Time Step in each Episode",
                    x_label="Episodes",
                    y_label="Time Step",
                    data_list=game_raw_data.episode_total_step_list)
                if is_save_chart_data:
                    plt.savefig(save_dir_path + "/" + start_interval_str +
                                "_episode_data_plot")

                plt = PlotUtil.plot(
                    plot_id=2,
                    plot_title="Reward in each Episode",
                    x_label="Episodes",
                    y_label="Time Step",
                    data_list=game_raw_data.episode_total_reward_list)
                if is_save_chart_data:
                    plt.savefig(save_dir_path + "/" + start_interval_str +
                                "_episode_data_plot")