Reinforcement Learning
stable-baselines3
MountainCar-v0
deep-reinforcement-learning
Eval Results (legacy)
Instructions to use txia-m/ppo-MountainCar-v0-a01 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use txia-m/ppo-MountainCar-v0-a01 with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="txia-m/ppo-MountainCar-v0-a01", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
PPO Agent playing MountainCar-v0
This is a trained model of a PPO agent playing MountainCar-v0 using the stable-baselines3 library.
Usage (with Stable-baselines3)
import gymnasium as gym
import torch
import numpy as np
from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.vec_env import VecNormalize
class StrictPhysicsWrapper(gym.Wrapper):
def __init__(self, env):
super().__init__(env)
def step(self, action):
next_state, reward, terminated, truncated, info = self.env.step(action)
position = next_state[0]
velocity = next_state[1]
dist_from_bottom = abs(position - (-0.5))
potential_reward = dist_from_bottom * 0.9
kinetic_reward = (velocity ** 2) * 10.0
new_reward = reward + potential_reward + kinetic_reward
if position >= 0.5:
new_reward += 100.0
return next_state, new_reward, terminated, truncated, info
env = make_vec_env("MountainCar-v0", n_envs=16, wrapper_class=StrictPhysicsWrapper)
env = VecNormalize(env, norm_obs=True, norm_reward=False, clip_obs=10.)
model = PPO(
policy='MlpPolicy',
env=env,
learning_rate=3e-4,
n_steps=1024,
batch_size=64,
n_epochs=10,
gamma=0.99,
gae_lambda=0.95,
ent_coef=0.0,
verbose=1,
policy_kwargs=dict(
net_arch=dict(pi=[64, 64], vf=[64, 64]),
activation_fn=torch.nn.Tanh
)
)
model.learn(total_timesteps=1000000)
...
- Downloads last month
- -
Evaluation results
- mean_reward on MountainCar-v0self-reported-97.80 +/- 7.32