Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏭 Process Digital Twin with Uncertainty Quantification

A Gaussian Process surrogate model of a debutanizer column with calibrated conformal prediction intervals and automated distribution-shift detection.

Python GPyTorch scikit-learn License: MIT


🎯 Motivation

Most machine learning models in process engineering output a single number.
A digital twin that is actually useful for process control and operator support must answer:

"How confident are you in this prediction — and does it degrade gracefully when conditions change?"

This project demonstrates uncertainty quantification (UQ) for a chemical process surrogate model using:

Component Role
Gaussian Process (GPyTorch) Bayesian surrogate with native posterior uncertainty
ARD Matérn-5/2 kernel Per-variable length-scales → variable importance ranking
Split Conformal Prediction Provable finite-sample coverage guarantees (distribution-free)
OOD Detection Posterior std threshold flags distribution-shifted operating points
Plotly Interactive dashboards for all figures

🔬 Process Context: Debutanizer Column

A debutanizer is a distillation column that separates light-end butanes (C4) from heavier fractions in a crude unit. The soft-sensor target is the C4 concentration in the top product — a key quality variable that cannot be measured continuously in real time.

Feed (C4 + heavy)  →  [Debutanizer Column]  →  Top Product (C4-rich)
                                              →  Bottom Product (C5+)

Input features (7 process variables):

Variable Description Type
x1_top_T Top tray temperature [°C] Process
x2_tray4_T Tray 4 temperature [°C] Process
x3_tray7_T Tray 7 temperature [°C] Process
x4_tray11_T Tray 11 temperature [°C] Process
x5_steam Reboiler steam flow [kg/h] Manipulated
x6_reflux Reflux flow [m³/h] Manipulated
x7_feed Feed flow [m³/h] Disturbance

Target: y_c4 — C4 mole fraction in top product [mol%]


🧠 Technical Architecture

1. Gaussian Process Surrogate (GPyTorch)

GP(x) ~ N(μ(x), k(x, x'))

Kernel: k(x, x') = σ²_f · Matérn₅/₂(x, x'; {ℓ_d})
  • ARD (Automatic Relevance Determination): each input dimension gets its own length-scale ℓ_d
  • Short ℓ_d → rapid function variation → variable is important
  • Training via Exact Marginal Log-Likelihood (Adam optimiser)
  • Outputs posterior mean μ* and variance σ²* for every prediction

2. Split Conformal Prediction

Wraps the GP to produce guaranteed prediction intervals:

Step 1 — Calibrate (on held-out calibration set):
    sᵢ = |yᵢ − μ̂(xᵢ)| / σ̂(xᵢ)      (normalised nonconformity score)
    q̂  = Quantile(s₁, …, sₙ; ⌈(n+1)(1-α)⌉/n)

Step 2 — Predict (for new test point x*):
    PI(x*) = [μ̂* − q̂·σ̂*,  μ̂* + q̂·σ̂*]

Coverage guarantee: P(y* ∈ PI(x*)) ≥ 1 − α

Key properties:

  • Distribution-free: no Gaussian assumption on residuals
  • Adaptive width: intervals widen exactly where GP is uncertain (OOD regions)
  • Provable coverage: marginal guarantee holds for any exchangeable data

3. Distribution Shift Detection

OOD score(x) = σ̂(x)   # GP posterior std (epistemic uncertainty)

Flag if: σ̂(x_test) > Percentile₉₅(σ̂(x_calib))

The GP's posterior variance is the ideal OOD score because:

  • In familiar regions → low variance → tight CI → no flag
  • Under distribution shift → high variance → wide CI → flagged automatically

📊 Key Results

Metric In-Distribution Out-of-Distribution
Empirical coverage ~90% ~88%
Mean PI width narrow +30–50% wider
OOD points flagged ~70–85%
Winkler score low higher (expected)

Key insight: The conformal PI maintains coverage under mild distribution shift (the conformal guarantee holds for exchangeable data), while the GP's posterior std gracefully signals degraded confidence — giving operators an early warning without catastrophic failure.


🗂️ Repository Structure

process-digital-twin/
├── src/
│   ├── data_generator.py     # Synthetic debutanizer data generation
│   ├── gp_model.py           # GPyTorch GP with ARD Matérn-5/2 kernel
│   ├── conformal.py          # Split conformal prediction + OOD detection
│   └── visualizations.py     # Plotly figure library
├── notebooks/
│   └── full_walkthrough.ipynb  # End-to-end notebook with narrative
├── outputs/                  # Generated HTML figures + metrics JSON
├── tests/
│   └── test_coverage.py      # Coverage guarantee unit tests
├── run_pipeline.py           # Main entrypoint — runs full pipeline
├── requirements.txt
└── README.md

🚀 Quick Start

git clone https://github.com/IsaH93/process-digital-twin
cd process-digital-twin

pip install -r requirements.txt

# Run full pipeline — generates all figures in outputs/
python run_pipeline.py

# Optional flags
python run_pipeline.py --alpha 0.05   # 95% confidence intervals
python run_pipeline.py --n-iter 800   # more GP training iterations
python run_pipeline.py --no-save      # run without saving outputs

📈 Output Figures

All figures are interactive HTML (Plotly). Open outputs/*.html in any browser.

File Description
gp_predictions_id.html GP mean + conformal PI vs true values (in-distribution)
distribution_shift.html Main story — tight CIs in-distribution, wide CIs under shift
calibration_curve.html Reliability diagram: empirical vs nominal coverage
length_scales.html ARD length-scales → variable importance ranking
uncertainty_vs_error.html GP std correlates with actual error (calibration check)
training_loss.html EMLL convergence curve

🔑 Why This Project Is Different

Typical DS portfolio project This project
Single point estimate Full posterior distribution
No coverage guarantees Conformal PI with provable (1-α) coverage
Silent failure under shift Explicit OOD flagging with threshold
Black-box variable importance ARD length-scales = interpretable sensitivity
Static matplotlib Interactive Plotly dashboards

🧰 Stack

  • GPyTorch — scalable Gaussian Process inference in PyTorch
  • scikit-learn — preprocessing, train/test split
  • SciPy — quantile computation for conformal calibration
  • Plotly — interactive process visualisations
  • NumPy / Pandas — data wrangling

📚 References

  1. Angelopoulos & Bates (2021). A Gentle Introduction to Conformal Prediction and Distribution-Free Uncertainty Quantification. arXiv:2107.07511
  2. Gardner et al. (2018). GPyTorch: Blackbox Matrix-Matrix Gaussian Process Inference with GPU Acceleration. NeurIPS 2018.
  3. Rasmussen & Williams (2006). Gaussian Processes for Machine Learning. MIT Press.
  4. Fortuna et al. (2007). Soft Sensors for Monitoring and Control of Industrial Processes. Springer.

👤 Author

Isa Hasanov — Process Systems Engineering (MSc, TU Dortmund)
Domain expertise in O&G + chemical engineering, transitioning to AI/ML Engineering

GitHub · LinkedIn


📄 License

MIT License — see LICENSE for details.

About

Gaussian process digital twin with conformal-prediction uncertainty quantification

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages