CoolFace
Apppublic

gggg03/Dynamic_Pricing_Optimization

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

P02 — Dynamic Pricing Optimization (RL)

Retail pricing simulation with Q-Learning (discrete prices) and DDPG (continuous prices, PyTorch), plus a live dashboard, competitor tracker, profitability comparison, and sensitivity analysis.

Project structure

FilePurpose
env_and_agents.pyRetailPricingEnv, Q-Learning, DDPG (PyTorch), Fixed/Rule agents
RL_Env_Simulation.ipynbEnvironment demo & sanity tests
step2_train_ql.pyTrain Q-Learning agent
step5_compare.pyFixed vs Rule vs QL vs DDPG profitability comparison
train_all.pyFull pipeline (steps 2–6 + DDPG sensitivity)
build_dash_data.pyMerge JSON → dash_data.json
build_dashboard.pyBuild rl_dashboard.html
dashboard_server.pyLive simulator + competitor tracker (Flask)
generate_report.pyBuild REPORT.md

Quick start (Windows)

powershell
cd "c:\Users\PMLS\Desktop\rl project"
pip install -r requirements.txt
run_project.bat

Or step by step:

powershell
pip install numpy flask torch

# Step 1 — test environment
python -c "from env_and_agents import RetailPricingEnv; e=RetailPricingEnv(42); print(e.reset().shape)"

# Full pipeline (Q-Learning + DDPG training, sensitivity, comparison, report)
python train_all.py

# Or run steps individually:
python step2_train_ql.py          # Q-Learning training → ql_agent.npz
# (DDPG trains inside train_all.py — step 3)
python step5_compare.py           # Comparison → comparison.json
python build_dash_data.py         # Aggregate JSON → dash_data.json
python build_dashboard.py         # Build dashboard HTML
python generate_report.py         # Write REPORT.md

# Live dashboard (real env + trained agents — do NOT open as file://)
python dashboard_server.py
# Then open http://127.0.0.1:5050

Assignment mapping

StepTaskScript
1Simulation environmentRL_Env_Simulation.ipynb / env_and_agents.py
2Q-Learning trainingstep2_train_ql.py
3DDPG training (PyTorch)train_all.py (Step 3 section)
4Dashboardbuild_dashboard.pyrl_dashboard.html
5Fixed vs Rule vs QL vs DDPGstep5_compare.py
6Report + QL & DDPG sensitivitygenerate_report.py + REPORT.md

Environment details

  • Discrete actions: 0.8, 0.9, 1.0, 1.1, 1.2 × base price ($100)
  • Continuous (DDPG): multiplier ∈ [0.7, 1.5] via trained Actor network
  • State: inventory, price, competitor price, hour, day, 7-day demand avg, product age %
  • Reward: (revenue − COGS) − holding cost − stockout penalty − volatility penalty
  • Demand: price-elastic vs competitor; peak-hour boost; weekend boost

DDPG architecture

ComponentArchitecture
Actor7 → 256 (LayerNorm+ReLU) → 256 (LayerNorm+ReLU) → 128 (ReLU) → 1 (Sigmoid→[0.7,1.5])
CriticState branch: 7→256 (LN+ReLU); concat action → 256→128→1
NoiseOrnstein–Uhlenbeck with σ-decay
OptimiserAdam; grad clipping 0.5 (actor), 1.0 (critic); soft update τ=0.005

Outputs

After python train_all.py:

FileContents
ql_agent.npzSaved Q-table
ddpg_best.pthBest PyTorch DDPG weights
ql_training.jsonQ-Learning learning curve
ddpg_training.jsonDDPG learning curve
comparison.json100-episode eval: Fixed / Rule / QL / DDPG
sensitivity.json7 Q-Learning hyperparameter configs
ddpg_sensitivity.json7 DDPG hyperparameter configs
rl_dashboard.htmlInteractive static dashboard
REPORT.mdFull written report with tables

Live dashboard strategies

The live simulator (python dashboard_server.py) supports:

  • fixed — always $100
  • rule — heuristic rule agent
  • ql — trained Q-Learning agent (requires ql_agent.npz)
  • ddpg — trained DDPG agent (requires ddpg_best.pth)
  • random — random discrete action