Reinforcement Learning with Gymnasium in Python
Fouad Trad
Machine Learning Engineer
import gymnasium as gym
env = gym.make('FrozenLake', is_slippery=True)
print(env.action_space)
print(env.observation_space)
print("Number of actions: ", env.action_space.n)
print("Number of states: ", env.observation_space.n)
Discrete(4)
Discrete(16)
Number of actions: 4
Number of states: 16
env.unwrapped.P
: dictionary where keys are state-action pairs
print(env.unwrapped.P[state][action])
[
(probability_1, next_state_1, reward_1, is_terminal_1),
(probability_2, next_state_2, reward_2, is_terminal_2),
etc.
]
state = 6 action = 0
print(env.unwrapped.P[state][action])
[(0.3333333333333333, 2, 0.0, False),
(0.3333333333333333, 5, 0.0, True),
(0.3333333333333333, 10, 0.0, False)]
Reinforcement Learning with Gymnasium in Python