Building a Custom Environment for Deep Reinforcement Learning with OpenAI Gym and Python
Why Stack Overflow recommends it
Stack Overflow users link it as the worked example they adapt when building custom Gym environments and training Keras-RL DQN agents, and as background when asking about action and observation spaces.
Recommended by 1 people across 1 different months, 2022 to 2023.
What it is
A 25-minute Python tutorial by Nicholas Renotte on writing a custom OpenAI Gym environment class (__init__, step and reset), then training and testing a DQN agent on it with Keras-RL. A shower-temperature control scenario is used, with chapters and code on GitHub.
What people said
Recommends mercury24 · 2022-01 · Stack Overflow · on “Training DQN Agent with Multidiscrete action space in gym”
I would like to train a DQN Agent with Keras-rl. My environment has both multi-discrete action and observation spaces. I am adapting the code of this video: [this video] Then, I am sharing my code class ShowerEnv(Env): def __init__(self, max_machine_states_vec, production_rates_vec, production_threshold, scheduling_horizon, operations_horizon = 100): """ Returns: self.action_space is a vector with the maximum production rate fro each machine, a binary call-to-maintenance and a binary call-to-schedule """ num_machines = len(max_machine_states_vec) assert len(max_machine_states_vec) == len(production_rates_vec), "Machine states and production rates have different cardinality" # Actions we can take,
Cites Mercury · 2022-05 · Stack Overflow · on “Variable input and output size for Keras”
Before I start, I am quite new to Keras and machine learning. I know the theory quite well but the syntax less so. I am trying to create a reinforcement learning neural network using Keras. The problem to be solved is essentially the travelling salesman problem. The problem is, is that the network is fed in its location and the environment, which is a randomly created network of points such as [[0,5],[30,17],[19,83]..., and as the agent travels through this network, it changes as a point cannot be visited again. So if the agent goes from [0,0] to [0,5] then [30,17], the input would look like [0,5],[30,17],[19,83] to [30,17],[19,83] to [19,83]. There is a similar issue with the output, which
Cites AliG · 2023-05 · Stack Overflow · on “Understanding action & observation spaces in gym for custom environments and agents”
I am currently trying to learn about reinforcement learning (RL). I am quite new to the field, and I apologize for the wall of text. I have encountered many examples of RL using TensorFlow, Keras, Keras-rl, stable-baselines3, PyTorch, gym, etc. However, I have discovered an oddity in the example codes that I do not understand, and I need some guidance. The oddity is in the use of gym’s observation spaces. In many examples, the custom environment includes initializing a gym observation space. However, this observation space seems never actually to be used. The environment state is many times created as a secondary variable. This variable is then changed based on the action, and then rewards a