Besides providing our custom map using the desc parameter, it's also possible to create random maps for the Frozen Lake environment, as shown in the code below:
# frozen-lake-random-maps-ex1.py import gym env = gym.make("FrozenLake-v0", desc=None, map_name=None) env.reset() env.render()
By setting both the parameters desc and map_name to None, the environment will be created using a random 8x8 map. However, it's not possible to create a random map of custom size using only the make method. But we can work around this limitation by importing the generate_random_map() function from the frozen_lake module and passing its output to the desc parameter:
# frozen-lake-random-maps-ex2.py import gym from gym.envs.toy_text.frozen_lake import generate_random_map random_map = generate_random_map(size=20, p=0.8) env = gym.make("FrozenLake-v0", desc=random_map) env.reset() env.render()
The generate_random_map() function provides us much more flexibility. The function receives two parameters: size and p. The parameter size expects an integer representing the side of the grid, resulting in a size x size map, whereas the p parameter is the probability of occurring a frozen tile, and is used to set the proportion between frozen tiles and holes.
Conclusion
The FrozenLake environment provided with the Gym library has limited options of maps, but we can work around these limitations by combining the generate_random_map() function and the desc parameter. The use of random maps it's interesting to test how well our algorithm can generalize.
References
Examples:
https://github.com/rodmsmendes/reinforcementlearning4fun/tree/master/frozen-lake-random-maps
Introduction to the Frozen Lake game:
https://reinforcementlearning4.fun/2019/06/09/introduction-reinforcement-learning-frozen-lake-example/
Using the Frozen Lake environment:
https://reinforcementlearning4.fun/2019/06/16/gym-tutorial-frozen-lake/
Installing OpenAI Gym:
https://reinforcementlearning4.fun/2019/05/24/how-to-install-openai-gym/
OpenAI Gym project homepage:
https://gym.openai.com
Top comments (0)