Downloads · 30 days
0
Adilbai/q-FrozenLake-v1-4x4-noSlippery
q-FrozenLake-v1-4x4-noSlippery is a reinforcement learning model from Adilbai. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This is a Q-Learning agent trained to solve the FrozenLake-v1 environment from OpenAI Gymnasium. The agent learns to navigate a frozen lake from start to goal while avoiding holes in the ice using tabular Q-learning w…
Downloads · 30 days
0
Access
Public
Updated Jun 12, 2025
Repo size
917 B
Likes
1
Public
Click a slice to open those files.
.mp431.2 KB · 74%
From the Hugging Face model README
This is a Q-Learning agent trained to solve the FrozenLake-v1 environment from OpenAI Gymnasium. The agent learns to navigate a frozen lake from start to goal while avoiding holes in the ice using tabular Q-learning with epsilon-greedy exploration.
SFFF
FHFH
FFFH
HFFG
Where:
The final Q-table represents the learned action values for each state-action pair:
State | Action 0 (Left) | Action 1 (Down) | Action 2 (Right) | Action 3 (Up) | Best Action
------|-----------------|-----------------|------------------|---------------|------------
0 | 0.735 | 0.774 | 0.774 | 0.735 | Down/Right
1 | 0.735 | 0.000 | 0.815 | 0.774 | Right
2 | 0.774 | 0.857 | 0.774 | 0.815 | Down
3 | 0.815 | 0.000 | 0.774 | 0.774 | Left
4 | 0.774 | 0.815 | 0.000 | 0.735 | Down
5 | 0.000 | 0.000 | 0.000 | 0.000 | Any (Hole)
6 | 0.000 | 0.903 | 0.000 | 0.815 | Down
7 | 0.000 | 0.000 | 0.000 | 0.000 | Any (Hole)
8 | 0.815 | 0.000 | 0.857 | 0.774 | Right
9 | 0.815 | 0.903 | 0.903 | 0.000 | Down/Right
10 | 0.857 | 0.950 | 0.000 | 0.857 | Down
11 | 0.000 | 0.000 | 0.000 | 0.000 | Any (Hole)
12 | 0.000 | 0.000 | 0.000 | 0.000 | Any (Hole)
13 | 0.000 | 0.903 | 0.950 | 0.857 | Right
14 | 0.903 | 0.950 | 1.000 | 0.903 | Right
15 | 0.000 | 0.000 | 0.000 | 0.000 | Goal State
Based on the Q-table, the optimal policy is:
model = load_from_hub(repo_id="Adilbai/q-FrozenLake-v1-4x4-noSlippery", filename="q-learning.pkl")
# Don't forget to check if you need to add additional attributes (is_slippery=False etc)
env = gym.make(model["env_id"])
env = gym.make('FrozenLake-v1', render_mode='human') reward, steps = run_episode(env, qtable, render=True) print(f"Episode reward: {reward}, Steps: {steps}") env.close()
### Performance Evaluation
```python
def evaluate_policy(qtable, n_episodes=100):
"""
Evaluate the learned policy
"""
env = gym.make('FrozenLake-v1')
rewards = []
steps_list = []
for _ in range(n_episodes):
reward, steps = run_episode(env, qtable)
rewards.append(reward)
steps_list.append(steps)
env.close()
success_rate = np.mean(rewards) * 100
avg_steps = np.mean(steps_list)
print(f"Evaluation Results ({n_episodes} episodes):")
print(f"Success Rate: {success_rate:.1f}%")
print(f"Average Steps: {avg_steps:.1f}")
print(f"Average Reward: {np.mean(rewards):.3f}")
return success_rate, avg_steps
# Evaluate the model
success_rate, avg_steps = evaluate_policy(qtable)
def visualize_policy(qtable):
"""
Visualize the learned policy
"""
action_names = ['←', '↓', '→', '↑']
policy_grid = np.zeros((4, 4), dtype=object)
for state in range(16):
row, col = state // 4, state % 4
if state in [5, 7, 11, 12]: # Holes
policy_grid[row, col] = 'H'
elif state == 15: # Goal
policy_grid[row, col] = 'G'
else:
best_action = np.argmax(qtable[state])
policy_grid[row, col] = action_names[best_action]
print("Learned Policy:")
print("S = Start, G = Goal, H = Hole")
for row in policy_grid:
print(' '.join(f'{cell:>2}' for cell in row))
visualize_policy(qtable)
def train_qlearning(env, n_episodes=1000000, learning_rate=0.005,
gamma=0.95, max_epsilon=1.0, min_epsilon=0.05,
decay_rate=0.0005):
"""
Train Q-learning agent (for reference)
"""
qtable = np.zeros((env.observation_space.n, env.action_space.n))
for episode in range(n_episodes):
state, _ = env.reset()
# Epsilon decay
epsilon = min_epsilon + (max_epsilon - min_epsilon) * np.exp(-decay_rate * episode)
for step in range(99): # max_steps
# Choose action
if np.random.random() < epsilon:
action = env.action_space.sample()
else:
action = np.argmax(qtable[state])
# Take action
next_state, reward, terminated, truncated, _ = env.step(action)
# Q-learning update
qtable[state, action] = qtable[state, action] + learning_rate * (
reward + gamma * np.max(qtable[next_state]) - qtable[state, action]
)
if terminated or truncated:
break
state = next_state
return qtable
Based on the Q-table values, the agent should achieve:
This Q-learning agent represents a well-trained tabular reinforcement learning solution for the classic FrozenLake navigation problem.