From c538aee022dcba2c744d1328aa7e66da6109a46d Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Mon, 10 Jun 2024 12:58:07 +0100 Subject: [PATCH] Rename benchmark variables and add h1 to notebooks --- .../Data-Manipulation-Customising-Red-Agent.ipynb | 2 +- .../notebooks/Training-an-RLLIB-MARL-System.ipynb | 4 ++-- src/primaite/notebooks/Training-an-RLLib-Agent.ipynb | 4 ++-- src/primaite/notebooks/Using-Episode-Schedules.ipynb | 2 +- src/primaite/notebooks/multi-processing.ipynb | 4 ++-- src/primaite/session/environment.py | 4 ++-- src/primaite/utils/session_output_reader.py | 6 +++--- src/primaite/utils/session_output_writer.py | 10 +++++----- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb index dd5def9e..33d56fb0 100644 --- a/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb +++ b/src/primaite/notebooks/Data-Manipulation-Customising-Red-Agent.ipynb @@ -458,7 +458,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb b/src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb index 96ee8e5d..c185b8b5 100644 --- a/src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb +++ b/src/primaite/notebooks/Training-an-RLLIB-MARL-System.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Train a Multi agent system using RLLIB\n", + "# Train a Multi agent system using RLLIB\n", "\n", "© Crown-owned copyright 2024, Defence Science and Technology Laboratory UK\n", "\n", @@ -108,7 +108,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/primaite/notebooks/Training-an-RLLib-Agent.ipynb b/src/primaite/notebooks/Training-an-RLLib-Agent.ipynb index ac64689f..bdd60f36 100644 --- a/src/primaite/notebooks/Training-an-RLLib-Agent.ipynb +++ b/src/primaite/notebooks/Training-an-RLLib-Agent.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Train a Single agent system using RLLib\n", + "# Train a Single agent system using RLLib\n", "\n", "© Crown-owned copyright 2024, Defence Science and Technology Laboratory UK\n", "\n", @@ -99,7 +99,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/primaite/notebooks/Using-Episode-Schedules.ipynb b/src/primaite/notebooks/Using-Episode-Schedules.ipynb index 692a52b3..0d0f1a4a 100644 --- a/src/primaite/notebooks/Using-Episode-Schedules.ipynb +++ b/src/primaite/notebooks/Using-Episode-Schedules.ipynb @@ -328,7 +328,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/primaite/notebooks/multi-processing.ipynb b/src/primaite/notebooks/multi-processing.ipynb index 1807d39c..86b549a7 100644 --- a/src/primaite/notebooks/multi-processing.ipynb +++ b/src/primaite/notebooks/multi-processing.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Simple multi-processing demonstration\n", + "# Simple multi-processing demonstration\n", "\n", "© Crown-owned copyright 2024, Defence Science and Technology Laboratory UK\n", "\n", @@ -143,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/primaite/session/environment.py b/src/primaite/session/environment.py index 1c605f59..8fd39f40 100644 --- a/src/primaite/session/environment.py +++ b/src/primaite/session/environment.py @@ -37,7 +37,7 @@ class PrimaiteGymEnv(gymnasium.Env): """Name of the RL agent. Since there should only be one RL agent we can just pull the first and only key.""" self.episode_counter: int = 0 """Current episode number.""" - self.average_reward_per_episode: Dict[int, float] = {} + self.total_reward_per_episode: Dict[int, float] = {} """Average rewards of agents per episode.""" @property @@ -91,7 +91,7 @@ class PrimaiteGymEnv(gymnasium.Env): f"Resetting environment, episode {self.episode_counter}, " f"avg. reward: {self.agent.reward_function.total_reward}" ) - self.average_reward_per_episode[self.episode_counter] = self.agent.reward_function.total_reward + self.total_reward_per_episode[self.episode_counter] = self.agent.reward_function.total_reward if self.io.settings.save_agent_actions: all_agent_actions = {name: agent.history for name, agent in self.game.agents.items()} diff --git a/src/primaite/utils/session_output_reader.py b/src/primaite/utils/session_output_reader.py index 322b3b8d..c3088870 100644 --- a/src/primaite/utils/session_output_reader.py +++ b/src/primaite/utils/session_output_reader.py @@ -11,16 +11,16 @@ from typing import Any, Dict, Tuple, Union import polars as pl -def av_rewards_dict(av_rewards_csv_file: Union[str, Path]) -> Dict[int, float]: +def total_rewards_dict(total_rewards_csv_file: Union[str, Path]) -> Dict[int, float]: """ Read an average rewards per episode csv file and return as a dict. The dictionary keys are the episode number, and the values are the mean reward that episode. - :param av_rewards_csv_file: The average rewards per episode csv file path. + :param total_rewards_csv_file: The average rewards per episode csv file path. :return: The average rewards per episode csv as a dict. """ - df_dict = pl.read_csv(av_rewards_csv_file).to_dict() + df_dict = pl.read_csv(total_rewards_csv_file).to_dict() return {int(v): df_dict["Average Reward"][i] for i, v in enumerate(df_dict["Episode"])} diff --git a/src/primaite/utils/session_output_writer.py b/src/primaite/utils/session_output_writer.py index 9253147a..bdcf2b35 100644 --- a/src/primaite/utils/session_output_writer.py +++ b/src/primaite/utils/session_output_writer.py @@ -26,9 +26,9 @@ class SessionOutputWriter: Is used to write session outputs to csv file. """ - _AV_REWARD_PER_EPISODE_HEADER: Final[List[str]] = [ + _TOTAL_REWARD_PER_EPISODE_HEADER: Final[List[str]] = [ "Episode", - "Average Reward", + "Total Reward", ] def __init__( @@ -43,7 +43,7 @@ class SessionOutputWriter: :param env: PrimAITE gym environment. :type env: Primaite :param transaction_writer: If `true`, this will output a full account of every transaction taken by the agent. - If `false` it will output the average reward per episode, defaults to False + If `false` it will output the total reward per episode, defaults to False :type transaction_writer: bool, optional :param learning_session: Set to `true` to indicate that the current session is a training session. This determines the name of the folder which contains the final output csv. Defaults to True @@ -56,7 +56,7 @@ class SessionOutputWriter: if self.transaction_writer: fn = f"all_transactions_{self._env.timestamp_str}.csv" else: - fn = f"average_reward_per_episode_{self._env.timestamp_str}.csv" + fn = f"total_reward_per_episode_{self._env.timestamp_str}.csv" self._csv_file_path: "Path" if self.learning_session: @@ -94,7 +94,7 @@ class SessionOutputWriter: if isinstance(data, Transaction): header, data = data.as_csv_data() else: - header = self._AV_REWARD_PER_EPISODE_HEADER + header = self._TOTAL_REWARD_PER_EPISODE_HEADER if self._first_write: self._init_csv_writer()