--- model-name: REINFORCE-CartPole-v1 tags: - reinforcement-learning - policy-gradient - gymnasium - pytorch --- # REINFORCE Agent for CartPole-v1 This is a REINFORCE agent trained on the `CartPole-v1` environment. ## Training Hyperparameters ```python {'h_size': 16, 'lr': 0.01, 'gamma': 0.99, 'n_training_episodes': 1000, 'max_t': 1000, 'print_every': 100} ``` ## Evaluation Results - Mean Reward: 362.10 - Standard Deviation: 179.98 ## How to use ```python import gymnasium as gym import torch from agent import Policy # Using agent.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() ```