How pausarock/pidl-based-tse works
1. Purpose and scope
- This repository is a small, single-purpose Python project for traffic state estimation on freeways using a Physics-Informed Neural Network (PINN) approach.
- The architecture is organized around one core model plus supporting loaders, with separate entry points for training and testing.
2. Main execution paths
- There are two top-level workflows:
- train.py builds the model, loads data/configuration, trains, evaluates, and saves artifacts.
- test.py loads a saved model and produces prediction outputs and evaluation results.
- This separation is important for diagramming the system as two pipelines sharing the same model/data preparation layer.
3. Core model subsystem
- pinn.py contains the main PINN implementation.
- It is the central computational component, combining:
- data-driven prediction from traffic measurements
- physics-based constraints for traffic dynamics
- The model likely consumes detector-based inputs and produces predicted traffic state variables such as flow and speed.
4. Data ingestion subsystem
- data_loader.py is the boundary between raw CSV data and the model.
- The README indicates the project uses CSV-based configuration and traffic data, so this module is responsible for turning those files into model-ready tensors/arrays.
- The external data dependency is on parent-directory files such as:
- sh_flow_data.csv
- sh_speed_data.csv
5. Topology and station configuration subsystem
- topology_loader.py handles the freeway structure and station metadata.
- It reads configuration files such as:
- detector_positions.csv
- ramp_info.csv
- station_config.csv
- This module defines the spatial layout the model must respect: detector locations, ramp locations/types, and which stations are supervised vs. hidden.
6. Configuration-driven architecture
- The project is strongly driven by CSV configuration rather than hardcoded topology.
- train_config.csv provides default detector ID lists used during training.
- Command-line arguments in train.py override or refine the configuration, such as:
- network depth/width (--layers)
- training duration (--total_steps)
- physics loss weights (--alpha1, --alpha2, --beta1, --beta2, --gamma)
- For an architecture diagram, this is a key boundary: configuration files feed both topology construction and training setup.
7. Training pipeline
- train.py is the orchestration layer.
- Its responsibilities are likely:
- load topology and detector selections
- load traffic flow/speed data
- instantiate the PINN
- train with supervised and physics-informed objectives
- periodically validate or select the best checkpoint
- The output artifact mentioned is best_model.pat, which is the saved trained model weights.
8. Testing and evaluation pipeline
- test.py is the inference/evaluation entry point.
- After loading the trained model, it generates:
- pred_flow_JWZ.csv
- pred_speed_JWZ.csv
- The README notes automatic evaluation using MAPE and RMSE, so testing is not just inference; it also computes quantitative performance metrics.
9. Data flow from files to outputs
- The end-to-end flow is:
- CSV topology/config files and traffic data are loaded
- topology and station definitions shape the estimation problem
- the PINN trains on observed detector data plus physics constraints
- the resulting model is saved
- test/inference produces prediction CSVs and plots
- This makes the architecture a classic offline ML pipeline rather than a request/response service.
10. External inputs and system boundaries
- All operational inputs are file-based, not service-based:
- configuration CSVs
- traffic measurement CSVs
- There is no evidence of a database, message broker, or web frontend in this repo.
- The main system boundary is the local filesystem plus Python runtime dependencies listed in requirements.txt.
11. Outputs and artifacts
- The repository produces both machine-readable and visual outputs:
- model checkpoint: best_model.pat
- prediction tables: pred_flow_JWZ.csv, pred_speed_JWZ.csv
- plots in PNG/SVG formats
- In a diagram, these are downstream artifacts from the training/testing pipeline rather than separate subsystems.
12. Repo structure summary
- __init__.py indicates the code is packaged as a Python module, but the project is still script-oriented.
- The main architectural split is:
- Topology/configuration layer: topology_loader.py, CSV files
- Data layer: data_loader.py, traffic CSVs
- Model layer: pinn.py
- Orchestration layer: train.py, test.py
- That separation is the clearest way to draw the system accurately.
Main entry points: test.py Test · train.py Train · pinn.py PINN · topology_loader.py Topology loader
Components 16
Orchestration
Entry points that assemble, train, and evaluate the PINN pipeline.
Model
Core physics-informed network and its training objective.
- PINN · Physics-informed neural network for freeway traffic state estimation.
pinn.py
Inputs
CSV-based traffic data, topology, and configuration inputs.
- Data loader · Converts raw traffic measurement CSVs into model-ready arrays or tensors.
data_loader.py - Topology loader · Loads detector, ramp, and station layout metadata that defines the estimation topology.
topology_loader.py - Train config · Default detector selection and training setup used by the training pipeline.
- Flow data · Observed freeway flow measurements used for supervised learning and evaluation.
- Speed data · Observed freeway speed measurements used for supervised learning and evaluation.
- Detectors · Detector locations along the freeway corridor.
- Ramps · Ramp metadata describing on-ramps and off-ramps.
- Stations · Station visibility and supervision layout for the estimation problem.
Outputs
Saved model artifacts and evaluation results.
- Best model · Saved trained PINN weights produced by training.
- Flow preds · Predicted traffic flow output from testing.
- Speed preds · Predicted traffic speed output from testing.
- Metrics · MAPE and RMSE computed during testing.
- Plots · Generated figures for model behavior and prediction quality.
Connections 19
- Train config → Train: defaults · Provides default detector IDs and training setup.
- Detectors → Topology loader: load · Defines detector spatial positions.
- Ramps → Topology loader: load · Provides ramp layout metadata.
- Stations → Topology loader: load · Defines supervised and hidden stations.
- Flow data → Data loader: load · Supplies traffic flow observations.
- Speed data → Data loader: load · Supplies traffic speed observations.
- Topology loader → Train: topology · Shapes the estimation problem used in training.
- Data loader → Train: batches · Provides model-ready training data.
- Train → PINN: build/train · Instantiates and optimizes the PINN.
- PINN → Train: losses · Returns supervised and physics-informed losses for optimization.
- Train → Best model: save · Persists the best trained model weights.
- Best model → Test: load · Restores the trained model for inference.
- Topology loader → Test: context · Provides the same spatial configuration for evaluation.
- Data loader → Test: inputs · Provides evaluation inputs derived from traffic data.
- Test → PINN: infer · Runs the trained PINN for prediction.
- PINN → Flow preds: emit · Produces flow predictions.
- PINN → Speed preds: emit · Produces speed predictions.
- Test → Metrics: score · Computes MAPE and RMSE against observed values.
- Test → Plots: render · Generates visual evaluation outputs.