<jupyter_start><jupyter_text>OpenAI Gym Available EnvironmentGym comes with a diverse suite of environments that range from easy to difficult and involve many different kinds of data. View the [full list of environments](https://gym.openai.com/envs) to get the birds-eye view.- [Classic control](https://gym.openai.com/envsclassic_control) and [toy text](https://gym.openai.com/envstoy_text): complete small-scale tasks, mostly from the RL literature. They’re here to get you started.- [Algorithmic](https://gym.openai.com/envsalgorithmic): perform computations such as adding multi-digit numbers and reversing sequences. One might object that these tasks are easy for a computer. The challenge is to learn these algorithms purely from examples. These tasks have the nice property that it’s easy to vary the difficulty by varying the sequence length.- [Atari](https://gym.openai.com/envsatari): play classic Atari games. - [2D and 3D robots](https://gym.openai.com/envsmujoco): control a robot in simulation. These tasks use the MuJoCo physics engine, which was designed for fast and accurate robot simulation.  Don't forget to set matplotlib to inline<jupyter_code>import matplotlib
%matplotlib inline<jupyter_output><empty_output><jupyter_text>CartPole-v1 exemple  Initialize environment<jupyter_code>import gym
env = gym.make('CartPole-v1')
_ = env.reset()
print("observation_space=",env.observation_space, "action_space=",env.action_space)<jupyter_output>observation_space= Box(-3.4028234663852886e+38, 3.4028234663852886e+38, (4,), float32) action_space= Discrete(2)<jupyter_text>Initialize agent<jupyter_code>from blobrl.agents import DQN
from blobrl.explorations import EpsilonGreedy

agent = DQN(observation_space=env.observation_space, action_space=env.action_space, greedy_exploration=EpsilonGreedy(0.1))<jupyter_output><empty_output><jupyter_text>Train Create Trainer<jupyter_code>from blobrl import Trainer
trainer = Trainer(environment=env, agent=agent, log_dir="./logs")<jupyter_output>D:\Users\nathan\Anaconda3\envs\RL\lib\site-packages\blobrl\trainer.py:29: UserWarning: be sure of your agent need to have good input and output dimension
  warnings.warn("be sure of your agent need to have good input and output dimension")<jupyter_text>Start train<jupyter_code>trainer.train(max_episode=500, nb_evaluation=0, render=False)
trainer.evaluate()
env.close()<jupyter_output><empty_output><jupyter_text>MountainCar-v0 exemple<jupyter_code>import gym
env = gym.make('MountainCar-v0')
_ = env.reset()
print("observation_space=",env.observation_space, "action_space=",env.action_space)<jupyter_output>observation_space= Box(-1.2000000476837158, 0.6000000238418579, (2,), float32) action_space= Discrete(3)<jupyter_text>Initialize agent<jupyter_code>from blobrl.agents import DQN
from blobrl.memories import ExperienceReplay
from blobrl.explorations import AdaptativeEpsilonGreedy
import torch.optim as optim

memory = ExperienceReplay(max_size=50000, gamma=0.99)  # gamma is discount reward factor (default is 0)
greedy_exploration = AdaptativeEpsilonGreedy(epsilon_max=0.8, epsilon_min=0.05, gamma=0.997)

agent = DQN(observation_space=env.observation_space, action_space=env.action_space, memory=memory, gamma=0.85, greedy_exploration=greedy_exploration)
agent.optimizer = optim.Adam(agent.network.parameters(), lr=0.001)<jupyter_output><empty_output><jupyter_text>Train Create Trainer<jupyter_code>from blobrl import Trainer
trainer = Trainer(environment=env, agent=agent, log_dir="./logs")<jupyter_output><empty_output><jupyter_text>Start train<jupyter_code>trainer.train(max_episode=1000, nb_evaluation=0, render=False)
trainer.evaluate()
env.close()<jupyter_output><empty_output><jupyter_text>FrozenLake-v0 example<jupyter_code>import gym
env = gym.make('FrozenLake-v0')
_ = env.reset()
print("observation_space=",env.observation_space, "action_space=",env.action_space)<jupyter_output>observation_space= Discrete(16) action_space= Discrete(4)<jupyter_text>Initialize agent<jupyter_code>from blobrl.agents import DQN
agent = DQN(observation_space=env.observation_space, action_space=env.action_space)<jupyter_output><empty_output><jupyter_text>Train Create Trainer<jupyter_code>from blobrl import Trainer
trainer = Trainer(environment=env, agent=agent, log_dir="./logs")<jupyter_output>D:\Users\nathan\Anaconda3\envs\RL\lib\site-packages\blobrl\trainer.py:29: UserWarning: be sure of your agent need to have good input and output dimension
  warnings.warn("be sure of your agent need to have good input and output dimension")<jupyter_text>Start train<jupyter_code>trainer.train(max_episode=1000, nb_evaluation=0, render=False)
trainer.evaluate()
env.close()<jupyter_output>(Right)
S[41mF[0mFF
FHFH
FFFH
HFFG
  (Right)
S[41mF[0mFF
FHFH
FFFH
HFFG<jupyter_text>Assault-v0 example<jupyter_code>import gym
env = gym.make('Assault-v0')
_ = env.reset()
trainer.evaluate()
env.close()
print("observation_space=",env.observation_space, "action_space=",env.action_space)<jupyter_output><empty_output><jupyter_text>Initialize agent<jupyter_code>from blobrl.agents import DQN
agent = DQN(observation_space=env.observation_space, action_space=env.action_space)<jupyter_output><empty_output><jupyter_text>Train Create Trainer<jupyter_code>from blobrl import Trainer
trainer = Trainer(environment=env, agent=agent, log_dir="./logs")<jupyter_output><empty_output><jupyter_text>Start train<jupyter_code>trainer.train(max_episode=200, nb_evaluation=0, render=False)
trainer.evaluate()
env.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1083966702859211, 'fraction_numerical': 0.02714440825190011, 'mean_word_length': 8.799645390070921, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '56317', 'license': 'Apache-2.0', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1893, 'n_words': 376, 'path': 'examples/example_train_jupyter.ipynb', 'repo_name': 'garaytc/reinforcement', 'size': '5526'}