Skip to main content

Asymmetric Temporal Difference Learning for stable deep RL

Project description

Mini-Chess Zero

Asymmetric TD Learning: A biologically-inspired approach to stable deep reinforcement learning

Python 3.8+ PyTorch License: MIT

🎯 Results

Metric Before After
Win Rate 3% 87.5%
Q-Value 70,615,864 9.29
Status Diverging Converged

Key Achievement: 1,380× reduction in Q-value explosion through novel stabilization techniques.


🧠 Novel Contribution: Asymmetric TD Learning

Inspired by dopamine neuron asymmetry in biological brains:

# Positive TD errors: Learn cautiously (weight = 0.5)
# Negative TD errors: Learn aggressively (weight = 1.5)
weights = torch.where(td_errors > 0, 0.5, 1.5)
loss = (weights * huber_loss(predicted, target)).mean()

This prevents overoptimistic value estimates while enabling rapid learning from mistakes.


📦 Installation

# Clone repository
git clone https://github.com/your-username/mini-chess-zero.git
cd mini-chess-zero

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Install the asymmetric-td package locally
pip install -e .

🚀 Quick Start

Train the Agent

python train_monitor.py

Play Against AI

python play_human.py

Run Web App

cd webapp && python api.py
# Open http://localhost:8000

Run Trading Backtest

cd trading && python backtest.py

📁 Project Structure

mini_chess_rl/
├── src/                    # Core RL (87.5% win rate)
│   ├── agent.py            # Stabilized DQN
│   ├── environment.py      # 5x5 Mini-Chess
│   └── replay_buffer.py
├── asymmetric_td/          # Python Package
│   ├── losses/             # AsymmetricTDLoss
│   ├── agents/             # StableDQN
│   └── utils/              # Gradient, soft update
├── webapp/                 # Chess Web App
├── trading/                # Trading Adaptation (+24% return)
├── research/               # Paper, ablation study
└── models/                 # Trained models

📊 Ablation Study

Configuration Q-Value Status
FULL 9.29 ✅ Stable
NO_ATD 9.23 ✅ Stable
NO_Q_CLIP 10.82 ⚠️ Drifting
VANILLA 12,822 💥 Exploded

The combined stabilization stack is essential—removing all techniques causes catastrophic failure.


🎮 Features

  • Asymmetric TD Learning - Novel biologically-inspired loss function
  • Gradient Clipping - Prevents explosion (max_norm=10)
  • Polyak Soft Updates - Smooth target updates (τ=0.005)
  • Q-Value Clipping - Bounds estimates ([-10, 10])
  • Reward Centering - Reduces variance
  • Action Masking - Legal move enforcement

📈 Neural Network Analysis

The trained agent learned classical chess piece values:

Piece Learned Q-Value
King +3.18
Queen +2.97
Rook +2.64
Bishop +2.26
Knight +1.98
Pawn +1.86

📄 Research Paper

See research/paper/paper_draft.md for the complete paper:

  • Title: "Asymmetric Temporal Difference Learning: Biologically-Inspired Stabilization for Deep RL"
  • Key Result: 1,380× reduction in Q-value magnitude

🔧 Configuration

Key hyperparameters in src/agent.py:

Parameter Value Description
GAMMA 0.95 Discount factor
LEARNING_RATE 0.0001 Adam LR
TAU 0.005 Soft update rate
GRAD_CLIP 10.0 Gradient clipping
ATD_WEIGHTS (0.5, 1.5) Asymmetric weights

📜 License

MIT License - see LICENSE for details.


🙏 Acknowledgments

  • Gardner Mini-Chess variant
  • PyTorch team
  • Schultz (1997) for dopamine asymmetry research

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asymmetric_td-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asymmetric_td-0.1.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file asymmetric_td-0.1.1.tar.gz.

File metadata

  • Download URL: asymmetric_td-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for asymmetric_td-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1969cd4946ce3719cf1da69e52e06297d4dd20e3b0005f1992ede1e7e8796b78
MD5 ace1b5e797fb5735ab3a3e912bac3683
BLAKE2b-256 b83982caa8134d222fcd0c52b74891a06fd9993cf006136c5665e14dfe46cbeb

See more details on using hashes here.

File details

Details for the file asymmetric_td-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: asymmetric_td-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for asymmetric_td-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c040c450c161e2c657e95d215571da5433d91707d2942d54519e2230bea9a83d
MD5 9b0e4bdb8900f95e92b1bf4b47a012d7
BLAKE2b-256 4d4ef2239b5c8f69ac7eaf2d548397bba6da9956227cde66035461841ae2d067

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page