How me-intenzo/phm_project works
Purpose and Entry Points
PHM-XAI is a Python predictive-maintenance pipeline for NASA C-MAPSS turbofan Remaining Useful Life (RUL) prediction. Raw FD001–FD004 dataset files are expected under data/raw/; subset-specific execution parameters live in configs/fd001.yaml through configs/fd004.yaml. main.py is the EDA entry point; stage-specific CLI entry points are scripts/preprocess.py, scripts/train.py, scripts/evaluate.py, scripts/explain.py, scripts/uncertainty.py, and scripts/decision.py.
Configuration and Pipeline Coordination
Configuration, deterministic execution, logging, and artifact I/O form the cross-cutting runtime boundary. Dataset, windowing, training, device, and seed choices are supplied by YAML configs and consumed by the scripts and model pipeline. Central utilities are in src/utils/config.py, src/utils/seed.py, and src/utils/io.py.
Data Preparation and RUL Supervision
The preprocessing layer converts C-MAPSS trajectory text data into validated, model-ready temporal samples. It loads train/test/RUL inputs, validates schema/content, creates RUL labels, selects features, scales sensors, and produces sliding windows. This is the primary boundary between raw engine-cycle data and tensors/model inputs, implemented across src/preprocessing/loader.py, src/preprocessing/labeling.py, and src/preprocessing/windowing.py; scaling and validation are in src/preprocessing/scaling.py and src/preprocessing/validator.py.
Predictive Models and Training
PyTorch-based sequence regressors estimate RUL from sensor windows. The model family includes LSTM, GRU, Transformer, and hybrid/attention-degradation variants, allowing training runs to select or compare architectural approaches. Training and model evaluation are centralized in src/models/trainer.py and src/models/evaluator.py; representative architectures are src/models/lstm.py, src/models/gru.py, src/models/transformer.py, and src/models/hybrid.py. Custom objectives reside in src/models/losses.py.
Evaluation and Robustness
Offline assessment measures predictive quality and experimental resilience, rather than serving predictions directly. The evaluation layer owns metrics, benchmarks, ablations, and robustness studies through src/evaluation/metrics.py, src/evaluation/benchmark.py, src/evaluation/ablation.py, and src/evaluation/robustness.py. scripts/evaluate.py is the evaluation orchestration boundary after training.
Explainability and Trust Signals
The explainability subsystem interprets model predictions using SHAP, Captum Integrated Gradients, and model attention, and provides degradation-oriented visualizations. It also computes an Explainability Reliability Index (ERI), making explanation reliability a first-class signal. Core modules are src/explainability/shap_explainer.py, src/explainability/integrated_gradients.py, src/explainability/attention.py, and src/explainability/eri.py; scripts/explain.py runs this stage. External explainability runtimes include SHAP and Captum.
Uncertainty, Decisions, and Human Feedback
Prediction uncertainty is quantified with calibration, conformal intervals, and coverage analysis before maintenance guidance is issued. This boundary is implemented in src/uncertainty/calibration.py, src/uncertainty/conformal.py, and src/uncertainty/coverage.py. The decision engine turns predicted RUL and operational constraints into rule-based maintenance recommendations via src/decision_engine/rules.py, src/decision_engine/constraints.py, and src/decision_engine/recommender.py. Human feedback is logged and can drive updates through src/hitl/feedback.py, src/hitl/logger.py, and src/hitl/updater.py.
Main entry points: trainer.py Training · recommender.py Maintenance recommender · config.py Runtime utilities · loader.py Trajectory loading
Components 18
Runtime
Shared configuration and artifact boundary.
- Subset configs · FD001–FD004 execution parameters.
configs/fd001.yaml - Runtime utilities · Loads settings, enforces deterministic runs, and manages artifacts.
src/utils/config.py
Data preparation
Converts C-MAPSS files into temporal training samples.
- C-MAPSS raw data · Train, test, and RUL inputs for FD001–FD004.
- Preprocess CLI
scripts/preprocess.py - Trajectory loading · Loads inputs and validates their schema and content.
src/preprocessing/loader.py - RUL labeling · Creates remaining-useful-life targets.
src/preprocessing/labeling.py - Scaling and windows · Selects and scales sensors, then creates sliding windows.
src/preprocessing/windowing.py - Model-ready samples
Modeling
Sequence regression training and evaluation.
- Train CLI
scripts/train.py - Sequence model family · Selectable RUL regressor architectures.
src/models/lstm.py - Training · Optimizes selected regressors with custom objectives.
src/models/trainer.py - Trained model
- Evaluate CLI
scripts/evaluate.py - Offline evaluation · Measures quality, benchmarks, ablations, and robustness.
src/evaluation/metrics.py
Trust and action
Post-prediction analysis, guidance, and feedback.
- Explainability and ERI · Generates attribution and explanation-reliability signals.
src/explainability/shap_explainer.py - Uncertainty analysis · Produces calibrated intervals and coverage analysis.
src/uncertainty/calibration.py - Maintenance recommender · Combines predicted RUL with operational constraints.
src/decision_engine/recommender.py - Human feedback loop · Logs feedback and drives model updates.
src/hitl/feedback.py
Connections 23
- Subset configs → Runtime utilities: loaded by
- Runtime utilities → Preprocess CLI: configures
- Runtime utilities → Train CLI: configures
- C-MAPSS raw data → Trajectory loading: ingested as
- Preprocess CLI → Trajectory loading: runs
- Trajectory loading → RUL labeling: validated trajectories
- RUL labeling → Scaling and windows: labeled series
- Scaling and windows → Model-ready samples: produces
- Train CLI → Training: runs
- Model-ready samples → Training: training inputs
- Sequence model family → Training: selected architecture
- Training → Trained model: writes
- Evaluate CLI → Offline evaluation: runs
- Trained model → Offline evaluation: assessed by
- Model-ready samples → Offline evaluation: evaluation data
- Trained model → Explainability and ERI: predictions and internals
- Model-ready samples → Explainability and ERI: sensor windows
- Trained model → Uncertainty analysis: predictions
- Uncertainty analysis → Maintenance recommender: intervals and coverage
- Trained model → Maintenance recommender: RUL predictions
- Explainability and ERI → Maintenance recommender: trust signals
- Maintenance recommender → Human feedback loop: recommendations reviewed
- Human feedback loop → Training: updates inform retraining