- TabularQLearning: Uses defaultdict Q-tables with smooth policy updates
- NetworkQLearning: PyTorch neural networks with target networks
- Unified Interface: Abstract QLearningBackend base class
- Added
networkparameter to TwoPhaseTimescaleIQL constructor - Added
state_dimparameter for neural network input dimension - Maintained backward compatibility with existing tabular mode
- Smooth policy updates using softmax instead of epsilon-greedy
- Added
--networkflag to enable neural network mode - Added
--state-dimparameter for state vector dimension - Updated help documentation
- Updated README.md with network mode examples
- Added installation requirements for PyTorch
- Documented when to use each mode
- Provided usage examples for both modes
# Small discrete environments
python run_iql.py --mode train --phase1-episodes 500 --phase2-episodes 500 --map simple_map
# Visualization
python run_iql.py --mode visualize --load q_values.pkl --map simple_map# Large or complex environments
python run_iql.py --mode train --phase1-episodes 500 --phase2-episodes 500 --map complex_map --network --state-dim 6
# Training with rendering
python run_iql.py --mode train --map simple_map --network --state-dim 4 --render
# Visualization (network mode)
python run_iql.py --mode visualize --load q_values_nn.pkl --map complex_map --network --state-dim 6- ✅ Fast for small state spaces (< 10,000 states)
- ✅ Exact Q-value storage and retrieval
- ✅ Complete policy analysis and debugging
- ✅ Deterministic behavior
- ❌ Limited to discrete state spaces
- ✅ Scalable to large state spaces (> 10,000 states)
- ✅ Generalization across similar states
- ✅ Handles continuous or high-dimensional states
- ✅ Memory efficient for large problems
- ❌ Approximate Q-values
- ❌ Requires more training data
q_learning_backends.py- Modular backend systemrun_iql.py- Updated runner script with network support- Test files for validation
iql_timescale_algorithm.py- Added modular backend supportmain.py- Added network command-line argumentsREADME.md- Updated documentation- Various import fixes for proper module structure
The implementation includes several test scripts:
- test_network_short.py - Comprehensive unit tests
- demo_network.py - Interactive demonstration
- test_integration_short.py - Full pipeline testing
- validate_network.py - Implementation validation
Use Tabular Mode when:
- State space is small and discrete
- You need exact Q-values
- You want complete policy analysis
- Fast training is important
Use Neural Network Mode when:
- State space is large (> 10,000 states)
- States have continuous components
- You need generalization across states
- Memory efficiency is important
The implementation also includes the improved Phase 1 training that:
- Learns individual conservative models for each human
- Uses targeted robot actions against specific humans
- Provides more accurate human behavior models
- Follows the mathematical formulation correctly
The IQL Timescale Algorithm now supports both tabular and neural network modes, making it suitable for a wide range of applications from simple gridworlds to complex multi-agent environments.