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.0.tar.gz (14.3 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.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asymmetric_td-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 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.0.tar.gz
Algorithm Hash digest
SHA256 579016f3d8d0e83b14db007adf8c917c1717d2bc2f9b932361ae32a8d855c398
MD5 63f26cc1b5e2d86194dcbdd1e33f37d3
BLAKE2b-256 347c08dd356669889518be55912cd3f889c4cb45d55cd271ff962424a65197c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asymmetric_td-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b74b55fdecb7f267f061cc5c86dfeadb35498fb0d0d0b61f088c1bff3e2daffb
MD5 afb9e1279dbf4170968a6045012dc36a
BLAKE2b-256 03323dd15acef7100b8be46e0392be82e2bb873194fdb5ebd0bb01f0485a7b1f

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