Downloads · 30 days
0
Soumarya20/REINFORCE-CartPole-v1-updated
REINFORCE-CartPole-v1-updated is a reinforcement learning model from Soumarya20. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product.
This is a REINFORCE agent trained on the CartPole-v1 environment.
Downloads · 30 days
0
Access
Public
Updated Aug 2, 2026
Repo size
2.7 KB
Likes
0
Public
Click a slice to open those files.
.pt2.7 KB · 49%
From the Hugging Face model README
This is a REINFORCE agent trained on the CartPole-v1 environment.
{'h_size': 16, 'lr': 0.01, 'gamma': 0.99, 'n_training_episodes': 1000, 'max_t': 1000, 'print_every': 100}
import gymnasium as gym
import torch
from your_policy_file import Policy # Assuming Policy class is in 'your_policy_file.py'
# Load the environment
env = gym.make("CartPole-v1")
# Instantiate the policy network (adjust sizes as per your model)
s_size = env.observation_space.shape[0]
a_size = env.action_space.n
h_size = 16
policy = Policy(s_size, a_size, h_size)
# Load the trained weights
policy.load_state_dict(torch.load("model.pt"))
policy.eval()
# Test the agent
state, info = env.reset()
total_reward = 0
terminated = False
truncated = False
while not terminated and not truncated:
action, _ = policy.act(state)
state, reward, terminated, truncated, info = env.step(action)
total_reward += reward
print(f"Test Episode Reward: {total_reward}")
env.close()