REINFORCE Agent playing CartPole-v1

This is a trained model of a REINFORCE (Monte Carlo Policy Gradient) agent playing CartPole-v1 for Unit 4 of the Hugging Face Deep Reinforcement Learning Course.

Evaluation Results

  • Mean Reward: 463.91 +/- 94.40
  • Certification Score (mean - std): 369.51
  • Certification Requirement: >= 350.00 (Status: PASSED โœ…)

Video Replay

CartPole-v1 Gameplay

Hyperparameters

{
  "env_id": "CartPole-v1",
  "state_space": 4,
  "action_space": 2,
  "h_size": 16,
  "n_training_episodes": 1000,
  "n_evaluation_episodes": 100,
  "max_t": 1000,
  "gamma": 1.0,
  "lr": 0.01,
  "target_score": 350.0
}

How to Load and Evaluate

import torch
import gym
import numpy as np

# Load policy
policy = torch.load("model.pt", map_location="cpu")
policy.eval()

# Run an episode
env = gym.make("CartPole-v1")
state = env.reset()
if isinstance(state, tuple):
    state = state[0]

done = False
total_reward = 0
while not done:
    action, _ = policy.act(state)
    res = env.step(action)
    state = res[0]
    reward = res[1]
    done = res[2] if len(res) == 4 else (res[2] or res[3])
    total_reward += reward

print(f"Total Reward: {total_reward}")
env.close()
Downloads last month

-

Downloads are not tracked for this model. How to track
Video Preview
loading

Evaluation results