Some basic examples of playing with RL
conda create -n conda_env
conda activate conda_env
pip install gymnasium[all]
pip install gymnasium[accept-rom-license]
# Try the next line if box2d-py fails to install.
conda install swig
pip install ai2thor==2.4.10
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
pip install torch torchvision torchaudio
pip install numpy pandas matplotlib
import gymnasium as gym
render = True # switch if visualize the agent
if render:
env = gym.make('CartPole-v0', render_mode='human')
else:
env = gym.make('CartPole-v0')
env.reset(seed=0)
for _ in range(1000):
env.step(env.action_space.sample()) # take a random action
env.close()
CartPole-v0
import gymnasium as gym
env = gym.make('CartPole-v0')
for i_episode in range(20):
observation = env.reset()
for t in range(100):
print(observation)
action = env.action_space.sample()
observation, reward, terminated, truncated, info = env.step(action)
done = np.logical_or(terminated, truncated)
env.close()
Pong-ram-v0
,Acrobot-v1
,Breakout-v0
)python my_random_agent.py Pong-ram-v0
CartPole-v0
or Acrobot-v1
python my_learning_agent.py CartPole-v0
pong_model_bolei.p
(after training 20,000 episodes), which you can load in by replacing save_file in the script.python pg-pong.py
python navigation_agent.py