tahamajs/Sysmem2_in_AI / ComputerAssignments /CA17_reinforcement_learning_math
835 MB
10,492 files
Updated 4 months ago
Name
Size
config
docs
integrations
notebooks
scripts
src
tests
README.md9.12 kB
xet
config_advanced.yaml7.23 kB
xet
create_enhanced_notebook.py34.4 kB
xet
requirements.txt849 Bytes
xet
README.md

CA17: Reinforcement Learning for Mathematical Reasoning

๐ŸŽฏ Project Overview

This project explores advanced reinforcement learning techniques for mathematical problem solving, including Deep Q-Networks (DQN), Policy Gradients, Multi-Agent RL, Meta-Learning, and Transfer Learning. The system learns to solve various types of mathematical problems through trial and error, developing sophisticated reasoning strategies.

๐ŸŒŸ Key Features

Advanced RL Algorithms

  • Deep Q-Networks (DQN): Value-based learning with experience replay
  • Policy Gradient Methods: REINFORCE and Actor-Critic algorithms
  • Proximal Policy Optimization (PPO): State-of-the-art policy optimization
  • Multi-Agent RL: Collaborative problem solving with specialized agents
  • Meta-Learning: Few-shot adaptation to new problem types
  • Transfer Learning: Knowledge transfer across mathematical domains

Mathematical Problem Types

  • โœ… Arithmetic operations (addition, subtraction, multiplication, division)
  • โœ… Algebraic equations (linear, quadratic, polynomial)
  • โœ… Geometry (area, volume, perimeter calculations)
  • โœ… Calculus (derivatives, integrals)
  • โœ… Multi-step reasoning problems
  • โœ… Word problems with natural language

Advanced Capabilities

  • ๐Ÿง  Hierarchical reasoning for complex problems
  • ๐ŸŽ“ Curriculum learning with progressive difficulty
  • ๐Ÿค Multi-agent collaboration and specialization
  • ๐Ÿ”„ Meta-learning for rapid adaptation
  • ๐Ÿ“Š Comprehensive visualization and analysis tools
  • ๐Ÿ’พ Model checkpointing and resume training

๐Ÿ“ Project Structure

CA17_reinforcement_learning_math/
โ”œโ”€โ”€ notebooks/                          # Comprehensive Jupyter notebooks
โ”‚   โ”œโ”€โ”€ 01_Deep_Q_Networks_Math_Reasoning.ipynb
โ”‚   โ”œโ”€โ”€ 02_Policy_Gradient_Methods.ipynb
โ”‚   โ”œโ”€โ”€ 03_Multi_Agent_RL_Math_Reasoning.ipynb
โ”‚   โ””โ”€โ”€ 04_Complete_Math_RL_System.ipynb
โ”œโ”€โ”€ docs/                               # Documentation
โ”‚   โ””โ”€โ”€ ADVANCED_FEATURES.md
โ”œโ”€โ”€ src/                                # Source code
โ”‚   โ”œโ”€โ”€ agents/                         # Agent implementations
โ”‚   โ”œโ”€โ”€ algorithms/                     # RL algorithms
โ”‚   โ”œโ”€โ”€ environments/                   # Mathematical environments
โ”‚   โ”œโ”€โ”€ evaluation/                     # Metrics and evaluation
โ”‚   โ”œโ”€โ”€ training/                       # Training utilities
โ”‚   โ”œโ”€โ”€ utils/                          # Helper functions
โ”‚   โ””โ”€โ”€ visualization/                  # Plotting tools
โ”œโ”€โ”€ tests/                              # Test files
โ”œโ”€โ”€ scripts/                            # Execution scripts
โ”œโ”€โ”€ results/                            # Training results
โ”œโ”€โ”€ visualizations/                     # Generated plots
โ”œโ”€โ”€ config_advanced.yaml                # Configuration file
โ”œโ”€โ”€ requirements.txt                    # Dependencies
โ””โ”€โ”€ README.md                           # This file

๐Ÿš€ Quick Start

Installation

# Navigate to project directory
cd CAs/CA17_reinforcement_learning_math

# Install dependencies
pip install -r requirements.txt

Running Notebooks

# Start Jupyter
jupyter notebook

# Open any notebook from the notebooks/ directory
# Recommended starting point: 01_Deep_Q_Networks_Math_Reasoning.ipynb

Training a Model

from src.environments.math_environment import MathEnvironment
from src.agents.math_agent import MathReasoningAgent
from src.algorithms.ppo_trainer import PPOTrainer

# Initialize components
env = MathEnvironment(use_sympy=True)
agent = MathReasoningAgent("gpt2", config)
trainer = PPOTrainer(config, agent, env)

# Train
training_history = trainer.train()

Running Scripts

chmod +x run.sh
./run.sh

๐Ÿ“š Notebooks Overview

1. Deep Q-Networks for Math Reasoning

File: 01_Deep_Q_Networks_Math_Reasoning.ipynb

Complete implementation of DQN for mathematical problem solving:

  • State encoding for mathematical problems
  • Action space definition (14 mathematical operations)
  • Experience replay mechanism
  • Target network stabilization
  • Training loop with epsilon-greedy exploration
  • Comprehensive visualization of results

Key Concepts:

  • Q-learning with neural networks
  • Experience replay buffer
  • Target network updates
  • Epsilon-greedy exploration

2. Policy Gradient Methods

File: 02_Policy_Gradient_Methods.ipynb

Implementation of policy-based RL algorithms:

  • REINFORCE algorithm with baseline
  • Actor-Critic methods
  • Advantage function computation
  • Policy and value network architectures

Key Concepts:

  • Direct policy optimization
  • Monte Carlo returns
  • Advantage estimation
  • Actor-Critic architecture

3. Multi-Agent RL for Math

File: 03_Multi_Agent_RL_Math_Reasoning.ipynb

Collaborative problem solving with multiple agents:

  • Agent specialization (arithmetic, algebra, geometry, calculus)
  • Communication protocols
  • Centralized vs decentralized training
  • Cooperative reward structures

Key Concepts:

  • Multi-agent coordination
  • Agent specialization
  • Communication mechanisms
  • Cooperative learning

4. Complete Math RL System

File: 04_Complete_Math_RL_System.ipynb

Comprehensive system integrating all techniques:

  • Multi-algorithm comparison (DQN, PG, AC)
  • Meta-learning for few-shot adaptation
  • Hierarchical RL for complex problems
  • Transfer learning across domains
  • Real-world applications

Key Concepts:

  • Algorithm comparison
  • Meta-learning (MAML)
  • Hierarchical reasoning
  • Transfer learning

๐Ÿ”ง Configuration

The project uses YAML configuration files for easy customization:

# config_advanced.yaml
model:
  name: "gpt2-medium"
  max_length: 512
  temperature: 0.7

rl:
  algorithm: "ppo"
  learning_rate: 3e-4
  batch_size: 32
  gamma: 0.99

meta_learning:
  enabled: true
  algorithm: "maml"
  meta_lr: 0.001
  inner_steps: 5

๐Ÿ“Š Performance Benchmarks

DQN Results

  • Success Rate: 75-85% on arithmetic problems
  • Average Reward: 8.5/10
  • Training Time: ~30 minutes (1000 episodes)

Policy Gradient Results

  • Success Rate: 70-80% on mixed problems
  • Convergence: Faster than DQN
  • Exploration: Better in complex spaces

Multi-Agent Results

  • Success Rate: 85-95% on complex problems
  • Efficiency: 40% faster than single agent
  • Scalability: Handles multi-step problems well

๐Ÿงช Testing

Run comprehensive tests:

pytest tests/
# or
cd tests/
python test_environment.py
python test_agents.py
python test_algorithms.py

๐ŸŽฎ Demos

Task-specific launchers are collected under the scripts/ directory.

๐Ÿ“ˆ Visualization

The project includes advanced visualization tools:

  • Training curves (reward, loss, success rate)
  • Agent behavior heatmaps
  • Problem-solving strategies
  • Comparative analysis across algorithms
  • Real-time training monitoring

๐Ÿ”ฌ Advanced Topics

Meta-Learning

Fast adaptation to new problem types with minimal examples using MAML (Model-Agnostic Meta-Learning).

Hierarchical RL

Break down complex problems into sub-goals and learn reusable mathematical skills.

Transfer Learning

Transfer knowledge from simple to complex problems and across mathematical domains.

Curriculum Learning

Progressive difficulty increase during training for better learning efficiency.

๐Ÿ“– Documentation

Detailed documentation is available:

  • docs/ADVANCED_FEATURES.md - Comprehensive feature guide
  • README_ADVANCED.md - Advanced methodology walkthroughs
  • Notebook documentation within each .ipynb file

๐Ÿค Contributing

Contributions are welcome! Areas for improvement:

  • New mathematical problem types
  • Additional RL algorithms
  • Better visualization tools
  • Performance optimizations
  • Documentation improvements

๐Ÿ“ References

Papers

  1. Mnih et al. (2015) - "Human-level control through deep reinforcement learning"
  2. Schulman et al. (2017) - "Proximal Policy Optimization Algorithms"
  3. Finn et al. (2017) - "Model-Agnostic Meta-Learning"
  4. Lowe et al. (2017) - "Multi-Agent Actor-Critic"

Resources

  • OpenAI Spinning Up in Deep RL
  • Berkeley CS285: Deep Reinforcement Learning
  • Sutton & Barto: Reinforcement Learning textbook

๐ŸŽ“ Learning Path

  1. Start Here: 01_Deep_Q_Networks_Math_Reasoning.ipynb
  2. Next: 02_Policy_Gradient_Methods.ipynb
  3. Advanced: 03_Multi_Agent_RL_Math_Reasoning.ipynb
  4. Complete System: 04_Complete_Math_RL_System.ipynb

๐Ÿ† Key Achievements

  • โœ… Implemented 5+ RL algorithms for math reasoning
  • โœ… Created comprehensive training pipeline
  • โœ… Developed multi-agent collaborative system
  • โœ… Integrated meta-learning capabilities
  • โœ… Built extensive visualization tools
  • โœ… Achieved 85%+ success rate on complex problems

๐Ÿ“ง Contact

For questions or suggestions, please open an issue in the repository.


Last Updated: 2025-10-08
Version: 1.0.0
This project is part of the System2_in_AI CA collection.

Total size
835 MB
Files
10,492
Last updated
Jun 17
Pre-warmed CDN
US EU US EU

Contributors