Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

🦿 Reinforcement Learning for Custom Hopper with Domain Randomization

his repository presents a comprehensive study on reinforcement learning (RL) algorithms applied to a custom MuJoCo Hopper environment. The project aims to build robust locomotion policies under uncertain dynamics using:

  • Classic Policy Gradient Methods: REINFORCE, Actor-Critic
  • Advanced On-Policy Algorithms: Proximal Policy Optimization (PPO)
  • Robustness Techniques: Domain Randomization (UDR), Curriculum Learning (CDR), Entropy Scheduling (ES)

πŸŽ₯ Hopper Locomotion Policy Demo

Watch the Hopper PPO + CDR + ES demo on YouTube
Click to watch the full 15-second demo

πŸ“ Repository Structure

.
β”œβ”€β”€ src/ # Core code (Python package)
β”‚ β”œβ”€β”€ agents/ # RL algorithm implementations
β”‚ β”œβ”€β”€ env/ # Custom MuJoCo-Hopper wrappers
β”‚ β”œβ”€β”€ evaluation/ # Metrics, plotting, helper scripts
β”‚ └── training/ # Training entry-points & configs
β”‚
β”œβ”€β”€ Logs/ # Raw tensorboard/CSV logs
β”‚ β”œβ”€β”€ Learning_Curve/ # β‡’ learning-curve CSVs
β”‚ β”œβ”€β”€ PPO_episode_rewards/ # β‡’ per-episode returns
β”‚ β”œβ”€β”€ PPO_robustness/ # β‡’ domain-randomisation runs
β”‚ β”œβ”€β”€ PPO_runtime_tmp/ # β‡’ scratch & tmp logs
β”‚ β”œβ”€β”€ actor_critic/ # β‡’ AC experiments
β”‚ └── baseline/ # β‡’ REINFORCE baseline runs
β”‚
β”œβ”€β”€ models/ 
β”‚ β”œβ”€β”€ PPO/
β”‚ β”œβ”€β”€ actor_critic/
β”‚ └── reinforce_baseline/
β”‚
β”œβ”€β”€ render/ # Visual outputs (GIF/MP4/PNG)
β”‚ └── plots/
β”‚
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ README.md # You are here πŸ‘‹
β”œβ”€β”€ __init__.py # Makes repo import-able (`import rl_master`)
β”œβ”€β”€ .idea/ # IDE settings (β‡’ add to .gitignore)
└── __pycache__/ # Byte-code cache (auto-generated)

πŸ§ͺ Environments & Randomization

The environment is based on a custom subclass of the MuJoCo Hopper (custom_hopper.py), extended with:

  • Parameter Randomization: friction, damping, body mass, initial state
  • Domain Randomization:
    • Uniform DR (UDR): randomized every episode
    • Curriculum DR (ES-CDR): difficulty scaled with agent performance and return entropy

🧠 Algorithms Implemented

Algorithm Description
REINFORCE Monte Carlo policy gradient with optional baseline
Actor-Critic TD-based policy/value method
PPO Clipped surrogate objective with GAE (Stable-Baselines3)
UDR Domain variation with uniform sampling
ES-CDR Return entropy-driven difficulty adjustment

βš™οΈ Environment Setup

Install the required packages:

pip install -r requirements.txt

You’ll need MuJoCo 2.1+ properly installed and licensed. Refer to: πŸ‘‰ https://github.com/openai/mujoco-py#install-mujoco


πŸ§ͺ Training

From the root directory, run:

# REINFORCE
python src/training/Train_Reinforce_vanila.py
# REINFORCE with baseline
python src/training/Train_Baseline.py
# Actor-Critic
python src/training/Train_Actor_Critic.py
# PPO + UDR + ES-CDR
python src/training/PPO_UDR_ES_CDR.py --Domain cdr --Entropy_Scheduling True --seed 0

πŸ”¬ Hyperparameter Optimization

python src/training/PPO_Hyperparameter_Calculation.py

You can adjust sweep parameters via JSON or inline config.


πŸ“Š Logging & Visualization

Training metrics (returns, entropy, etc.) are saved as CSV in the Logs/ directory.

To plot results:

python evaluation/plot_csv_scripts/plot_metrics.py

Or use the built-in metric utilities in src/evaluation.


πŸ€– Custom Environment

Implemented in src/env/custom_hopper.py, our environment introduces:

  • Dynamic randomization of:
    • Mass, friction, damping, init pose
  • UDR: Resampled every episode
  • CDR + ES: Difficulty increases based on policy performance and entropy

🧠 PPO + Curriculum Domain Randomization (CDR) + Entropy Scheduling (ES)

This project extends PPO with adaptive training difficulty using:

πŸ” Curriculum Domain Randomization (CDR)

CDR gradually increases the range of domain parameters (e.g., torso mass, friction) during training, helping the agent:

  • First master simple dynamics.
  • Then adapt to complex, realistic scenarios.

Use it with:

--Domain cdr

πŸ“‰ Entropy Scheduling (ES)

ES monitors the policy’s return entropy. When the agent is confident (low entropy), it:

  • Advances the curriculum level.
  • Makes the environment harder.

Enable it with:

--Entropy_Scheduling True

πŸ§ͺ Example PPO + CDR + ES Command

python src/training/PPO_UDR_ES_CDR.py --Domain cdr --Entropy_Scheduling True --seed 0

πŸ“ˆ Sample Results

Level Mean Return Std Dev Return Entropy
1 820 Β±50 1.02
2 710 Β±70 1.30
3 665 Β±85 1.48


πŸ“š References & Acknowledgements

  • OpenAI Baselines
  • Stable-Baselines3 Docs
  • MuJoCo Documentation

🧠 Future Directions

  • Add evaluation over unseen dynamics
  • Experiment with off-policy algorithms (e.g., SAC, DDPG)
  • Integrate video rendering and performance visualizations

πŸ“¬ Contact

Please reach out via GitHub issues or Linkedin profiles.

About

Reinforcement learning for a custom MuJoCo Hopper with PPO, REINFORCE, and Actor-Critic, featuring domain randomization, curriculum learning, and entropy scheduling for robust locomotion under uncertain dynamics

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /