๐Ÿš€ Dueling Double DQN Agent for LunarLander-v3

This repository provides a high-performance Dueling Double Deep Q-Network (Dueling DDQN) agent trained to master the LunarLander-v3 environment from Gymnasium (Farama Foundation).


๐Ÿ“Š Benchmark & Evaluation Results

Tested on 100 consecutive evaluation episodes with deterministic evaluation policy ($\epsilon = 0.0$):

Metric Result Target / Threshold
Mean Reward 273.14 ยฑ 44.76 $\ge 200.0$ (Environment Solved)
Max Reward 313.57 โ€”
Min Reward 25.68 โ€”
Landing Success Rate 92.0% โ€”
Average Flight Steps 255.6 steps Max 1000 steps

๐Ÿ† Environment Status: SOLVED (Mean score $\ge 200$ points consistently across diverse initial conditions).


๐Ÿง  Neural Network & Agent Architecture

The agent implements a Dueling Deep Q-Network combined with Double Q-Learning, allowing decoupled state-value estimation from action-advantage estimation.

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ State Input: s โˆˆ โ„โธ           โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Linear(8, 128) + ReLU         โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Linear(128, 128) + ReLU       โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ”‚ (Shared Feature Map: โ„ยนยฒโธ)        โ”‚
                โ–ผ                                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Value Stream V(s)             โ”‚   โ”‚ Advantage Stream A(s, a)      โ”‚
โ”‚ Linear(128, 64) + ReLU        โ”‚   โ”‚ Linear(128, 64) + ReLU        โ”‚
โ”‚ Linear(64, 1)                 โ”‚   โ”‚ Linear(64, 4)                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚                                   โ”‚
                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Q(s, a) = V(s) + ( A(s, a) - 1/|A| โˆ‘_{a'} A(s, a') )                  โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Output: Q-values โˆˆ โ„โด         โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Layer Specifications

Stream / Module Layer Input Dim Output Dim Activation Parameters
Shared Backbone Linear 1 8 128 ReLU 1,152
Linear 2 128 128 ReLU 16,512
State-Value $V(s)$ Linear 3 (V1) 128 64 ReLU 8,256
Linear 4 (V2) 64 1 None 65
Advantage $A(s, a)$ Linear 3 (A1) 128 64 ReLU 8,256
Linear 4 (A2) 64 4 None 260
Total Trainable Parameters 34,501

โš™๏ธ Hyperparameters

Hyperparameter Value Description
Algorithm Dueling DDQN Decoupled value/advantage estimation with Double DQN target formulation
Optimizer Adam Adaptive moment estimation
Learning Rate ($\alpha$) 0.0005 ($5 \times 10^{-4}$) Policy network learning rate
Discount Factor ($\gamma$) 0.99 Future reward discount
Replay Buffer Size 100,000 Experience replay capacity
Batch Size 64 Mini-batch sample size per update step
Target Soft-Update ($\tau$) 0.001 ($1 \times 10^{-3}$) Polyak averaging coefficient ($\theta_{target} \leftarrow \tau \theta_{policy} + (1-\tau)\theta_{target}$)
Exploration ($\epsilon_{\text{start}}$) 1.0 ($100%$) Initial random exploration probability
Exploration ($\epsilon_{\text{end}}$) 0.05 ($5%$) Minimum exploration floor
Epsilon Decay Schedule Geometric Decay Decays smoothly over 75% of total training episodes
Loss Function Smooth L1 (Huber Loss) Robust regression loss less sensitive to outliers than MSE
Gradient Clipping max_norm = 1.0 Prevents gradient explosion

๐Ÿช Environment Specifications (LunarLander-v3)

State Space (8 Continuous Dimensions)

  1. $x$: Horizontal coordinate
  2. $y$: Vertical coordinate
  3. $v_x$: Horizontal linear velocity
  4. $v_y$: Vertical linear velocity
  5. $\theta$: Lander orientation angle (radians)
  6. $\omega$: Angular velocity
  7. $l_1$: Left leg ground contact flag (0.0 or 1.0)
  8. $l_2$: Right leg ground contact flag (0.0 or 1.0)

Action Space (4 Discrete Actions)

  • 0: Do nothing (Rest)
  • 1: Fire left orientation engine (Tilts right)
  • 2: Fire main engine (Thrusts upward)
  • 3: Fire right orientation engine (Tilts left)

๐Ÿ“ฆ Files Included

  • best_model.pth: Best performing checkpoint during training (Mean reward: 273.14).
  • latest_model.pth: Final training checkpoint after complete episode run.
  • dqn_agent.py: Standalone PyTorch implementation of DuelingQNetwork and DQNAgent.
  • evaluate_hf.py: Turn-key evaluation and graphical test script.
  • README.md: Comprehensive model card & benchmark report.

๐ŸŽฎ Quick Start & Evaluation

1. Installation

pip install torch gymnasium[box2d] huggingface_hub pygame

2. Run Evaluation with Visual Rendering

python evaluate_hf.py --repo moona-ai/lunar-lander-v3-dqn --episodes 5 --render human

3. Run in Challenging Wind Conditions

python evaluate_hf.py --repo moona-ai/lunar-lander-v3-dqn --episodes 5 --render human --wind

๐Ÿ’ป Direct Python Integration

import gymnasium as gym
import torch
from huggingface_hub import hf_hub_download
from dqn_agent import DQNAgent

# 1. Download best weights directly from Hugging Face Hub
model_path = hf_hub_download(repo_id="moona-ai/lunar-lander-v3-dqn", filename="best_model.pth")

# 2. Instantiate agent & load checkpoint
agent = DQNAgent(state_size=8, action_size=4)
agent.load(model_path)
print("โœ… LunarLander Dueling DDQN model loaded successfully!")

# 3. Create Gymnasium environment & run test episode
env = gym.make("LunarLander-v3", render_mode="human")
state, _ = env.reset()
done = False
total_reward = 0.0

while not done:
    # Evaluate with deterministic greedy policy (evaluate=True)
    action, q_values = agent.act(state, evaluate=True)
    state, reward, terminated, truncated, _ = env.step(action)
    total_reward += reward
    done = terminated or truncated

print(f"๐ŸŽ‰ Episode Finished! Total Reward: {total_reward:.2f}")
env.close()

๐Ÿท๏ธ Citation & Acknowledgements

  • Environment: Gymnasium Box2D LunarLander
  • Algorithm References:
    • Dueling Network Architectures for Deep Reinforcement Learning (Wang et al., 2016)
    • Deep Reinforcement Learning with Double Q-learning (van Hasselt et al., 2015)
  • Trained & Uploaded with: LunarLander RL Studio
Downloads last month

-

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

Evaluation results