Views
No views yet

1def get_action(self, observation):
2 observation = np.array(observation, dtype=np.float32)
3 action_scores = np.dot(observation, self.weights)
4 return int(np.argmax(action_scores))1from model import CMAESAgent
2
3# Load the model
4agent = CMAESAgent.from_pretrained("harpertoken/harpertoken-cartpole")
5
6# Evaluate
7mean_reward, std_reward = agent.evaluate(num_episodes=5)
8print(f"Mean reward: {mean_reward:.2f} ± {std_reward:.2f}")1import numpy as np
2from gymnasium import make
3
4# Load model weights
5weights = np.load('model_weights.npy') # 4x2 matrix
6
7# Create environment
8env = make('CartPole-v1')
9
10# Run inference
11def get_action(observation):
12 logits = observation @ weights
13 return int(np.argmax(logits))
14
15observation, _ = env.reset()
16while True:
17 action = get_action(observation)
18 observation, reward, done, truncated, info = env.step(action)
19 if done or truncated:
20 break1class CMAESAgent:
2 def __init__(self, env_name):
3 self.env = gym.make(env_name)
4 self.observation_space = self.env.observation_space.shape[0] # 4 for CartPole
5 self.action_space = self.env.action_space.n # 2 for CartPole
6 self.num_params = self.observation_space * self.action_space # 8 total parameters
7 self.weights = None
8
9 def get_action(self, observation):
10 observation = np.array(observation, dtype=np.float32)
11 action_scores = np.dot(observation, self.weights)
12 return int(np.argmax(action_scores))1@misc{das2025cartpole,
2 author = {Niladri Das},
3 title = {CartPole Solution},
4 year = {2025},
5 publisher = {Hugging Face},
6 journal = {Hugging Face Model Hub},
7 howpublished = {https://huggingface.co/harpertoken/harpertoken-cartpole}
8}